Send settings/rules etc. through MQTT (in JSON format)?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Send settings/rules etc. through MQTT (in JSON format)?

#1 Post by grovkillen » 19 Jan 2017, 13:06

Hi,

I'm new here but have been using ESPeasy for some time. I love the firmware but have some suggestions for the road map. I would like to update my nodes through MQTT instead of using the WebGUI. MQTT is able to carry quite a lot of data and if I could just send my settings/config (+ rules?) file as a JSON message it would be a lot easier to do the procedure more automatically. Maybe even send a firmware path for future updates.

Another thing I have created in order to have ALL my nodes respond on commands is to use MQTT import and "sniff" for the topic "cmdMQTT". I have the cmdMQTT retained at server with the value of 1, that means that everytime a node is started/booted it will signal out it's IP number (see rules below). Any suggestions is welcomed! :)

Rules (you might add more numbers for more responses):

Code: Select all

on sniff#cmdMQTT=1 do
  Publish %sysname%/IP,%ip%
endon

on sniff#cmdMQTT=2 do
  Publish %sysname%/Time,%systime%
endon
PS. How come rules are not saved with the config file?
PS2. You all know that leading forward flash is considered bad practice in MQTT topic format. Link>>

Don’t use a leading forward slash
It is allowed to use a leading forward slash in MQTT, for example /myhome/groundfloor/livingroom. But that introduces a unnecessary topic level with a zero character at the front. That should be avoided, because it doesn’t provide any benefit and often leads to confusion.
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#2 Post by HAbuild » 11 Feb 2018, 10:12

https://www.letscontrolit.com/wiki/inde ... QTT_Import

So there is this topic and the official page, is it redundant?
Was this implemented? I can't even get close to getting it to work. The commands don't seem to exist on a nodemcu board atleast. Nor do the rules seem to work for receiving MQTT payloads, although that is probably because I don't know to use them.
Can any one shed some light on this?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#3 Post by grovkillen » 11 Feb 2018, 10:24

When I wrote this I wasn't a part of the crew. The wiki is the correct place to go to.

Can you send screen shots of your unit?
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#4 Post by HAbuild » 11 Feb 2018, 10:58

Screenies!
Nodemcu Amica Bottom.PNG
Nodemcu Amica Bottom.PNG (403.5 KiB) Viewed 15754 times
Nodemcu Amica top.PNG
Nodemcu Amica top.PNG (675.23 KiB) Viewed 15753 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#5 Post by grovkillen » 11 Feb 2018, 11:00

Of the web GUI please :)
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#6 Post by HAbuild » 11 Feb 2018, 11:08

Moar Screenies!
main.PNG
main.PNG (20.69 KiB) Viewed 15743 times
What are you trying to find out? I don't have the rules or sniff#cmdMQTT in atm the moment, because I decided to move on to a reed switch.
So I was basically copying your example, then trying to send a payload of 1 to somewhere! sorry still learning. I couldn't get the commands to work in HTML(although that was probably nubness) or shouldn't they work directly from the serial monitor? or do they need a preface? systime, time, status, ip, don't work in serial either

http://MYIP/control?cmd=systime
Unknown or restricted command!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#7 Post by grovkillen » 11 Feb 2018, 12:28

Do you even have a MQTT broker/server running? If you want help you'd need to upload your entire setup (with screenshots). I would like to help but it's hard when I'm missing a lot of the puzzle.
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#8 Post by HAbuild » 11 Feb 2018, 13:46

My initial point of posting in this thread was because the commands in the example don't work even in the serial monitor for me. Well except reboot. So if the commands don't work how am I going to call them from anywhere let alone MQTT?

Yes I have a MQTT Broker running on a RPi, which is working fine when I get the command right. I use it to pulse my relay on GPIO,16, without an issue and I receive a payload back in either text or JSON.


Screenshoots
commands unknown
commands unknown
Serial MAIN ISSUE.PNG (26.6 KiB) Viewed 15729 times
Unknown command
puttering along
puttering along
Serial 1.PNG (30.96 KiB) Viewed 15729 times
Normal action
The Rules Example as loaded.
The Rules Example as loaded.
Rules page 2.PNG (24.44 KiB) Viewed 15729 times
should Publish [%sysname%/Time,%systime%] need a Bracket? or < > or should work without / even though thats poor form?

working rules of a sort.
working rules of a sort.
Rules page 1.PNG (25.1 KiB) Viewed 15729 times
rules that could use improvement.
Handy Link to know
Handy Link to know
JSON.PNG (16.04 KiB) Viewed 15729 times
IP/json FUN
cmdMQTT this seems uneeded if you can topic payload cmd
cmdMQTT this seems uneeded if you can topic payload cmd
Device MQTT Import.PNG (26.04 KiB) Viewed 15729 times
?? just an alternate to topic %sysname%/cmd,reboot ??
devices enabled
devices enabled
Devices.PNG (32.51 KiB) Viewed 15729 times
enabled, DHT died, how do you pull that DHT : reading unknown?
how would I pull this to MQTT?

CONFIG
next post

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#9 Post by HAbuild » 11 Feb 2018, 13:48

CONFIG
generic nom
generic nom
config name.PNG (8.88 KiB) Viewed 15728 times
HAB MQTT connected
HAB MQTT connected
Controllers HAB.PNG (11.03 KiB) Viewed 15728 times
connected MQTT

pinouts
pinouts
Hardware.PNG (43.57 KiB) Viewed 15728 times
connections

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#10 Post by grovkillen » 11 Feb 2018, 14:03

How did you set up your controller?
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#11 Post by HAbuild » 11 Feb 2018, 14:19

HAB settings
HAB MQTT settings
HAB MQTT settings
HAB MQTT settings.PNG (21.3 KiB) Viewed 15706 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#12 Post by TD-er » 11 Feb 2018, 14:23

Just a question. Why do you keep masking the IP-address?
Don't get me wrong, awareness for security is a good thing.
But I am afraid you might be using public IP-addresses for ESPeasy and that's not a good idea.
Showing internal IP-addresses is not really a security risk, since they are not reachable for people not connected to your local network.

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#13 Post by HAbuild » 11 Feb 2018, 14:32

IP is a local address, to a Local Broker on my RPi OpenHabian build.

Ok I think I may understand.
The commands are command.ino correct? so they won't work like a plugin and must be forced to echo out to a topic?
So you can't directly call them. you have to force an indirect call?

If that's not the case, can't you only call PLUGINS from MQTT?

eg
%sysname%/Garage\cmd,GPIO,15,1 works directly from publish
%sysname%/cmd, systime or systime, can sends a payload that is ignored.

Or perhaps I am completely wrong.



https://www.letscontrolit.com/wiki/inde ... _Reference
command.ino
command.ino
command ino.PNG (4.89 KiB) Viewed 15698 times
plugin list
plugin list
SOnotAplugin.PNG (3.95 KiB) Viewed 15698 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#14 Post by TD-er » 11 Feb 2018, 14:54

You can also send commands via a HTTP-url.
http://<espeasyip>/control?cmd=<command>

For example a command I recently tested (and extended) on my board with OLED display connected:
http://192.168.1.75/control?cmd=OLEDFRAMEDCMD,off

As described at the top of this page: https://www.letscontrolit.com/wiki/inde ... _Reference

The references to the .ino files is some dump GrovKillen made last week to document all commands.
And for me a reference to make sure all commands can be used via all supported channels.
And also for people who want to look into the source to see what the command really does.

Oh and those parts with %-signs, these will be replaced by the things they reference.
For example %systime% will be substituted by the actual time known by the ESP board.

And another thing, don't use spaces in commands. Just a comma to separate the command and the parameters.

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#15 Post by HAbuild » 11 Feb 2018, 15:06

Yep that HTML bit is nice too.

SO The RAW LIST of commands, which are not in the table above are not accessible as such, so systime, ip, status are not in the table are unknown commands and SO the example rules won't work and the sniff will never have values.
So what is the point of that page!? :) Like I said I can already send commands using mqtt, I just wanted to know if systime etc are real commands.

edit: for clarity I mean what is the point of this page, it seems to be redundant at the moment
https://www.letscontrolit.com/wiki/inde ... QTT_Import

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#16 Post by grovkillen » 11 Feb 2018, 15:14

HAbuild wrote: 11 Feb 2018, 15:06 .... so systime, ip, status are not in the table are unknown commands....
You got it all mixed up. These are variables, not commands. The RAW list is for reference (as clearly stated). The list above is the official user command list.
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 :idea: :idea: :idea:

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#17 Post by grovkillen » 11 Feb 2018, 15:23

MQTT import is used to make external information available internally. So no, it is not redundant.

You can send a number to the topic (as an example) :, "cmdMQTT" and all units which listen to this topic will receive it simultaneously.

It's really powerful.
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#18 Post by HAbuild » 11 Feb 2018, 15:59

grovkillen wrote: 11 Feb 2018, 15:23 MQTT import is used to make external information available internally. So no, it is not redundant.

You can send a number to the topic (as an example) :, "cmdMQTT" and all units which listen to this topic will receive it simultaneously.

It's really powerful.
OOOO so 4 topics the ESP-Easy subscribes to. to say set reboot or start a task, like power down over night or something. and import lets you do this easily to multiple devices. by sending a 1 to cmdMQTT.

I was trying to sniff a systime off a device or there abouts. Thanks.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#19 Post by grovkillen » 11 Feb 2018, 16:03

Great! Glad to have helped :)
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 :idea: :idea: :idea:

HAbuild
Normal user
Posts: 15
Joined: 10 Feb 2018, 08:16

Re: Send settings/rules etc. through MQTT (in JSON format)?

#20 Post by HAbuild » 11 Feb 2018, 16:46

Somethink like this would help me I think. as a novice with no coding background.

subscribeMQTT.PNG
subscribeMQTT.PNG (31.89 KiB) Viewed 15669 times

subscribeMQTT.PNG
subscribeMQTT.PNG (31.89 KiB) Viewed 15669 times
rules for example

Code: Select all

on sniff#cmdMQTT=1 do
  Publish %sysname%/IP,%ip% // I am alive and this is my address
endon


on sniff#cmdMQTT=2 do
  Publish %sysname%/Time,%systime% //The current time on this device will published to cmdMQTT/TIME/
endon                                                       // possible to adjust time if not using NTP?

on sniff#cmdMQTT=3 do
 Publish %sysname%/status,Rebooting   //set a non focused reboot to multiple devices.
 Reboot
endon

on sniff#cmd/REBOOT/time/=4 do   //reboot at the time based on persistence on broker?
  Publish %sysname%/status,Rebooting 
 Reboot
endon
ENABLE
what you should see on enable.PNG
what you should see on enable.PNG (7.7 KiB) Viewed 15668 times
someone publishhed.PNG
someone publishhed.PNG (12.86 KiB) Viewed 15666 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send settings/rules etc. through MQTT (in JSON format)?

#21 Post by grovkillen » 11 Feb 2018, 17:09

V2.1.0 is hopefully going to add more features with mqtt groups etc. But for now mqtt import is the way to go.
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 :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 31 guests