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!
Publish in MQTT JSON format
Moderators: grovkillen, Stuntteam, TD-er
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Publish in MQTT JSON format
Let's say your task name is "gps" and your value names are the ones you use in your example. Then:
Where <mqtt topic> is whatever topic you plan on using.
Code: Select all
On gps#latitude Do
Publish,<mqtt topic>,{"latitude": [gps#latitude],"longitude": [gps#longitude], "Altitude": [gps#altitude], "Speed": [gps#speed]}
Endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: Publish in MQTT JSON format
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]}'
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Publish in MQTT JSON format
You're right! Thanks for that.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



-
- New user
- Posts: 3
- Joined: 19 May 2020, 20:00
Re: Publish in MQTT JSON format
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.
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.
Last edited by LeanzLatino on 19 May 2020, 21:39, edited 1 time in total.
Re: Publish in MQTT JSON format
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
/Ton (PayPal.me)
-
- New user
- Posts: 3
- Joined: 19 May 2020, 20:00
Re: Publish in MQTT JSON format
Hey
Yes i tried now it sure does work.
Thank you alot!
Yes i tried now it sure does work.
Thank you alot!
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 18 guests