B4J Question ByteConcerter Problem

DARintoul

Member
Licensed User
Longtime User
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
 
Last edited:

MarkusR

Well-Known Member
Licensed User
Longtime User
for me it looks like you send double and receive as float.
have double and float the same size in B4R & B4J?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
hmm the manual B4xBasicLanguageV1_4.pdf said
b4r Byte 0 - 255
B4A, B4i, B4J min -127 max 127
is that the difference / issue?
 
Upvote 0
Top