Do you have any example payloads for different temperatures, especially values of 33°C and above?
The two example values in the documentation (0x1B being 27°C, and 0xF2 being -14°C), happen to be regular signed integers. But the “greater than 32” (rather than 127) in the following surprises me:
Temperature ranges -20°C to +50°C (Variable range -127 → 127)
- - ([256 or 0] - Byte)
- If the decimal conversion of the byte is greater than 32 then the number required for the formula is 256 otherwise the number required for the formula is 0.
That makes me wonder how temperatures of 33°C and above would be sent. I don’t think that’s possible at all with this formula?
The decoder that @descartes found also assumes a standard signed integer. (Note that var temp0 = p.readInt8(6)
is not supported in the JavaScript version that TTN Payload Formats use.) And another decoder uses the value 50, rather than 32, which probably works as the documented range is -20°C to +50°C. But for a standard signed integer, it should really be 127 (or, when using bitwise operators, if (value & 0x80) ...
).
I’d assume that the following should do:
// Sign-extend a single byte to 32 bits to make JavaScript understand
// negative values, by shifting 24 bits to the left, followed by a
// sign-propagating right shift of the same number of bits.
temp1 = bytes[6]<<24>>24;
temp2 = bytes[10]<<24>>24;
temp3 = bytes[14]<<24>>24;
temp4 = bytes[18]<<24>>24;