Read GPIO's status during a Reboot

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
ohaldi
Normal user
Posts: 71
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Read GPIO's status during a Reboot

#1 Post by ohaldi » 06 Nov 2024, 08:56

Hello
When my ESP32 restarts, it sends me a correct "nofity 1" email to inform me that it has restarted.
But it also sends me the "notify 2" email. I think the ESP hasn't yet read the GPIOs on reboot.
If I check the devices with web access, my entry Switch - Switch DOOR ❷ GPIO-19 State: is set to 1.
Should I set a timer or delay to solve this problem?

Top of my Rules:
on System#Boot do
LCD,4,1,%ip% // Show IP
notify 1 //Send Email System Boot
endon

//will run once a day at noon
On Clock#Time=All,23:00 do
reboot
endon

on Door#State=0 do // Door is open
TimerSet,1,0 // Stop Loops
event,Progress
LCD,1,1,""
LCD,2,1,"Das Tor ist offen "
notify 2 // Email Door is open!
endon
// etc...
Many thanks in advance for your help
Otto

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

Re: Read GPIO's status during a Reboot

#2 Post by TD-er » 06 Nov 2024, 09:17

First rule of ESPEasy rules: Do not use delay.

The reason why you should not use delay is that it will block anything else running on the ESPEasy node.

It is best to set a timer and also keep in mind that calling 'event' will wait till the call is done before going further.
Quite often it is better to use 'asyncevent'.
This will place the event in a queue and handle it later.

The reasons why this is better:
- Rules parsing takes less time, causing less issues of missed state changes.
- For each event call, a new rules parser is started, taking up resources (especially tricky on ESP8266)
- Event calling event, calling... can create a loop.
- Asyncevent does check if the same event is already present in the event queue and only adds to the queue when unique.

The only reason why you may want to use event over asyncevent is when the next steps in the rules parsing depend on what is being done in the handling of that event.

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

Re: Read GPIO's status during a Reboot

#3 Post by TD-er » 06 Nov 2024, 09:21

Anyway, you could do a check at boot to see the pin state of that GPIO pin (or the task) at boot, like this:

Code: Select all

on System#Boot do
  asyncevent,"Door#State=[Plugin#GPIO#Pinstate#19]"
  LCD,4,1,%ip% // Show IP
  notify 1 //Send Email System Boot
endon
Or since the notify depends on the connected state, you may want to extend it a bit like this:

Code: Select all

on System#Boot do
  let,1,1 // set variable int#1 to signal we still need to send the boot email
  asyncevent,"Door#State=[Plugin#GPIO#Pinstate#19]"
endon

on WiFi#Connected do
  if [int#1] = 1
      notify 1 //Send Email System Boot
      let,1,0
  endif
  LCD,4,1,%ip% // Show IP
endon

Post Reply

Who is online

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