Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By daniel.alzate
#70039 Hello, i hope anybody can help me validate this.

Im using some code from @davescherler https://github.com/esp8266/Arduino/issues/1381 to test light_sleep function, but with a little difference:

Code: Select allwifi_fpm_do_sleep(5000*1000);


When i use the original argument (0xFFFFFFF) the chips goes to sleep and im able to wake it up by using gpio, however, if i use the modified one (5000*1000) the chip never sleeps (continues the main loop), besides 5 seconds later the callback function is called.

I found this: https://github.com/espressif/ESP8266_RTOS_SDK/blob/master/include/espressif/esp_wifi.h

Code: Select all/**
  * @brief     Force ESP8266 enter sleep mode, and it will wake up automatically when time out.
  *
  * @attention 1. This API can only be called when force sleep function is enabled, after
  *               calling wifi_fpm_open. This API can not be called after calling wifi_fpm_close.
  * @attention 2. If this API returned 0 means that the configuration is set successfully,
  *               but the ESP8266 will not enter sleep mode immediately, it is going to sleep
  *               in the system idle task. Please do not call other WiFi related function right
  *               after calling this API.
  *
  * @param     uint32 sleep_time_in_us : sleep time, ESP8266 will wake up automatically
  *                                      when time out. Unit: us. Range: 10000 ~ 268435455(0xFFFFFFF).
  *    - If sleep_time_in_us is 0xFFFFFFF, the ESP8266 will sleep till
  *    - if wifi_fpm_set_sleep_type is set to be LIGHT_SLEEP_T, ESP8266 can wake up by GPIO.
  *    - if wifi_fpm_set_sleep_type is set to be MODEM_SLEEP_T, ESP8266 can wake up by wifi_fpm_do_wakeup.
  *
  * @return   0, setting succeed;
  * @return  -1, fail to sleep, sleep status error;
  * @return  -2, fail to sleep, force sleep function is not enabled.
  */
sint8 wifi_fpm_do_sleep(uint32 sleep_time_in_us);


Looking at documentation, especifically "...ESP8266 will not enter sleep mode immediately, it is going to sleep in the system idle task..." i wonder if the "arduino way" of looping indefinitely is avoiding the light sleep with timeout behaves as expected, since (i think) the cpu is never idle because of the infinite loop.

Any comment would help

Thanks