feat(esp_wifi): add ESPNOW power-save example

This commit is contained in:
liuning 2023-05-16 17:56:34 +08:00
parent c920123629
commit 332a4d3bef
2 changed files with 28 additions and 2 deletions

View File

@ -58,4 +58,29 @@ menu "Example Configuration"
help help
When enable long range, the PHY rate of ESP32 will be 512Kbps or 256Kbps When enable long range, the PHY rate of ESP32 will be 512Kbps or 256Kbps
config ESPNOW_ENABLE_POWER_SAVE
bool "Enable ESPNOW Power Save"
default "n"
select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE
depends on ESPNOW_WIFI_MODE_STATION
help
With ESPNOW power save enabled, chip would be able to wakeup and sleep periodically
Notice ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is essential at Wi-Fi disconnected
config ESPNOW_WAKE_WINDOW
int "ESPNOW wake window, unit in millisecond"
range 0 65535
default 50
depends on ESPNOW_ENABLE_POWER_SAVE
help
ESPNOW wake window
config ESPNOW_WAKE_INTERVAL
int "ESPNOW wake interval, unit in millisecond"
range 1 65535
default 100
depends on ESPNOW_ENABLE_POWER_SAVE
help
ESPNOW wake interval
endmenu endmenu

View File

@ -299,8 +299,9 @@ static esp_err_t example_espnow_init(void)
ESP_ERROR_CHECK( esp_now_init() ); ESP_ERROR_CHECK( esp_now_init() );
ESP_ERROR_CHECK( esp_now_register_send_cb(example_espnow_send_cb) ); ESP_ERROR_CHECK( esp_now_register_send_cb(example_espnow_send_cb) );
ESP_ERROR_CHECK( esp_now_register_recv_cb(example_espnow_recv_cb) ); ESP_ERROR_CHECK( esp_now_register_recv_cb(example_espnow_recv_cb) );
#if CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE #if CONFIG_ESPNOW_ENABLE_POWER_SAVE
ESP_ERROR_CHECK( esp_now_set_wake_window(65535) ); ESP_ERROR_CHECK( esp_now_set_wake_window(CONFIG_ESPNOW_WAKE_WINDOW) );
ESP_ERROR_CHECK( esp_wifi_connectionless_module_set_wake_interval(CONFIG_ESPNOW_WAKE_INTERVAL) );
#endif #endif
/* Set primary master key. */ /* Set primary master key. */
ESP_ERROR_CHECK( esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK) ); ESP_ERROR_CHECK( esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK) );