Hallo, at first, excuse my English. ESPEasy is a great piece of work and I love it, thanks all for this great effort!!
And my question, I'd like to send from my ESP8266 a JSON mqtt message to my mqtt broker. Is there any way how to do it?
If I use url http://<myesp>/json, I receive correct JSON message and I want to the same data using mqtt. Is there any way how to use a rule to do so?
Of course, I can send, by rules, payload of every sensor separately, but I'd like to receive all informations in one JSON message and parse them directly in openHAB.
My configuration:
- ESP8266 D1 mini Pro
- latest MEGA build
- working MQTT communication to broker (openHAB MQTT @ rasppi3)
- set of sensors (DHT11. DHT22, HTU21D)
Thanks for any help! :]
JSON over MQTT?
Moderators: grovkillen, Stuntteam, TD-er
JSON over MQTT?
Please excuse my English, thanks!
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: JSON over MQTT?
The only thing with that is that you cannot know the age of the values since they will all be sent at the same time. Individual sent values will be sent on time of change or interval.
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
Re: JSON over MQTT?
Hi, thx for reply, there is no need to receive sensor's data asap on every change, in my project :] ..
I found some solution, it works for me. I dodn't know that I can publish text&variables as <value>, but it's possible, obviously.
So here my dev board, 1x DGT11, 1xDHT22 and one HTU21D (I2C):
And simple rule with mqtt publish
The result is valid JSON message:
I have to write it manually, but it works! Maybe it can help someone else ..
I found some solution, it works for me. I dodn't know that I can publish text&variables as <value>, but it's possible, obviously.
So here my dev board, 1x DGT11, 1xDHT22 and one HTU21D (I2C):
And simple rule with mqtt publish
Code: Select all
on System#Boot do
timerSet,1,1
endon
On Rules#Timer=1 do
Publish /%sysname%/JSON,{"Sysname":"%sysname%","Uptime":"%uptime%","DHT11indoorTemperature":"[DHT11indoor#Temperature]","DHT11indoorHumidity":"[DHT11indoor#Humidity]","DHT22outdoorTemperature":"[DHT22outdoor#Temperature]","DHT22outdoorHumidity":"[DHT22outdoor#Humidity]","HTU21DTemperature":"[HTU21D#Temperature]","HTU21DHumidity":"[HTU21D#Humidity]"}
timerSet,1,10
endon
The result is valid JSON message:
Code: Select all
{"Sysname":"ESPsensor","Uptime":"1","DHT11indoorTemperature":"23","DHT11indoorHumidity":"30","DHT22outdoorTemperature":"-1.20","DHT22outdoorHumidity":"42.90","HTU21DTemperature":"23.41","HTU21DHumidity":"100.00"}
I have to write it manually, but it works! Maybe it can help someone else ..
Please excuse my English, thanks!
Re: JSON over MQTT?
I'm using the version ESP_Easy_mega_20210802_normal_ESP8266_4M1M and the form that work fine is put payload between quotes "" like this:
publish,home/temp,"{"Time":"%systime%","Temp":"[temp#temp1]"}"
publish,home/temp,"{"Time":"%systime%","Temp":"[temp#temp1]"}"
Re: JSON over MQTT?
I guess you need to use different quotes for the last parameter of publish, like this:
Code: Select all
publish,home/temp,'{"Time":"%systime%","Temp":"[temp#temp1]"}'
Re: JSON over MQTT?
You're right. Work fine with both kind of quotesTD-er wrote: ↑19 Aug 2021, 21:45I guess you need to use different quotes for the last parameter of publish, like this:For explanation, see: https://github.com/letscontrolit/ESPEasy/issues/2724Code: Select all
publish,home/temp,'{"Time":"%systime%","Temp":"[temp#temp1]"}'
Re: JSON over MQTT?
It only works fine with the same quotes if the argument parsing is set to be more tolerant.
Either by checking this option in the tools->Advanced page, or you're running one of the commands that explicitly have the parameter parsing a bit more tolerant.
Not sure which commands have it, but I guess it might be "logentry"
Either by checking this option in the tools->Advanced page, or you're running one of the commands that explicitly have the parameter parsing a bit more tolerant.
Not sure which commands have it, but I guess it might be "logentry"
Who is online
Users browsing this forum: Google [Bot] and 126 guests