# Extract the received value from downlink messages

**URL:** <https://www.thethingsnetwork.org/forum/t/extract-the-received-value-from-downlink-messages/39784>\
**Category:** LMIC\
**Created:** [September 9, 2020, 1:58pm UTC](https://www.thethingsnetwork.org/forum/t/extract-the-received-value-from-downlink-messages/39784 "2020-09-09T13:58:20Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [September 10, 2020, 8:35am UTC](https://www.thethingsnetwork.org/forum/t/extract-the-received-value-from-downlink-messages/39784/8 "2020-09-10T08:35:22Z")

</div>

> [@adjaramillo](#):
>
> If I encode in binary will be something like this:
> 
> ```auto
> {
> "confirmed": true,
> "fPort": 10,
> "data": "01001110010101000100000101110111"
> }
> 
> ```

That’s not encoding in binary, that’s a text string that only holds ones and zeroes, but it’s still very much text. Even 32 characters of text! (And next, there’s some more encoding happening that we don’t know of, as we don’t know what library or API you’re using.)

Maybe [Working with Bytes](https://www.thethingsnetwork.org/docs/devices/bytes.html) is a good start.

I don’t know what library you’re using in Node-RED, but when using plain MQTT you’d need something like:

> [@Why is Node-RED integration no longer supported?](https://www.thethingsnetwork.org/forum/t/why-is-node-red-integration-no-longer-supported/39390/5):
>
> ```auto
> msg.payload = {
> dev_id: devId,
> port: 1,
> confirmed: false,
> schedule: 'replace',
> payload_raw: Buffer.from(bytes).toString('base64')
> };
> 
> ```

And `bytes` should then be two bytes for your number 500, maybe using [writeUInt16BE](https://nodejs.org/docs/latest-v10.x/api/buffer.html#buffer_buf_writeuint16be_value_offset):

```auto
// Allocate 2 bytes, to hold a single 16 bits unsigned integer; you
// may need more to send multiple values, or to use larger values.
const bytes = Buffer.allocUnsafe(2);
// 16 bits integer, 0..65,535
bytes.writeUInt16BE(500, 0);

```

Alternatively: start with scheduling downlinks using TTN Console. The number 500 [would be the 2 bytes 0x01F4](https://www.rapidtables.com/convert/number/decimal-to-hex.html?x=500) when written in hexadecimal:

 ![schedule downlink](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/4/2/42478435a32049c86bead87f1d50bc27c91c27c1.png)

All of the above should decode fine using descartes’:

> [@descartes](#):
>
> And then if you assign the result to an integer, you are ready to go with something like this:
> 
> `int TxPeriod = ( LMIC.frame[LMIC.dataBeg] << 8 ) + LMIC.frame[LMIC.dataBeg+1];`

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/extract-the-received-value-from-downlink-messages/39784)._
