From 332a4d3bef50bd00c288b6f8ae9de14b5d0ec294 Mon Sep 17 00:00:00 2001 From: liuning Date: Tue, 16 May 2023 17:56:34 +0800 Subject: [PATCH 1/2] feat(esp_wifi): add ESPNOW power-save example --- examples/wifi/espnow/main/Kconfig.projbuild | 25 +++++++++++++++++++ .../wifi/espnow/main/espnow_example_main.c | 5 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/wifi/espnow/main/Kconfig.projbuild b/examples/wifi/espnow/main/Kconfig.projbuild index 4c76d8b14e..459e567ccd 100644 --- a/examples/wifi/espnow/main/Kconfig.projbuild +++ b/examples/wifi/espnow/main/Kconfig.projbuild @@ -58,4 +58,29 @@ menu "Example Configuration" help 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 diff --git a/examples/wifi/espnow/main/espnow_example_main.c b/examples/wifi/espnow/main/espnow_example_main.c index 38bbecacf8..7ecc90dd04 100644 --- a/examples/wifi/espnow/main/espnow_example_main.c +++ b/examples/wifi/espnow/main/espnow_example_main.c @@ -299,8 +299,9 @@ static esp_err_t example_espnow_init(void) ESP_ERROR_CHECK( esp_now_init() ); ESP_ERROR_CHECK( esp_now_register_send_cb(example_espnow_send_cb) ); ESP_ERROR_CHECK( esp_now_register_recv_cb(example_espnow_recv_cb) ); -#if CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE - ESP_ERROR_CHECK( esp_now_set_wake_window(65535) ); +#if CONFIG_ESPNOW_ENABLE_POWER_SAVE + 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 /* Set primary master key. */ ESP_ERROR_CHECK( esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK) ); From 57335c90510b662708e51082f86463f2094917b4 Mon Sep 17 00:00:00 2001 From: liuning Date: Tue, 16 May 2023 17:35:20 +0800 Subject: [PATCH 2/2] fix(esp_wifi): fix ret when setting channel at wifi not started --- components/esp_wifi/include/esp_wifi.h | 3 ++- components/esp_wifi/lib | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index aa65e32c6b..b31ca083f5 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -578,7 +578,7 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw); /** * @brief Set primary/secondary channel of ESP32 * - * @attention 1. This API should be called after esp_wifi_start() + * @attention 1. This API should be called after esp_wifi_start() and before esp_wifi_stop() * @attention 2. When ESP32 is in STA mode, this API should not be called when STA is scanning or connecting to an external AP * @attention 3. When ESP32 is in softAP mode, this API should not be called when softAP has connected to external STAs * @attention 4. When ESP32 is in STA+softAP mode, this API should not be called when in the scenarios described above @@ -593,6 +593,7 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw); * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_IF: invalid interface * - ESP_ERR_INVALID_ARG: invalid argument + * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start */ esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second); diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 814f1482ac..d83e414db9 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 814f1482ac59038a0641672115564169174e5dae +Subproject commit d83e414db987a3464c6f5f27aade2edfa0abb2c8