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:
//**************************************************************************/
//*!
// 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)
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?