How to Extract Negative value in Payload function

Am trying to send negative temperature data from DB18B20 to TTN using Arduino LMIC, am able to send negative data, but TTN decoder is considering as un signed Int and changing the value from -3456 to 62080.

Please help me to decode Negative value in TTN decoder function.

Code at Arduino :

  int16_t temp5 = -3456; 
  Serial.print("      Dummy of 6th IC is: ");

  data[10] = temp5 >> 8;
  data[11] = temp5 & 0xFF;

Payload sent : temp5 = -3456

Decoder at TTN :

  var temp5 = (bytes[10] << 8)| bytes[11];

Payload receive and decoded at TTN = 62080

See Decrypting messages for dummies Or add some base value like 32,768 (the minimum value for a signed 16 bits integer) before sending, and subtract that again after decoding.

1 Like