From 2a2811d5e697872cccfa1382d468ab47a3ee06ca Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Fri, 13 Mar 2026 16:15:44 +0800 Subject: [PATCH] feat(protocol_examples_common): support infinite retries for example_handler_on_wifi_disconnect --- .../protocol_examples_common/Kconfig.projbuild | 1 + .../common_components/protocol_examples_common/wifi_connect.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/common_components/protocol_examples_common/Kconfig.projbuild b/examples/common_components/protocol_examples_common/Kconfig.projbuild index 65efe53fbd..e5dffde890 100644 --- a/examples/common_components/protocol_examples_common/Kconfig.projbuild +++ b/examples/common_components/protocol_examples_common/Kconfig.projbuild @@ -46,6 +46,7 @@ menu "Example Connection Configuration" help Set the Maximum retry to avoid station reconnecting to the AP unlimited, in case the AP is really inexistent. + Set to -1 for infinite retries. choice EXAMPLE_WIFI_SCAN_METHOD prompt "WiFi Scan Method" diff --git a/examples/common_components/protocol_examples_common/wifi_connect.c b/examples/common_components/protocol_examples_common/wifi_connect.c index a2b88200ee..1bbed95fe5 100644 --- a/examples/common_components/protocol_examples_common/wifi_connect.c +++ b/examples/common_components/protocol_examples_common/wifi_connect.c @@ -32,7 +32,7 @@ static void example_handler_on_wifi_disconnect(void *arg, esp_event_base_t event int32_t event_id, void *event_data) { s_retry_num++; - if (s_retry_num > CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY) { + if (CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY >= 0 && s_retry_num > CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY) { ESP_LOGI(TAG, "WiFi Connect failed %d times, stop reconnect.", s_retry_num); /* let example_wifi_sta_do_connect() return */ if (s_semph_get_ip_addrs) { @@ -180,7 +180,7 @@ esp_err_t example_wifi_sta_do_connect(wifi_config_t wifi_config, bool wait) vSemaphoreDelete(s_semph_get_ip6_addrs); s_semph_get_ip6_addrs = NULL; #endif - if (s_retry_num > CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY) { + if (CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY >= 0 && s_retry_num > CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY) { return ESP_FAIL; } }