# MQTT publish on The Things Stack

**URL:** https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882
**Category:** General
**Created:** [5 October 2021 10:51 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882 "2021-10-05T10:51:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Miriana](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Miriana](https://discourse.nodered.org/u/Miriana)
#### Post date: [5 October 2021 10:51 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882/1 "2021-10-05T10:51:02Z")

</div>

Hi everyone,

I am trying to publish a message with MQTT on The Things Stack. I followed the instructions here [Send Messages | The Things Stack for LoRaWAN](https://www.thethingsindustries.com/docs/integrations/node-red/send/) and I used the code found at the following link ([TheThingsNetwork TTN decrypt payload · GitHub](https://gist.github.com/CurlyWurly-1/845bb5b8cf788939dd261f472c289f77#file-flow-json)) as downlink payload formatter (on The Things Stack)..I have no errors but no message arrives at The Thing Stack... Do you have any suggestions?

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [5 October 2021 11:21 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882/2 "2021-10-05T11:21:38Z")

</div>

Hi can you copy your flow please  
Also looks like your trying to decode your downlink the only thing you need to do is  
base64 encode your payload

Take read of this  
[https://www.thethingsindustries.com/docs/integrations/mqtt/#publishing-downlink-traffic](https://www.thethingsindustries.com/docs/integrations/mqtt/#publishing-downlink-traffic)

This is the sort of thing you need in a function node

```auto
var hexPL = var hexPL = Buffer.from('01557733', 'hex');
var base64PL = hexPL.toString('base64');
msg.payload = {
    "downlinks": [
        {
            "f_port": 2,
            "frm_payload": base64PL,
            "priority": "NORMAL",
            "confirmed": false,
            "correlation_ids": ["my-dowlink"]
        }
    ]
  };
msg.topic = "v3/app1@tenant1/devices/dev1/down/push";

```

---

<div class="post-metadata">

### Author: ![Miriana](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Miriana](https://discourse.nodered.org/u/Miriana)
#### Post date: [5 October 2021 12:50 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882/3 "2021-10-05T12:50:44Z")

</div>

This is the json code :

```auto
[
    {
        "id": "d991ed90e03c724c",
        "type": "tab",
        "label": "Flow 5",
        "disabled": false,
        "info": ""
    },
    {
        "id": "8945234d519c3224",
        "type": "inject",
        "z": "d991ed90e03c724c",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "10",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[0, 42, 255, 0]",
        "payloadType": "bin",
        "x": 490,
        "y": 240,
        "wires": [
            [
                "940a7ad4781f5ee8"
            ]
        ]
    },
    {
        "id": "6ae6832d05fae10e",
        "type": "mqtt out",
        "z": "d991ed90e03c724c",
        "name": "",
        "topic": "v3/ ***@tenant1/devices/*** /down/push",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "07b5ab05d787cc85",
        "x": 1090,
        "y": 240,
        "wires": []
    },
    {
        "id": "940a7ad4781f5ee8",
        "type": "function",
        "z": "d991ed90e03c724c",
        "name": "",
        "func": "return {\n \"payload\": {\n \"downlinks\": [{\n \"f_port\": 15,\n \"frm_payload\": msg.payload.toString(\"base64\"),\n \"priority\": \"NORMAL\"\n }]\n }\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 240,
        "wires": [
            [
                "239e6e5bc72e41c9",
                "6ae6832d05fae10e"
            ]
        ]
    },
    {
        "id": "239e6e5bc72e41c9",
        "type": "debug",
        "z": "d991ed90e03c724c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1010,
        "y": 160,
        "wires": []
    },
    {
        "id": "07b5ab05d787cc85",
        "type": "mqtt-broker",
        "name": "",
        "broker": "eu1.cloud.thethings.industries",
        "port": "1883",
        "tls": "283a670c.e20a28",
        "clientid": "",
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "283a670c.e20a28",
        "type": "tls-config",
        "name": "Default",
        "cert": "",
        "key": "",
        "ca": "",
        "certname": "",
        "keyname": "",
        "caname": "",
        "servername": "",
        "verifyservercert": true,
        "alpnprotocol": ""
    }
] 

```

I can't copy the file because I am a new user. Maybe from the the photos you can understand...

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [5 October 2021 17:08 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882/4 "2021-10-05T17:08:00Z")

</div>

ok that looks good to me  
a wee note don't share your MQTT Username  
obscure it v3/xxx@yyyy/devices/70b3d5e75e00dea2/down/push  
Assume for your End device ID you've used the LoRaWAN devEUI?  
Also looks like a Lansite device?

Add these topics to mqtt in node and create a debug node on each  
And see if that helps also in the TTN/i console put verbose logging on, your should see your downlink scheduled.

```auto
v3/xxxyyy@tenant1/devices/+/down/queued
v3/xxxyyy@tenant1/devices/+/down/sent
v3/xxxyyy@tenant1/devices/+/down/failed
v3/xxxyyy@tenant1/devices/+/down/ack

```

---

<div class="post-metadata">

### Author: ![Miriana](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Miriana](https://discourse.nodered.org/u/Miriana)
#### Post date: [6 October 2021 08:30 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882/5 "2021-10-06T08:30:55Z")

</div>

Thank you!!

---

<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 December 2021 08:31 UTC](https://discourse.nodered.org/t/mqtt-publish-on-the-things-stack/51882/6 "2021-12-05T08:31:30Z")

</div>

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