-->
Page 1 of 1

Force timed light sleep, delay again after wake up

PostPosted: Mon Jul 13, 2020 1:57 pm
by space_noodle
Hi experts! I am working on a small sketch to periodically check a web service as well as handling a user button push. The main functions are:

- wake up every X seconds and call a web service
- go to forced light sleep for X seconds or GPIO interrupt

Here is the code https://github.com/williamlian/activity ... _sleep.ino

The whole force sleep code I was following the LowPowerMode example from the library https://github.com/esp8266/Arduino/tree ... wPowerDemo

My problem is, every time it wakes from light sleep - either by timer or GPIO, I can see an immediate callback from the Serial print, but then another 10s delay (set by delay).

As you can see from my sleep function:
Code: Select allvoid sleep() {
  WiFi.mode(WIFI_OFF);
  // stop (but don't disable) the 4 OS timers
  extern os_timer_t *timer_list;
  timer_list = nullptr; 
  wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
  gpio_pin_wakeup_enable(BTN_PIN, GPIO_PIN_INTR_LOLEVEL);
  wifi_fpm_set_wakeup_cb(wakeupCallback);
  Serial.println("start sleep\n\n");
  Serial.flush();
  wifi_fpm_open();
  wifi_fpm_do_sleep(SLEEP_MS * 1000);  <------
  delay(SLEEP_MS + 1);                 <------
}


In my setting SLEEP_MS = 10, so every 10s I will see a print from Serial of "Sleep Interrupted", followed by another 10s delay, then it goes back to the start of the loop() function.

According to the example (and my test as well), by using the callback function, the extra delay is skipped, and the code goes to next line immediately after the callback returns. I wonder why it is not the case in my code.

I followed the instruction and I think I don't have any outstanding timer (as you can see I commented out the tickers just to make sure I don't have any timer), nor PWMs.

Could you help me to debug how could I make the wake up without extra delays? Thank you very much!