Author Topic: Odd beacon Behaviour  (Read 296 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Odd beacon Behaviour
« on: August 21, 2016, 10:01:51 am »
I am trying to put data into the 4 beacon bytes available (so I don't have to publish via MQTT so much).

I have found some odd things:

This is my code for publishing beacon data:

Code: [Select]
    //**************************************************************************/
    //*!
    //    Encodes Float or Integer into 4 bytes of beacon data
    //    encoding is - byte 0 is data type (numeric value)
    //    Integer as Short (2 bytes)
    //    Fraction as byte (1 byte)
    //*/
    //**************************************************************************/
    Shared Sub BeaconPublish(data_Type As Byte, value As Object)
        Dim fraction As Byte = 0
        Dim data As Short = 0
        If value Is Float Then
            data = value.Cast(Float).ToShort() //get integer part (16 bit only)
            fraction = ((value.Cast(Float) - data) * 100.0).ToByte()
        ElseIf value Is Integer Then
            data = value.Cast(Integer).ToShort() //get integer part (16 bit only)
        ElseIf value Is Short Then
            data = value.Cast(Short)
        ElseIf value Is Byte Then
            data = value.Cast(Byte).ToShort() //get integer part (16 bit only)
        End If
        Dim beaconData As ListOfByte = New ListOfByte()
        beaconData.Add(data_Type)
        beaconData.AddShort(data)
        beaconData.Add(fraction)
        Lplan.SetBeaconData(beaconData)
        Lplan.SendBeacon()
        //Lplan.BeaconNow () //does not seem to work
    End Sub

This is what I receive and decode. Mostly it works, then sometimes I get the first three bytes repeated in the beacon data, sometimes just second and third (this gives the -17.67 result which is bogus)

Code: [Select]
10:33:59.868 [INFO ] [org.openhab.model.script.error:53   ] - Beacon Bytes:  EF:BF:BD:11:01:00:05:22:00:12:EF:BF:BD:2E:13:01:00:
10:33:59.943 [INFO ] [org.openhab.model.script.error:53   ] - bytes[6] = 5
10:34:01.321 [INFO ] [org.openhab.model.script.error:53   ] - Decoded Bytes:  Humidity 34.18000000 05:22:00:12
10:34:38.226 [INFO ] [org.openhab.model.script.error:53   ] - Beacon Bytes:  EF:BF:BD:11:01:00:08:EF:BF:BD:01:1C:EF:BF:BD:2E:13:01:00:
10:34:38.227 [INFO ] [org.openhab.model.script.error:53   ] - bytes[6] = 8
10:34:38.407 [INFO ] [org.openhab.model.script.error:53   ] - Decoded Bytes:  Altitude -17.67000000 08:EF:BF:BD
10:34:48.637 [INFO ] [org.openhab.model.script.error:53   ] - Beacon Bytes:  EF:BF:BD:11:01:00:01:EF:BF:BD:01:00:EF:BF:BD:2E:13:01:00:
10:34:48.718 [INFO ] [org.openhab.model.script.error:53   ] - bytes[6] = 1
10:34:49.918 [INFO ] [org.openhab.model.script.error:53   ] - Decoded Bytes:  Uptime -17.67000000 01:EF:BF:BD


Also, according to the documentation Lplan.SendBeacon() should accept a ListOfBytes as data - but it doesn't. In fact seems to do nothing.
Lplan.BeaconNow () is Documented, but does not seem to exist.

It would be helpful if we could send 5 bytes - then I could send 1 byte as data type, then 4 bytes as the data (as all numeric types are stored as 4 bytes), instead I have to fit 4 bytes of data into 3. Not a big problem as I'm publishing environmental data, so +/- 32k is plenty for temperature, humidity, pressure etc. Just saying...

Is this behavior a bug?

Share on Facebook Share on Twitter


mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Odd beacon Behaviour
« Reply #1 on: August 23, 2016, 11:18:32 am »
Beacons are broadcast messages so you don't know if they arrive. We have 4 bytes available to store them. I will ask our wireless guy if we have more data available but I don't think so.

Are you using MQTT or UDP to receive the data. We have a new version of the beacon document that describe how to decode it. It is on the download page. Also if you don't set the data it shows the software version of the module.
By the way the program looks good and compiles correctly

John

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Odd beacon Behaviour
« Reply #2 on: August 23, 2016, 12:14:32 pm »
Thanks John,

I'll download the latest Beacon spec.

I'm using both MQTT and UDP (belt and braces for the moment). The UDP always seems to be correct, the MQTT does not, and is missing the RSSI value.

I'll let you know how it goes.