Hi all
I need some pointers here please.
I have a esp with this build - ESP_Easy_mega_20200801_normal_ESP8266_4M1M
I have GPIO 13 set as "Output High" and GPIO 14 set as "Input"
I have a rule to monitor GPIO 13 and 14 and it seems to work:
on System#Boot do
Monitor GPIO,13
Monitor GPIO,14
endon
on GPIO#13=0 do
Publish,%sysname%/%unit%/Activate,0
endif
endon
on GPIO#13=1 do
Publish,%sysname%/%unit%/Activate,1
endif
endon
on GPIO#14=0 do
Publish,%sysname%/%unit%/ACK,0
endif
endon
on GPIO#14=1 do
Publish,%sysname%/%unit%/ACK,1
endif
endon
Now here is where it goes strange... and i understand why.
When GPIO 14 is low and i have a loss of power, the signal that pulled GPIO low now also disconnect inside the unit, when the power is restored, MQTT still show GPIO as "0" and not as "1".
when i query GPIO pin status i get:
{
"log": "",
"plugin": 1,
"pin": 14,
"mode": "input pullup",
"state": 1
}
Ok
I then tried to add the rule above to On MQTT#connect Do, but that does not seem to work
On MQTT#Connect Do
if [GPIO#13]=0
Publish,%sysname%/%unit%/Activate,0
endif
if [GPIO#13]=1
Publish,%sysname%/%unit%/Activate,1
endif
if [GPIO#14]=0
Publish,%sysname%/%unit%/ACK,0
endif
if [GPIO#14]=1
Publish,%sysname%/%unit%/ACK,1
endif
endon
Please indicate where i am missing the point
MQTT pin state on boot rule sort of working
Moderators: grovkillen, Stuntteam, TD-er
Re: MQTT pin state on boot rule sort of working
You're acting directly on the GPIO's themselves so there is no state stored in the RTC memory (which only may help in case of a crash, not power loss)
Also there is no update from the broker to set the GPIO's again.
So I guess the safest thing is to add a rule block acting on the boot event to set a flag signaling the state is not correct on the broker. (see command "let" to set a variable)
As soon as you have a new connection to the MQTT broker you may check to see if the state of the GPIOs may be out of sync and thus send out the publish calls.
You can even keep track of each changed GPIO pin in a variable and on the MQTT connected event publish the latest state of each pin, so you can be sure your broker is up-to-date with all pin states as soon as the connection has been restored.
Also there is no update from the broker to set the GPIO's again.
So I guess the safest thing is to add a rule block acting on the boot event to set a flag signaling the state is not correct on the broker. (see command "let" to set a variable)
As soon as you have a new connection to the MQTT broker you may check to see if the state of the GPIOs may be out of sync and thus send out the publish calls.
You can even keep track of each changed GPIO pin in a variable and on the MQTT connected event publish the latest state of each pin, so you can be sure your broker is up-to-date with all pin states as soon as the connection has been restored.
Who is online
Users browsing this forum: No registered users and 36 guests