How to send msg from MQTT/NodeRed?

I have a Heltec successfully Wifi connected to a Raspberry Pi running NodeRed and the Aedes MQTT broker. I can read text, position, nodeinfo, telemetry packets. Yay !

Now I would like to also SEND a packet from nodered ➟ MQTT ➟ Wifi ➟ Heltec ➟ my mesh

Assuming the simplest “send msg” test case is:
INJECT NODE ➟ FUNCTION NODE ➟ MQTT OUT NODE
with the function node generating the appropriate message.

First, what exactly should be the format of the message created by the function node ? The official documentation is thin and ambiguous on that (MQTT | Meshtastic sender, payload, key) and another thread (Here is a newb MQTT tutorial for 1.3 - #9 by gparduino) suggests I need to add a type: “sendtext”.

It might be wrong, but I currently have

msg.payload = {
    "sender": "!e2e26840",  // address of my Heltec
    "from": 3806488640,     // address of my Heltec, maybe not needed ?
    "timestamp": msg.payload, // from inject node, maybe not needed ?
    "type": "text",                  // or "sendtext" ?
    "payload": {
        "text": "A test message from MQTT"
    }
}
return msg;

Second, for my MQTT out node, the topic is
msh/2/json/team
where “team” is the name of my primary channel.

This does not work - no messages appear on my mesh. Is the message format wrong ? Is the MQTT topic string wrong ? Is there a bug in the current json implementation ?

Any help would be appreciated, if it works I will be sure to share it on the discord as well.

I believe you need at least a "to": <nodeNum> as well. For a broadcast, it will be 0xFFFFFFFF (4294967295).

Thank you, that’s a good idea, to make the packet more like the ones I receive for type text.

I tried adding a
to: 4294967295
but it did not make a difference, nothing was sent.
I also wonder about the redundancy / ambiguity of that “to” and the topic of the MQTT out node which specifies a destination, too. (Either the channel msh/2/json/team or a specific node msh/2/json/!e2e26840)

So, still no success

What’s the type of the value? If it’s an int32, 0xFFFFFFFF should be -1.

If it still doesn’t work, I would advise to connect your device to a PC via USB and check the serial logs using meshtastic --noproto. It will show if it sees something and you can probably deduce what’s wrong.

well this is strange. Per a tip from discord, I fired up MQTT Explorer, subscribed to the Aedes MQTT broker I have set up in NodeRed.
When I trigger the send WHILE MQTT EXPLORER IS LISTENING, it goes through to the heltec and mesh. If I quite MQTT explorer and try the same thing, it does not get through.
I have no explanation for this behavior. Isnt the heltec just a regular subscriber to the MQTT broker just like the MQTT Explorer ? How would the presence of the latter influence the former ?

updating here: this was too strange, so I rebooted my pi, nodered, mqtt etc. And now I am able to send without MQTT explorer app in the mix. Perhaps something was stuck somewhere in the pipes…
Anyway, no hard cause, but if anyone else runs into this, perhaps try rebooting too.

Credit for the working msg format and mqtt channel goes to pdxlocs on discord:

msg.payload = {
    "channel":  "0",
    "sender":   "broker",
    "type":     "sendtext",
    "payload":  msg.payload
}
return msg;

and mqtt out topic:
msh/2/json/team

Thanks to @cordToad explanations I’ve tried a MQTT publish with this JSON

{
    "channel": "0",
    "sender":  "broker",
    "type":    "sendtext",
    "payload": {
        "text": "mqtt-test"
    }
}

to the normal LongFast channel: msh/2/json/LongFast

I’m trying with the Raspberry Pi with the latest 2.2.18. I can send text to the LongFast channel with the CLI. But the mqtt method does not work for me. What I can see in the log on the Raspberry Pi is:

INFO  | 20:36:18 395 [mqtt] JSON Received on MQTT, parsing..
DEBUG | 20:36:18 395 [mqtt] Found Channel name: LongFast (Index 0)
DEBUG | 20:36:18 395 [mqtt] JSON Ignoring downlink message we originally sent.

That’s all. Nothing happens. Can anyone help? I’m trying since hours. Or is this yet not working on the Raspberry PI package?

Thanks in advance!

Short update, it works now. Encryption was enabled in the mqtt module config on the meshtastic device. With Encryption disabled messages from mqtt will be sent to the mesh flawlessly :smiley:

1 Like

Yay, congratulations !

For future/other peoples reference:

I was using

Pi 4
NodeRed 3.1.3
Aedes 0.12.0 MQTT broker
and firmware 2.2.16 on a Heltec v3 serving as the MQTT gateway.

I did end up rebooting everything and after that it worked. My previous permutations may have clogged up some things in the MQTT pipes or there was just a bug. Try that as well, who knows…

I know the devs like us to use protobufs, but it is hard to beat the simplicity of the JSON api once it works. Also it is “self maintained” inside the firmware if anything in the protobuf formats change, so you don’t have to worry about having to check/update the protobuf definition files in your nodered. So perfect for somewhat less competent/lazy users like me !

1 Like

I have the same error message, I reboot. the mqtt receive it but the Heltec give me JSON Ignoring.

INFO | 20:36:18 395 [mqtt] JSON Received on MQTT, parsing…
DEBUG | 20:36:18 395 [mqtt] Found Channel name: LongFast (Index 0)
DEBUG | 20:36:18 395 [mqtt] JSON Ignoring downlink message we originally sent.

I change my mqtt server Aedes for mosquito and i have the same problem.

Heltec 3 Meshtastic version 2.2.17.

Any help would be appreciated !!!

And you have verified that:

in Heltec setup, MQTT module:
Enabled yes
client proxy likely no for you
encryption enabled: no
json enabled yes
tls no
and your mqtt server details

and then in channel settings
your main / channel 0 - double click on channel 0 in Channels settings,
uplink enabled yes
downlink enabled yes

Yes I done everything. did it with 2 different heltec.
I receive without a problem but when i try to send in json with MQTT, received it correctly but the radio received nothing ,and the heltec(connect to mqtt) console send me JSON Ignoring downlink message we originally sent.

“message we originally sent” means it received a rebroadcast from a packet your node send out. It will ignore it since it is not useful to your node.

I was using this enveloppe
{
“sender”: “broker”,
“type”: “sendtext”,
“payload”: {
“text”: “mqtt-test”
}
}
the working one
{
“sender”:“broker”,
“type”:“sendtext”,
“payload”: “mqtt-test”
}

1 Like

Sorry for this! I’ve only reported the encryption thing. But you’re absolutely right, the payload must not be declared as text also. I’ve forgotten to mention this too.