Decoding uint16 sent from Arduino

Hello, and sorry for a maybe very beginner question.
I’m trying to decode my readings from my temperature sensor. the Arduino code is

float temperature = sensors.getTempCByIndex(0);

int16_t temp = (temperature * 100);
Serial.println(temp);
  

modem.beginPacket();
modem.print(temp);

I can see the right payload in HEX on the ‘live data’ site, but cant seems to figure out how to decode it in the payload formatter.

function Decoder(bytes, port) {
var decoded = {};
if (port === 2)
{
decoded.temp = (bytes[1] << 8) + bytes[0];
}
return decoded;
}

This is the only example I could find of someone doing something similar, but it returns numbers with no meaning to me.

Thanks in advance

an example is if I’m decoding 0x32 0x33 0x35 0x30 it becomes 13106

Don’t send character encoded packets, that’s wasteful, send binary values or even denser encodings - uint16_t should end up at most 2 bytes, not four.

Also keep in mind that temperature can’t be an unsigned integer unless you put in a sufficient offset to make sure that it’s always positive.

If you send negative values, beware the complications of trying to re-join two’s complement byte fields in javascript(!)

1 Like

Thanks