does system#boot fire when waking from deep sleep?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dampa
Normal user
Posts: 87
Joined: 19 Jul 2018, 01:48

does system#boot fire when waking from deep sleep?

#1 Post by dampa » 20 Apr 2020, 14:00

Memos D1 Mini - ESP_Easy_mega-20200410_normal_ESP8266_4M1M

Should system#boot be triggered when waking from deepsleep? I would think that system#wake would be triggered but tht system#boot would only happen at a power on or a reboot being issued.

I have some code that sets a variable to 1 in a 'on system#boot do' rule, then when MQTT#Connected, I test the variable and if it is on, I turn it off and send a mqtt message to Node-red and send out an email.

The idea is when the dvice is powered on, it will send an email with the IP address of the device.

Code: Select all

on System#boot do
   TaskValueSet,5,3,1    //set send email on (mydata#sendmail)
endon

on MQTT#Connected do
   if [mydata#sendemail]=1
     TaskValueSet,5,3,0    //set send email off
     publish greenhouse/msg/%sysname%/email,'{"ssid":"%ssid%","ip":"%ip%"}'
   endif
endon
The issue it that everytime the device wakes from deepsleep, I end up getting an email. That means System#boot must be running on wakeup from deep sleep.

Is this how it is suppose to work? If so is tehre a reference to what events happen during a power/reset verses a deepsleep?

thanks!
Last edited by dampa on 28 Apr 2020, 11:41, edited 1 time in total.

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

Re: does system#boot fire when waking from deep sleep?

#2 Post by grovkillen » 20 Apr 2020, 17:08

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:

dampa
Normal user
Posts: 87
Joined: 19 Jul 2018, 01:48

Re: does system#boot fire when waking from deep sleep?

#3 Post by dampa » 20 Apr 2020, 18:07

Thanks grovkillen I saw that but it seems System#Wake and System#Boot are effectivaly equilivant.

I did some testing and when waking from deepsleep or rebooting/powering on, system#wake runs first then system#boot.

Here is how I came to that conclusion. I created 5 rules and a 'Generic - Dummy Device' called 'debug' with a value called 'x'. The idea was in System#Boot to add 1 to 'x', in System#Wake add 10, System#sleep add 100 etc. In a boot I got 11011. While it showed me which got run, it didn't tell the order so I added a second variable to 'debug' called 'n', added a new command to each ruleset (N=N+1) and changed the rules so System#Boot adds 1*n to 'x', System#Wake add 10*n so the rules are:

Code: Select all

on System#Boot do
   TaskValueSet 1,2,[debug#n]+1
   TaskValueSet 1,1,[debug#x]+1*[debug#n]
endon

on System#Wake do
   TaskValueSet 1,2,[debug#n]+1
  TaskValueSet 1,1,[debug#x]+10*[debug#n]
endon

on System#sleep do
   TaskValueSet 1,2,[debug#n]+1
  TaskValueSet 1,1,[debug#x]+100*[debug#n]
endon

on WiFi#Connected do
   TaskValueSet 1,2,[debug#n]+1
  TaskValueSet 1,1,[debug#x]+1000*[debug#n]
endon

on MQTT#Connected do
   TaskValueSet 1,2,[debug#n]+1
  TaskValueSet 1,1,[debug#x]+10000*[debug#n]
endon

on gosleep do
  deepsleep,10
endon

on reset do
  TaskValueSet 1,1,0
  TaskValueSet 1,2,0
endon 
the values can be reset by the http command

Code: Select all

http://your-ip/control?cmd=event,reset
and deepsleep (remember to connect D0 to RST to wake back up) can be run with

Code: Select all

http://your-ip/control?cmd=event,gosleep
With this a power on or reboot ends up with d=43012 (System#Wake, System#Boot, WiFi#Connected, MQTT#Connected) while a deepsleep ends up with d=54123 (System#sleep, System#Wake, System#Boot, WiFi#Connected, MQTT#Connected)

So System#Wake and System#Boot always run one after the other and there is no way to tell if it is a power on/reboot vrs a wake from deepsleep...sigh
Last edited by dampa on 20 Apr 2020, 18:20, edited 1 time in total.

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

Re: does system#boot fire when waking from deep sleep?

#4 Post by grovkillen » 20 Apr 2020, 18:17

It's by design, Wake happens before Boot. Why? Wake is the first thing happening and Boot is when the boot sequence is done.
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:

dampa
Normal user
Posts: 87
Joined: 19 Jul 2018, 01:48

Re: does system#boot fire when waking from deep sleep?

#5 Post by dampa » 20 Apr 2020, 18:50

I found a solution! a cold boot (power on) initilizes all variables to 0 while a reboot from the console or a deepsleep preserves the variables so I can work with that. Thanks for responding and a GREAT product!

All I need to do is have a variable 'sendmail' and in tthe System#Boot rules say

Code: Select all

   if [mydate#sendmailm] = 0
      TaskValueSet 5,3,1
   endif
Then in the MQTT#connect have

Code: Select all

   if [mydata#sendemail]=1
     TaskValueSet,5,3,3    //set send email off
     publish greenhouse/msg/%sysname%/email,'{"ssid":"%ssid%","ip":"%ip%"}'
   endif
so on a cold boot, sendmail will be initilized to 0, the System#Boot rule will set it to 1 and the MQTT#Connect rule will see it is a 1 and set it to 3 and send a message to Node-RED to send out an email.

On a deepsleep, when it wakes, sendmail will be 3 so the System#Boot rule will never fire nor the MQTT#Connect rule.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests