Chat freely about anything...

User avatar
By space_noodle
#87878 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 ... _sleep.ino

The whole force sleep code I was following the LowPowerMode example from the library ... 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() {
  // stop (but don't disable) the 4 OS timers
  extern os_timer_t *timer_list;
  timer_list = nullptr; 
  gpio_pin_wakeup_enable(BTN_PIN, GPIO_PIN_INTR_LOLEVEL);
  Serial.println("start sleep\n\n");
  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!