# MQTT downlink in Node Red

**URL:** <https://www.thethingsnetwork.org/forum/t/mqtt-downlink-in-node-red/38096>\
**Category:** Application Development\
**Created:** [June 26, 2020, 9:28am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-downlink-in-node-red/38096 "2020-06-26T09:28:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaoAkash](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/raoakash/32/25844_2.png) [@RaoAkash](https://www.thethingsnetwork.org/forum/u/RaoAkash)\
**Post date:** [June 26, 2020, 9:28am UTC](https://www.thethingsnetwork.org/forum/t/mqtt-downlink-in-node-red/38096/1 "2020-06-26T09:28:41Z")

</div>

I need to trigger a downlink message when an uplink message is received on node red.  
The /devices//up works well and the data received in payload\_raw is fine.  
but /devices//down doesnt schedules a downlink message.

This is the message that I am passing to the TTN pulish Node subscribed to /devices//down: ```  
{  
“port”: 1,  
“confirmed”: true,  
“payload\_raw”: “AQIDBA==”,  
}

```auto

```

---

<div class="post-metadata">

**Author:** ![pe1mew](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/pe1mew/32/45049_2.png) [@pe1mew](https://www.thethingsnetwork.org/forum/u/pe1mew)\
**Post date:** [June 26, 2020, 12:49pm UTC](https://www.thethingsnetwork.org/forum/t/mqtt-downlink-in-node-red/38096/2 "2020-06-26T12:49:39Z")

</div>

This this a flow I use in Node Red. It has all the information needed to work with me and may help you when you study it.

```auto
// TTN downliank settings
var dev_id = msg.topic; // from previous MQTT received message in this case;
var dlPort = 3; // downlink prot inthis application
var dlConfirmed = true;
var dlScheduled = "replace"; // allowed values: "replace" (default), "first", "last"

// MQTT settings
msg.topic = "<ApplicationID>>/devices/" + dev_id + "/down";
msg.qos = 0;
msg.retain = false;

// prepare RAW payload and convert to base64
var payload_raw = Buffer.alloc(2, 0);
payload_raw[1] = 0x03; // command for this application
var base64data = payload_raw.toString('base64');

// use payload fields
var message = {
    port: dlPort, 
    confirmed: dlConfirmed, 
    schedule: dlScheduled, 
    payload_raw: base64data,
}; 

msg.payload = message;
return msg;

```

---

<div class="post-metadata">

**Author:** ![RaoAkash](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/raoakash/32/25844_2.png) [@RaoAkash](https://www.thethingsnetwork.org/forum/u/RaoAkash)\
**Post date:** [June 26, 2020, 1:19pm UTC](https://www.thethingsnetwork.org/forum/t/mqtt-downlink-in-node-red/38096/3 "2020-06-26T13:19:55Z")

</div>

Thank you, this works, thank you so much
