# How to send bytes data to downlink

**URL:** <https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379>\
**Category:** Application Development\
**Created:** [November 2, 2018, 5:11pm UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379 "2018-11-02T17:11:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedrojung](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@pedrojung](https://www.thethingsnetwork.org/forum/u/pedrojung)\
**Post date:** [November 2, 2018, 5:11pm UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379/1 "2018-11-02T17:11:36Z")

</div>

Hello 🙂  
I have downlink url from uplink request body  
and want to post it on postman.

on Application console - device - I sent bytes data to change interval of checking temp.  
 ![34](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/1/2/12eaba3b0fd89719ca0f5b59cb80ef0149704612.png)

It work like charm!!!

but wonder how to do it on postman.  
I searched it for it but says I should put device id and payload\_raw on body.  
is it so?  
should I put bytes data to payload\_raw?  
like below?

```json
{
  "dev_id": "xxxxxxxxx", // The device ID
  "port": 11, // LoRaWAN FPort
  "confirmed": false, // Whether the downlink should be confirmed by the device
  "payload_fields": { // The JSON object to be encoded by your encoder payload function
    0B 81 04 00 00 01 2C
  }
}

```

---

<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:** [November 2, 2018, 8:54pm UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379/2 "2018-11-02T20:54:40Z")

</div>

> [@pedrojung](#):
>
> should I put bytes data to payload\_raw

Yes, you’ll have to [Base64 encode](http://tomeko.net/online_tools/hex_to_base64.php) the bytes, and put that in `payload_raw`. So, for 0x0B81040000012C, use:

```json
{
  "dev_id": ...,
  ...,
  "payload_raw": "C4EEAAABLA=="
}

```

Alternatively, provide an Encoder function in TTN Console, and pass human-readable values in `payload_fields`. Like, just as an example, if your encoder would be:

```javascript
function Encoder(object, port) {
  var bytes = [];
  // Encode 8 boolean values into a single byte
  bytes[0] |= object.my1stBoolean ? 1<<0 : 0;
  bytes[0] |= object.my2ndBoolean ? 1<<1 : 0;
  bytes[0] |= object.my3rdBoolean ? 1<<2 : 0;
  bytes[0] |= object.my4thBoolean ? 1<<3 : 0;
  bytes[0] |= object.my5thBoolean ? 1<<4 : 0;
  bytes[0] |= object.my6thBoolean ? 1<<5 : 0;
  bytes[0] |= object.my7thBoolean ? 1<<6 : 0;
  bytes[0] |= object.my8thBoolean ? 1<<7 : 0;

  // Unsigned decimal in range from 0 to 655.35, or signed decimal in
  // range from -327.68 to +327.67, multiplied by 100 to be sent as 
  // signed integer; Most Significant Byte first
  bytes[1] = (object.my16bitsDecimal * 100)>>8 & 0xFF;
  bytes[2] = (object.my16bitsDecimal * 100) & 0xFF;

  // 32 bits value, MSB
  bytes[3] = object.my24bitsInteger>>24 & 0xFF; 
  bytes[4] = object.my24bitsInteger>>16 & 0xFF; 
  bytes[5] = object.my24bitsInteger>>8 & 0xFF; 
  bytes[6] = object.my24bitsInteger & 0xFF;

  return bytes;
}

```

…then for the exact same result, you could use:

```json
{
  "dev_id": ...,
  ...,
  "payload_fields": {
    "my1stBoolean": true,
    "my2ndBoolean": true,
    "my3rdBoolean": false,
    "my4thBoolean": true,
    "my5thBoolean": false,
    "my6thBoolean": false,
    "my7thBoolean": false,
    "my8thBoolean": false,
    "my16bitsDecimal": -325.08,
    "my24bitsInteger": 300
  }
}

```

---

<div class="post-metadata">

**Author:** ![pedrojung](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@pedrojung](https://www.thethingsnetwork.org/forum/u/pedrojung)\
**Post date:** [November 3, 2018, 2:00am UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379/3 "2018-11-03T02:00:50Z")

</div>

Thanks for answer 🙂

I tried your first way base 64 encode, but 400 bad request error. why is it?  
can you guess?

![23](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/5/9/59af611cfa1168b3a4016e3a0782434516897281.png)

---

<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:** [November 3, 2018, 8:21am UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379/4 "2018-11-03T08:21:09Z")

</div>

The screenshot shows you’re using `payload_fields` instead of `payload_raw`. The Base64-encoded payload should go into `payload_raw`. Only use `payload_fields` if you’ve defined an Encoder in TTN Console.

Your `MHgwQjgxMDQwMDAwMDAxRQ==` converts to hexadecimal `30783042383130343030303030303145` which is ASCII text. Converting that hexadecimal representation into an ASCII representation [gives me](https://www.rapidtables.com/convert/number/hex-to-ascii.html) `0x0B81040000001E` again.

So, you’ve encoded twice. That’s wrong.

To send the byte `0x0B` you should send a single value, basically [the bits](https://www.binaryhexconverter.com/hex-to-binary-converter) `00001011`. But above you’re sending the human-readable ASCII characters `0` and `B`, which in hexadecimal notation are the bytes `0x30` and `0x78`, or when displayed as bits are `00110000 01111000`, so twice as many bits. See also [https://www.thethingsnetwork.org/docs/devices/bytes.html](https://www.thethingsnetwork.org/docs/devices/bytes.html)

So, you should not Base64-encode the human-readable hexadecimal **text** representation, but you should Base64-encode the actual binary value. For manual testing use [the Base64 encoder](http://tomeko.net/online_tools/hex_to_base64.php) I already linked to in my answer above, which already expects human-readable hexadecimal text as its input. See also [https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425](https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425)

In short, you should use the example I gave you:

> [@arjanvanb](#):
>
> ```javascript
> "payload_raw": "C4EEAAABLA=="
> 
> ```

How did you Base64-encode the value you’re using?

---

<div class="post-metadata">

**Author:** ![susiloharjo](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/susiloharjo/32/35456_2.png) [@susiloharjo](https://www.thethingsnetwork.org/forum/u/susiloharjo)\
**Post date:** [May 27, 2019, 3:50am UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379/5 "2019-05-27T03:50:03Z")

</div>

Hi @arjanvanb

i have dragino lora i/o (LT-33222-L), according to datasheet for activate relay on/of just sending 0x030101 to downlink , i try send downlink via ttn console and it works i can activate on/off relay, but why i can’t activate relay via button in my node-red

im using this json payload format  
{  
“dev\_id”: “dev\_dragino”,  
“confirmed”: false,  
“port”: 2,  
“payload\_raw”: “AwEB”  
}

i can see data on schedule in my downlink but not activate the relay, any idea to solve this?

---

<div class="post-metadata">

**Author:** ![sacchidanand\_utech](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/sacchidanand_utech/32/25844_2.png) [@sacchidanand\_utech](https://www.thethingsnetwork.org/forum/u/sacchidanand_utech)\
**Post date:** [January 31, 2020, 8:15am UTC](https://www.thethingsnetwork.org/forum/t/how-to-send-bytes-data-to-downlink/19379/6 "2020-01-31T08:15:00Z")

</div>

Hi @susiloharjo  
will you please send your node-red flow.
