MQTT downlink in Node Red

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==”,
}

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.

// 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;
3 Likes

Thank you, this works, thank you so much

1 Like