Hi,

My aplication send as payload temp and moisture as hex.

the actual payload now is: 16 1C
16 is the temp 22 degrees 1C is the moisture 28%

How do i decode this 16 1C to te 22degrees and 28% ?
I read the decoding payload for dummys topic, that did not help much

(Darren Millett) #2

Let javascript do the work for you:

``````decoded.Temperature = bytes[0];
decoded.Humidity = bytes[1];
``````

Remember, a number is ultimately just a binary number stored inside the computer. Itâ€™s how that number is displayed that matters.
Payload data is displayed in Hex bytes, but if you decode it using Payload Functions, it gets stored (and displayed) as a json object, so usually numbers will be printed as decimal.

N.B. Negative numbers tend to cause problems (they are stored as 2â€™s complement), so you might want to modify you code to add and substract 100 to the temperature.
i.e. in the node: temp = temp + 100;
And in the payload decoding: decoded.Temperature = bytes[0] - 100;
That will give you a range from -100c to +155c, which is pretty safe for air temperature.

``````decoded.Temperature = bytes[0];
decoded.Humidity = bytes[1];
``````

Internal error: Decoder threw error: ReferenceError("â€˜decodedâ€™ is not defined")

something went wrong â€¦

(Ud Lo Ra) #4

You must learn at least a minimum of programming and Javascript to develop an applicationâ€¦ declare the variable first.

ok ok
Added another var that works but not al i like.

the value must be rounded to two decimals, how do i do that in java ?
expamples failedâ€¦

i use: math.round (bat/1000)
the result is a figure with no decimals.
the result = 4 in stead of 4.145
i want as a result 4.15

`Math.round(bat/10.0)/100.0`