mqtt rule - help needed

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Zodiac69
Normal user
Posts: 49
Joined: 13 Jun 2016, 17:20

mqtt rule - help needed

#1 Post by Zodiac69 » 08 Aug 2020, 19:12

Hi All
I presume i am doing something stupid...

I am subscribed to mqtt and i can see my status, analog value and i can control GPIO over mqtt.
I am trying to use a rule to send the IP address every 30 seconds as per the example under the rules, but i never see it triggered in the log or any info in my mqtt using mqtt explorer

on MQTT#Connected do
Publish,%sysname%/%unit%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
endon

Any pointers will be helpfull

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

Re: mqtt rule - help needed

#2 Post by grovkillen » 08 Aug 2020, 20:24

Code: Select all

On Rules#Timer=1 Do
....
EndOn
You need to act on the event.
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:

Zodiac69
Normal user
Posts: 49
Joined: 13 Jun 2016, 17:20

Re: mqtt rule - help needed

#3 Post by Zodiac69 » 08 Aug 2020, 22:15

Hi grovkillen

As i said, i am doing something stupid...

On Rules#Timer=1 Do
Publish,%sysname%/%unit%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

Still not working???

User avatar
Ath
Normal user
Posts: 185
Joined: 10 Jun 2018, 12:06
Location: NL

Re: mqtt rule - help needed

#4 Post by Ath » 08 Aug 2020, 22:28

But are you (also) starting the timer in the on mqtt#connected rule? It doesn't start by itself...

Zodiac69
Normal user
Posts: 49
Joined: 13 Jun 2016, 17:20

Re: mqtt rule - help needed

#5 Post by Zodiac69 » 08 Aug 2020, 22:47

Hi Ath

Sorry, i did not post the complete rule :(
----
On MQTT#Connected Do
Publish,%sysname%/%unit%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

On Rules#Timer=1 Do
Publish,%sysname%/%unit%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn
----
The only thing i saw in the log file is that it intentional reconnect to the mqtt, but i do not see the IP address getting pushed to the mqtt broker.

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

Re: mqtt rule - help needed

#6 Post by TD-er » 08 Aug 2020, 23:19

Does MQTT#connected ever fire?
You can try to trigger an LED, write a logentry in the rules, etc. to test.

Does the sysname have a space in it?
Maybe best to wrap the parameters with quotes, just to be sure.

Code: Select all

Publish,"%sysname%/%unit%/IP","%ip%"

Zodiac69
Normal user
Posts: 49
Joined: 13 Jun 2016, 17:20

Re: mqtt rule - help needed

#7 Post by Zodiac69 » 08 Aug 2020, 23:30

Hi TD-er

No spaces in sysname, sysname is only 4 alpha chars - Nuco
Wrapping them in quotes also did make any change.
I shall see if i can get some diagnostics going, but i suspect that the rule is not firing...

Zodiac69
Normal user
Posts: 49
Joined: 13 Jun 2016, 17:20

Re: mqtt rule - help needed

#8 Post by Zodiac69 » 08 Aug 2020, 23:43

So i change the rule to switch on the "Blue" LED on mqtt connect, it didn't, so it seems that rules are not firing - but check in lower in log.

On MQTT#Connected Do
Publish,"%sysname%/%unit%/IP","%ip%"
GPIO,2,0
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

On Rules#Timer=1 Do
Publish,"%sysname%/%unit%/IP","%ip%"
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

Here is the log file: - I press the Reset on my board

619: EVENT: System#Boot
1659: WIFI : Connected! AP: Zodiac01 (bla:bla:bal:bal:bla:bla) Ch: 4 Duration: 1033 ms
1661: WIFI : DHCP IP: 192.168.xxx.yyy (Nuco) GW: 192.168.xxx.yyy SN: 255.255.255.0 duration: 15 ms
1679: ADC : Analog value: 8 = 8.000
1692: SW : State 0.00
1701: EVENT: Time#Initialized
2767: EVENT: Clock#Time=Sat,23:34
2822: firstLoopConnectionsEstablished
2827: EVENT: WiFi#Connected
2861: WD : Uptime 0 ConnectFailures 0 FreeMem 19128 WiFiStatus WL_CONNECTED
2907: MQTT : Intentional reconnect
2958: MQTT : Connected to broker with client ID: Nuco/1
2962: Subscribed to: Nuco/1/#
2970: EVENT: Power#Analog=8.00
3027: EVENT: Activate#Activate=0.00
3129: ADC : Analog value: 8 = 8.000
3139: EVENT: MQTT#Connected - Here mqtt event fire, but blue LED does not come on???
3178: SW : State 0.00
3227: EVENT: Power#Analog=8.00
3327: EVENT: Activate#Activate=0.00
13105: ADC : Analog value: 15 = 15.000
13129: EVENT: Power#Analog=15.00
23101: ADC : Analog value: 8 = 8.000
23127: EVENT: Power#Analog=8.00
31984: WD : Uptime 1 ConnectFailures 0 FreeMem 15048 WiFiStatus WL_CONNECTED
33105: ADC : Analog value: 8 = 8.000
33129: EVENT: Power#Analog=8.00
43101: ADC : Analog value: 8 = 8.000
43127: EVENT: Power#Analog=8.00
53101: ADC : Analog value: 8 = 8.000
53129: EVENT: Power#Analog=8.00
60434: EVENT: Clock#Time=Sat,23:35

User avatar
ThomasB
Normal user
Posts: 715
Joined: 17 Jun 2018, 20:41
Location: USA

Re: mqtt rule - help needed

#9 Post by ThomasB » 09 Aug 2020, 03:27

1. Sometimes a rule event won't fire because of corruption in the rule file. For example, an unprintable character may be hiding in it. This evil situation can cause very strange behavior. I suggest deleting ALL the rule files and hand typing the rules again. Don't copy and paste since the source text might have the problem in it.

2. Visit Tools->Advanced->RuleSettings. Confirm "Rules" and "Old Engine" check boxes are both enabled.

3. Old versions of ESPEasy do not support MQTT#Connected. But that isn't the issue here since the event appears in the logs. But even so, try a different recent release.

@all: BTW, it is a good idea to mention your ESPEasy version number and hardware (board) when you post a problem in the forum.

- Thomas

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

Re: mqtt rule - help needed

#10 Post by TD-er » 09 Aug 2020, 09:26

As an addition to Thomas suggestion (which I didn't think of).
You can copy the text to a program like Notepad++, which allows to highlight special characters.

If you find any, please let me know, so I can perhaps add a check for such characters in the parser.

User avatar
Ath
Normal user
Posts: 185
Joined: 10 Jun 2018, 12:06
Location: NL

Re: mqtt rule - help needed

#11 Post by Ath » 09 Aug 2020, 10:20

Adding an 'eventlog' line in the script is often quite helpful:

Code: Select all

On Rules#Timer=1 Do
EventLog,"%sysname%/%unit%/IP,%ip%" // removed some quotes!
Publish,"%sysname%/%unit%/IP","%ip%"
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

Zodiac69
Normal user
Posts: 49
Joined: 13 Jun 2016, 17:20

Re: mqtt rule - help needed

#12 Post by Zodiac69 » 09 Aug 2020, 19:12

Hi All
Thank you for the assistance thus far. - Just for FYI, "Old Engine" was NOT enabled before.
So i started from scratch, wipe, re-programme - ESP_Easy_mega_20200703_normal_ESP8266_4M1M, board is from Electrodragon ESP8266 R3.
Setup everything like it was before. Update Rules Set 1 and confirmed that there is no spaces or "funny" characters.

Set log to Debug, but still nothing in my mqtt broker. I then decided to push the "Reset" button and check the log and i saw the following, but still nothing in my broker.
ACT : Publish,'Nuco/1/IP,192.168.2.195'
Command: Publish
Publish: Nuco/1/IP,192.168.2.195

I then removed all the quotation marks, and :D - it is working, see log below:
ACT : Publish,Nuco/1/IP,192.168.2.195
Command: Publish
Publish: Nuco/1/IP192.168.2.195

So my working rule now looks like this with no quotations: and i use the "Old Engine:"
On MQTT#Connected Do
Publish,%sysname%/%unit%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

On Rules#Timer=1 Do
Publish,%sysname%/%unit%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

It seems that after making changes to "Rules", a Re-Boot is the best as it seems that the rules don't always fire correctly after changes.
Thank you to everyone that assisted.

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

Re: mqtt rule - help needed

#13 Post by TD-er » 09 Aug 2020, 20:56

Using the 'old engine' is the best indeed.

I think I rename the new one to "experimental", as it is way harder to use.

User avatar
ThomasB
Normal user
Posts: 715
Joined: 17 Jun 2018, 20:41
Location: USA

Re: mqtt rule - help needed

#14 Post by ThomasB » 09 Aug 2020, 22:21

Glad you solved the problem.
It seems that after making changes to "Rules", a Re-Boot is the best as it seems that the rules don't always fire correctly after changes.
In your setup the reboot was needed because of the MQTT#Connected rule. Typically this rule trigger occurs soon after reboot when WiFi is established and the MQTT broker is found. That is to say, the edits to the rules were late to the party and the Connect rule needs the MQTT broker to change states (move from disconnect state to connect state). A reboot is one way to do this.

= Thomas

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

Re: mqtt rule - help needed

#15 Post by TD-er » 09 Aug 2020, 23:43

Just to let you know.

You can trigger those events as mentioned by Thomas.

Just enter the command

Code: Select all

event,MQTT#Connected
in the "command" field on the Tools page of the web interface.

buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Re: mqtt rule - help needed

#16 Post by buzzger0815 » 10 Aug 2020, 15:10

Hi!

How about sending your ip every minute. If every minute would be enough, sending the ip would be as simple as

Code: Select all

on Clock#Time=all,**:** do
  Publish,%sysname%/%unit%/IP,%ip%
endon

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests