# Trouble sending data to TTN Device Downlink via MQTT Out

**URL:** https://discourse.nodered.org/t/trouble-sending-data-to-ttn-device-downlink-via-mqtt-out/77288
**Category:** General
**Created:** [5 April 2023 19:25 UTC](https://discourse.nodered.org/t/trouble-sending-data-to-ttn-device-downlink-via-mqtt-out/77288 "2023-04-05T19:25:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NewToNodeRed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/newtonodered/32/76711_2.png) [@NewToNodeRed](https://discourse.nodered.org/u/NewToNodeRed)
#### Post date: [5 April 2023 19:25 UTC](https://discourse.nodered.org/t/trouble-sending-data-to-ttn-device-downlink-via-mqtt-out/77288/1 "2023-04-05T19:25:04Z")

</div>

I a looking to troubleshoot sending commands to my downlink of my device on the TTN network.

In the TTN console I do this and it works:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/81a9fa9f7ab2769162a155ac8557e15187d20b1c.png)

But from Node Red I have the following in a function feeding into a MQTT Out and it does not work: [Device and App ID are of course REPLACED as to not share them]

```auto
// TTN downliank settings
var dev_id = "REPLACED"; // from previous MQTT received message in this case;
var dlPort = 2; // downlink port in this application
var dlConfirmed = true;
var dlScheduled = "replace"; // allowed values: "replace" (default), "first", "last"

// MQTT settings
msg.topic = "v3/REPLACED@ttn/devices/" + dev_id + "/down/push";
msg.qos = 0;
msg.retain = false;

var payload_raw = Buffer.alloc(2, 0);
payload_raw[1] = 0x12c; // Changed uplink fequency to 5min (300 sec in Hex)
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;

```

I was referencing this post:

> **[V3 using MQTT to Downlink from NodeRED](https://www.thethingsnetwork.org/forum/t/v3-using-mqtt-to-downlink-from-nodered/52629)**
>
> Hi guys, this is something that has been already discussed in this forum but even with the posts that i found that talks about this, I cannot success to downlink a message using NodeRed with the “MQTT out” node. I can read data from my sensors...

and this post:

> **[MQTT downlink in Node Red](https://www.thethingsnetwork.org/forum/t/mqtt-downlink-in-node-red/38096)**
>
> 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...

as starting points but have hit a dead end for now. Any help is appeciated.

---

<div class="post-metadata">

### Author: ![NewToNodeRed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/newtonodered/32/76711_2.png) [@NewToNodeRed](https://discourse.nodered.org/u/NewToNodeRed)
#### Post date: [6 April 2023 20:22 UTC](https://discourse.nodered.org/t/trouble-sending-data-to-ttn-device-downlink-via-mqtt-out/77288/2 "2023-04-06T20:22:20Z")

</div>

I wondered if my example was too old so I looked up The Things Stack current documentation and found it here:  
[https://www.thethingsindustries.com/docs/integrations/mqtt/#publishing-downlink-traffic](https://www.thethingsindustries.com/docs/integrations/mqtt/#publishing-downlink-traffic)

So I updated my function node to this:

```auto
msg.topic = "v3/REPLACED@ttn/devices/REPLACED/down/push";
var base64data = msg.payload;

msg.payload = {
    "f_port": 2,
    "frm_payload": base64data,
    "priority": "NORMAL"
};

return msg;

```

And I am passing the base64 encoded values for the seconds in as the msg.payload.

```auto
Possible values I am passing:
Hex Time Base64
0100012C = 300 secs (5 mins)	xKw=
01000258 = 600 secs (10 mins)	yZg=
01000384 = 900 sec (15 mins)	zoQ=
010004B0 = 1200 sec (20 mins)	0rA=
01000708 = 1800 sec (30 mins)	3Ig=
01000E10 = 3600 sec (1hr) 4LiQ

```

Here is part of the debug output to show a payload example.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f485f932cec2fd0bf7c22ac0f5b006c601daa0f4.png)

But even still I have yet to seem to get this to work.

And thoughts on how to even troubleshoot this would be good as I do not even know if the command from Node Red is reaching the TTN application. None of the live data views show it.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 June 2023 20:22 UTC](https://discourse.nodered.org/t/trouble-sending-data-to-ttn-device-downlink-via-mqtt-out/77288/3 "2023-06-05T20:22:36Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
