# Need Help ASAP: Updating node-red function to work with MQTT

**URL:** <https://www.thethingsnetwork.org/forum/t/need-help-asap-updating-node-red-function-to-work-with-mqtt/51253>\
**Category:** The Things Stack v3\
**Created:** [September 2, 2021, 8:07pm UTC](https://www.thethingsnetwork.org/forum/t/need-help-asap-updating-node-red-function-to-work-with-mqtt/51253 "2021-09-02T20:07:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZiffyClyro](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ziffyclyro/32/35697_2.png) [@ZiffyClyro](https://www.thethingsnetwork.org/forum/u/ZiffyClyro)\
**Post date:** [September 2, 2021, 8:07pm UTC](https://www.thethingsnetwork.org/forum/t/need-help-asap-updating-node-red-function-to-work-with-mqtt/51253/1 "2021-09-02T20:07:28Z")

</div>

Hello,  
I am quite new to working with both LoRa and TTN. Currently I am working on a school project, and I am using node-red to send downlink messages to the TTN. My problem is that I am not sure how exactly should I return my needed payload from a function node in node-red. The current code I based my school project on was made with the discontinued palette **node-red-contrib-ttn** , using the **ttn uplink** node and the **ttn downlink** node. The code in the function node is as follows, and needs to be converted to a format that an mqtt out node would understand:

```javascript
if (msg.payload.water_level === 0) {
     msg.payload.pump_running = 1;
 }
 if (msg.payload.water_level === 5) {
     msg.payload.pump_running = 0;
 }
 return msg;

```

The uplink payload is as follows:  
 ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/0/b/0b887d4dc20007dc67cbac4a587ac10c47c69115.png)  
Note: I simulated a uplink because I am currently unable to connect to a gateway (I am at home, not at my university where we have gateways).

I am also not sure if I wrote the correct topic in the mqtt out node, should the topic be:  
`v3/lora-pumpa/devices/eui-a8610a30392c6d0b/down/push`  
or  
`v3/lora-pumpa/devices/a8610a30392c6d0b/down/push`

This is a school project with a deadline, so I would appreciate if someone could help me out ASAP.

---

<div class="post-metadata">

**Author:** ![Johan\_Scheepers](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/johan_scheepers/32/48536_2.png) [@Johan\_Scheepers](https://www.thethingsnetwork.org/forum/u/Johan_Scheepers)\
**Post date:** [September 2, 2021, 8:29pm UTC](https://www.thethingsnetwork.org/forum/t/need-help-asap-updating-node-red-function-to-work-with-mqtt/51253/2 "2021-09-02T20:29:14Z")

</div>

**node-red-contrib-ttn** This package has been deprecated and you need to use now MQTT intergradation.

Search the forum and you will find lots to read and examples on it.

> [@MQTT in Node-RED \[HowTo\]](https://www.thethingsnetwork.org/forum/t/mqtt-in-node-red-howto/39909):
>
> [Node-RED](https://nodered.org/) has built-in support to act as an MQTT client, which can be used with [TTN’s MQTT Data API](https://www.thethingsnetwork.org/docs/applications/mqtt/). warning For new developments, one should not use the The Things Network’s [node-red-contrib-ttn](https://www.npmjs.com/package/node-red-contrib-ttn), which is no longer supported. Setting up the MQTT client The following may seem a lot of steps, but Node-RED will guide one through the initial setup. For the current version V2 as used on the TTN community network: Drop an “mqtt in” node on your flow: [mqtt in] Double-click it: [mqtt in] …

---

<div class="post-metadata">

**Author:** ![Jeff-UK](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeff-uk/32/35697_2.png) [@Jeff-UK](https://www.thethingsnetwork.org/forum/u/Jeff-UK)\
**Post date:** [September 2, 2021, 8:30pm UTC](https://www.thethingsnetwork.org/forum/t/need-help-asap-updating-node-red-function-to-work-with-mqtt/51253/3 "2021-09-02T20:30:42Z")

</div>

School project or not be aware that downlinks generally are fround upon as each downlink renders the transmitting GW deaf to uplinks for ALL users in range - a heavy price for one users/one applications convenience. That said they are permitted but again be aware of the TTN FUP, which because of the impact outlined, limits you to 10 max per day - and that includes e.g. join request process. Also on assumption you are turning a pump on and off perhaps under LoRaWAN control, be sure to ask yourself what happens if the command does not get through (its RF and subject to interference & blocking after all!) - water level overflow? Water level run dry? Pump burn out because…etc. Best always to implement a local (safety as a min - operational + safety at best) control loop and simply use LoRaWAN for monitoring or occasional system adjustment/tweaking vs critical stop/start etc… 😉

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [September 2, 2021, 9:47pm UTC](https://www.thethingsnetwork.org/forum/t/need-help-asap-updating-node-red-function-to-work-with-mqtt/51253/4 "2021-09-02T21:47:40Z")

</div>

> [@ZiffyClyro](#):
>
> This is a school project with a deadline, so I would appreciate if someone could help me out ASAP.

So your first learning experience is about briefing people when you are under pressure:

- Deadline? What deadline? A deadline has a date and time but nothing concrete mentioned. Do you have a day, a week, a month?
- ASAP? When is that? How does it link to the deadline? How much time do you estimate you need from getting some help & the deadline?
- What does the uplink tell us? Why did you include it?
- Does your Node-RED receive uplinks OK?
- How did you determine the format of the MQTT downlink?

There’s no problem helping point people doing school/college/university course work in the right direction, but it’s not good for you to have stuff handed to you as you won’t learn that way. So be prepared!
