# Decoding uint16 sent from Arduino

**URL:** <https://www.thethingsnetwork.org/forum/t/decoding-uint16-sent-from-arduino/55203>\
**Category:** Application Development\
**Created:** [February 14, 2022, 8:53pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-uint16-sent-from-arduino/55203 "2022-02-14T20:53:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlheide](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/carlheide/32/35697_2.png) [@carlheide](https://www.thethingsnetwork.org/forum/u/carlheide)\
**Post date:** [February 14, 2022, 8:53pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-uint16-sent-from-arduino/55203/1 "2022-02-14T20:53:14Z")

</div>

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

```auto
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.

```auto
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

---

<div class="post-metadata">

**Author:** ![carlheide](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/carlheide/32/35697_2.png) [@carlheide](https://www.thethingsnetwork.org/forum/u/carlheide)\
**Post date:** [February 14, 2022, 9:14pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-uint16-sent-from-arduino/55203/2 "2022-02-14T21:14:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cslorabox](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cslorabox/32/35697_2.png) [@cslorabox](https://www.thethingsnetwork.org/forum/u/cslorabox)\
**Post date:** [February 15, 2022, 12:30am UTC](https://www.thethingsnetwork.org/forum/t/decoding-uint16-sent-from-arduino/55203/3 "2022-02-15T00:30:50Z")

</div>

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(!)

---

<div class="post-metadata">

**Author:** ![carlheide](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/carlheide/32/35697_2.png) [@carlheide](https://www.thethingsnetwork.org/forum/u/carlheide)\
**Post date:** [February 15, 2022, 9:11am UTC](https://www.thethingsnetwork.org/forum/t/decoding-uint16-sent-from-arduino/55203/4 "2022-02-15T09:11:38Z")

</div>

Thanks
