MQTT and JSON

221 views
Skip to first unread message

Brian Orpin

unread,
Feb 9, 2021, 7:16:05 AM2/9/21
to rtl_433
I seem to have tried every combination without success in doing what I'd like. I have probably missed to one to do it though...

Is it possible to output a JSON payload of all data to a single MQTT topic for each device?

```
rtl_433/device1 {"name": value, "name2":value}
```

Cheers

Christian Z.

unread,
Feb 9, 2021, 7:26:07 AM2/9/21
to rtl_433
The template string works for the devices, events, and states outputs in MQTT, so

rtl_433 -F 'mqtt,events=rtl_433[/type][/model][/subtype][/channel][/id]'

should work.

Brian Orpin

unread,
Feb 9, 2021, 7:59:11 AM2/9/21
to rtl_433
Thanks.

I think I'm missing something fundamental. What is the difference in output between devices, states, and events in terms of the data?

I also do not really understand how the template string expands.

I used

events=rtl2[/type][/model][/subtype][/channel][/id

And got this topic on the Broker

rtl2/Fineoffset-WHx080/0/236

with this data

{"time":"2021-02-09 12:44:24","model":"Fineoffset-WHx080","subtype":0,"id":236,"battery_ok":0,"temperature_C":1.0,"humidity":61,"wind_dir_deg":180,"wind_avg_km_h":0,"wind_max_km_h":2.448,"rain_mm":0.9,"mic":"CRC"}

Is it possible to concatenate the type, model etc into a single topic - rtl2/Fineoffset-WHx080-0-236

Christian Z.

unread,
Feb 9, 2021, 10:38:39 AM2/9/21
to rtl_433
The speparation char is only an option, so this works too

rtl_433 -F 'mqtt,events=rtl_433/[type]/[model]/[subtype]/[channel]/[id]'

but you'll get consecutive slashes if the token are unset.
It's just a plain string with [tokens] replaced.

In your case: rtl_433 -F 'mqtt,events=rtl2/[model]-[channel]-[id]'

And with recent rtl_433 version the character can be anything, so this also works now:

rtl_433 -F 'mqtt,events=rtl_433[/type][-model][*subtype][%channel][Xid]'

Brian Orpin

unread,
Feb 11, 2021, 3:44:21 AM2/11/21
to rtl_433
Ok thanks.

In that last example, should the character be outside the []?

AIUI - the [] is expanded and if that KV pair is in the received data the Key is replaced by the Value. Any other character can be included outside the [].

The char '/' will be interpreted as a subtopic.

Yes, that makes sense :) - Thanks.

Christian Z.

unread,
Feb 11, 2021, 3:50:31 AM2/11/21
to rtl_433
You can place any leading character before the token in [ ] and it will only be printed if that token exists.

foo/[channel]/bar will print foo//bar when there is no channel data.
foo[/channel]/bar will print foo/bar when there is no channel data.
And that can also be foo[Xchannel]/bar or foo[-channel]-bar etc. to print e.g. fooX1/bar.

Brian Orpin

unread,
Feb 11, 2021, 6:00:17 AM2/11/21
to rtl_433
I think what I did wrong when I tried this was I had spaces between the tokens, which was pretty stupid!

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages