# Simple payload conversion

**URL:** <https://www.thethingsnetwork.org/forum/t/simple-payload-conversion/5273>\
**Category:** Application Development\
**Created:** [February 7, 2017, 11:44am UTC](https://www.thethingsnetwork.org/forum/t/simple-payload-conversion/5273 "2017-02-07T11:44:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [February 7, 2017, 6:10pm UTC](https://www.thethingsnetwork.org/forum/t/simple-payload-conversion/5273/2 "2017-02-07T18:10:36Z")

</div>

> [@snoller](#):
>
> The hex-code i receive is for instance “3131312030313400” which translates to: Light:111 Temp:14  
> Can someone provide me a simple function for this conversion or give me a hint?

Instead of sending two numbers, the node is sending the text `111 014` with a trailing null-character (a [null-terminated string](https://en.wikipedia.org/wiki/Null-terminated_string)).

So, mandatory first hint: please don’t send text. This is probably just for testing, so, well, okay. But even just using 8 bytes to send two values that would probably need 2 to 4 bytes in total (depending on the range of the measurements, and if negative values can be sent too), is just [not a good idea](https://www.thethingsnetwork.org/forum/t/limitations-data-rate-packet-size-30-seconds-uplink-and-10-messages-downlink-per-day-fair-access-policy/1300).

That said, you can use [a payload function](https://www.thethingsnetwork.org/forum/t/is-there-any-documentation-on-payload-functions/3441/3) like:

```
function Decoder(bytes, port) {

    // Get the string "111 014" out of the bytes 3131312030313400
    var text = String.fromCharCode.apply(null, bytes);

    // Split into an array of 2 strings, on the space character
    var values = text.split(" ");

    // Return as true numbers
    return {
      light: parseInt(values[0]),
      temp: parseInt(values[1])
    }
}

```

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/simple-payload-conversion/5273)._
