Sleep modes¶
API Reference¶
Header File¶
Functions¶
-
void
esp_deep_sleep
(uint32_t time_in_us)¶ Set the chip to deep-sleep mode.
The device will automatically wake up after the deep-sleep time set by the users. Upon waking up, the device boots up from user_init.
- Attention
- 1. XPD_DCDC should be connected to EXT_RSTB through 0 ohm resistor in order to support deep-sleep wakeup.
- Attention
- 2. system_deep_sleep(0): there is no wake up timer; in order to wake up, connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST
- Return
- null
- Parameters
uint32
: time_in_us : deep-sleep time, unit: microsecond
-
void
esp_deep_sleep_set_rf_option
(uint8_t option)¶ Call this API before esp_deep_sleep and esp_wifi_init to set the activity after the next deep-sleep wakeup.
If this API is not called, default to be esp_deep_sleep_set_rf_option(1).
- Return
- null
- Parameters
uint8
: option :0
: : Radio calibration after the deep-sleep wakeup is decided by byte 108 of esp_init_data_default.bin (0~127byte).1
: : Radio calibration will be done after the deep-sleep wakeup. This will lead to stronger current.2
: : Radio calibration will not be done after the deep-sleep wakeup. This will lead to weaker current.4
: : Disable radio calibration after the deep-sleep wakeup (the same as modem-sleep). This will lead to the weakest current, but the device can’t receive or transmit data after waking up.
-
void
esp_wifi_fpm_open
(void)¶ Enable force sleep function.
- Attention
- Force sleep function is disabled by default.
- Return
- null
- Parameters
null
:
-
void
esp_wifi_fpm_close
(void)¶ Disable force sleep function.
- Return
- null
- Parameters
null
:
-
void
esp_wifi_fpm_do_wakeup
(void)¶ Wake ESP8266 up from MODEM_SLEEP_T force sleep.
- Attention
- This API can only be called when MODEM_SLEEP_T force sleep function is enabled, after calling wifi_fpm_open. This API can not be called after calling wifi_fpm_close.
- Return
- null
- Parameters
null
:
-
void
esp_wifi_fpm_set_wakeup_cb
(fpm_wakeup_cb cb)¶ Set a callback of waken up from force sleep because of 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. fpm_wakeup_cb_func will be called after system woke up only if the force sleep time out (wifi_fpm_do_sleep and the parameter is not 0xFFFFFFF).
- Attention
- 3. fpm_wakeup_cb_func will not be called if woke up by wifi_fpm_do_wakeup from MODEM_SLEEP_T type force sleep.
- Return
- null
- Parameters
void
: (*fpm_wakeup_cb_func)(void) : callback of waken up
-
esp_err_t
esp_wifi_fpm_do_sleep
(uint32_t sleep_time_in_us)¶ 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.
- Return
- 0, setting succeed;
- Return
- -1, fail to sleep, sleep status error;
- Return
- -2, fail to sleep, force sleep function is not enabled.
- Parameters
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.
-
void
esp_wifi_fpm_set_sleep_type
(wifi_sleep_type_t type)¶ Set sleep type for force sleep function.
- Attention
- This API can only be called before wifi_fpm_open.
- Return
- null
- Parameters
wifi_sleep_type_t
: type : sleep type
-
wifi_sleep_type_t
esp_wifi_fpm_get_sleep_type
(void)¶ Get sleep type of force sleep function.
- Return
- sleep type
- Parameters
null
: