Sending json text via MQTT

Anyone know how to send messages through MQTT with a local broker? My settings are:

Lilygo t3s3 running 2.3.4.ea61808 Beta
Channel 0 (primary): LongFast
Uplink: Enabled
Downlink: Enabled

MQTT:
enabled: yes
IP: 10.55.0.106 (mosquitto broker running on my LAN)
username: blank
password: blank
encrypted: false
json: true
topic: msg/US
client proxy: false

I’m able to see the json messages of received direct messages like so:

msh/US/2/json/LongFast/!fa5a18e8 {"channel":0,"from":413545356,"id":1604305848,"payload":{"text":"test message"},"rssi":-75,"sender":"!fa5a18e8","snr":6,"timestamp":1713383600,"to":1976953804,"type":"text"}

But I’m not able to send. I’ve tried:

mosquitto_pub -d -h 10.55.0.106 -t 'msh/US/2/json/LongFast/!18a6338c' -m '{"channel":3,"from":413545356,"id":1604305993,"payload":{"text":"test12"},"sender":"!18a6338c","to":1976953804,"type":"text"}'

The above complains about the topic not being “mqtt” or downlink being disabled (it’s not).

I also tried:

mosquitto_pub -d -h 10.55.0.106 -t 'msh/US/2/json/mqtt/!18a6338c' -m '{"channel":3,"from":413545356,"id":1604305993,"payload":{"text":"test12"},"sender":"!18a6338c","to":1976953804,"type":"text"}'

My local node seems to be ignoring the message, however. Nothing gets output over the USB serial debug.

Has anyone been able to send json via MQTT?

One thing I noticed from the docs (MQTT | Integrations Overview | Meshtastic) is that the “type” is supposed to be “sendtext”, not “text”.

1 Like

It worked! Thanks. This was the command I used:

mosquitto_pub -d -h 10.55.0.106 -t 'msh/US/2/json/mqtt' -m '{"channel":0,"from":4200208616,"payload":"test2 from CLI","to":1976953804,"type":"sendtext"}'

image

Hello, I encountered this issue. My JSON message is as follows: After sending it on the server, it can be successfully subscribed to on the topic, but it cannot be received successfully on the Meshtastic app. Do you know what might be the issue?

{
  "channel": 0,
  "from": 3774247732,
  "payload": "test2 from CLI",
  "type": "sendtext"
}

Please carefully follow: MQTT | Integrations Overview | Meshtastic

For example, you have to add a channel named “mqtt” where you publish this JSON message to.

Hello! Thank you for your help. Besides, I have another question. When I send a json message from the device to the server using mqtt, the Chinese automatically becomes / u 0000 empty string, Do you have a solution to this?

when i send chinese by my device,some errror touble me
{“channel”:0,“from”:3774327000,“id”:3643018114,“payload”:{“text”:“\u0000\u0000\u0000”},“sender”:“!e0f7a8d8”,“timestamp”:1717572789,“to”:4294967295,“type”:“text”}
there is always \u0000\u0000\u0000
could you please help me?

Unfortunately the light-weight JSON library in the firmware doesn’t support special characters.

Reference: [Bug]: json (payload) utf-8 characters converted to \n0000 · Issue #3562 · meshtastic/firmware · GitHub