TEXT I am sending Teperature values via MQTT from a B4R app to a B4J app
CODE
' B4R Code
Temp(2) as Double
TempC(0) = 20.925
TempC(1) = 0
Log("TempC - ",TempC(0))
Log("Temperature - ", numberformat(TempC(0),0,2)
Dim Data(8) as Byte
Data = bc.DoublesToBytes(Array As Double(TempC(0)))
For i =0 to Data.length-1
Log(Data(i))
Next
Return Data
/CODE 'Send as MQTT Payload
TEXT B4R Log Output
TempC - 20.925
Temperature = 20.94
0
128
167
65
CODE
' B4J Code Payload received via MQTT
Dim B As Byte
For i = 0 To Payload.Length-1
B = Payload(i)
Log(B)
Next
Dim Buffer() As Float = bc.FloatsFromBytes(Payload)
Log("Payload - ")
Log(Buffer(0))
Log("Payload - ")
Log(NumberFormat(Buffer(0),3,2))
/CODE
TEXT B4J Log Output
0
-128
-89
65
Payload -
1.181494290456987E-38
Payload -
00
Allowing for the fact that bytes are signed in B4J the Payload received is the same as Payload sent.
Question is how to get Buffer(0) to output 20.925?
Your help is appreciated
regards
Donald
CODE
' B4R Code
Temp(2) as Double
TempC(0) = 20.925
TempC(1) = 0
Log("TempC - ",TempC(0))
Log("Temperature - ", numberformat(TempC(0),0,2)
Dim Data(8) as Byte
Data = bc.DoublesToBytes(Array As Double(TempC(0)))
For i =0 to Data.length-1
Log(Data(i))
Next
Return Data
/CODE 'Send as MQTT Payload
TEXT B4R Log Output
TempC - 20.925
Temperature = 20.94
0
128
167
65
CODE
' B4J Code Payload received via MQTT
Dim B As Byte
For i = 0 To Payload.Length-1
B = Payload(i)
Log(B)
Next
Dim Buffer() As Float = bc.FloatsFromBytes(Payload)
Log("Payload - ")
Log(Buffer(0))
Log("Payload - ")
Log(NumberFormat(Buffer(0),3,2))
/CODE
TEXT B4J Log Output
0
-128
-89
65
Payload -
1.181494290456987E-38
Payload -
00
Allowing for the fact that bytes are signed in B4J the Payload received is the same as Payload sent.
Question is how to get Buffer(0) to output 20.925?
Your help is appreciated
regards
Donald
Last edited: