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

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:

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:
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:

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

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.

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… :wink:

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!