Page 1 of 1
Publish in MQTT JSON format
Posted: 19 May 2020, 20:05
by LeanzLatino
Hey iam trying to figure out how to get publish MQTT json format that homeassistant and many more application use.
Iam using gps plugin and would like to use value in this format.
{"latitude": 50.601972,"longitude": 10.112339, "Altitude": 20.0, "Speed": 2}
Thank you in advance!
Re: Publish in MQTT JSON format
Posted: 19 May 2020, 20:47
by grovkillen
Let's say your task name is "gps" and your value names are the ones you use in your example. Then:
Code: Select all
On gps#latitude Do
Publish,<mqtt topic>,{"latitude": [gps#latitude],"longitude": [gps#longitude], "Altitude": [gps#altitude], "Speed": [gps#speed]}
Endon
Where <mqtt topic> is whatever topic you plan on using.
Re: Publish in MQTT JSON format
Posted: 19 May 2020, 21:07
by dynamicdave
I thought the json string needed single quotes around the curly brackets... (in the recent ESP Easy releases)
Code: Select all
Publish,<mqtt topic>,'{"latitude": [gps#latitude],"longitude": [gps#longitude], "Altitude": [gps#altitude], "Speed": [gps#speed]}'
Re: Publish in MQTT JSON format
Posted: 19 May 2020, 21:10
by grovkillen
You're right! Thanks for that.
Re: Publish in MQTT JSON format
Posted: 19 May 2020, 21:30
by LeanzLatino
It doenst seem to change i have also tried.
On gps#latitude Do
Publish,%sysname%,: [gps#latitude],"longitude": [gps#longitude], "Altitude": [gps#Altitude], "Speed": [gps#speed]}
Endon
and also
On gps#latitude Do
Publish,coordinates,: [gps#latitude],"longitude": [gps#longitude], "Altitude": [gps#Altitude], "Speed": [gps#speed]}
Endon
I use same value that wiki recommend , i havent changed to Capital letters etc.
Re: Publish in MQTT JSON format
Posted: 19 May 2020, 21:39
by Ath
LeanzLatino wrote: ↑19 May 2020, 21:30
It doenst seem to change i have also tried.
Have you tried the example @dynamicdave gave? That uses the quotes around arguments containing spaces or commas, as required in current releases of ESPEasy
Your last examples have invalid JSON
Re: Publish in MQTT JSON format
Posted: 19 May 2020, 21:43
by LeanzLatino
Hey
Yes i tried now it sure does work.
Thank you alot!