feat(protocol_examples_common): support infinite retries for example_handler_on_wifi_disconnect

This commit is contained in:
Tan Yan Quan
2026-03-16 19:49:30 +08:00
parent 9e7abc9f01
commit 969969ec36
2 changed files with 3 additions and 2 deletions
@@ -46,6 +46,7 @@ menu "Example Connection Configuration"
help help
Set the Maximum retry to avoid station reconnecting to the AP unlimited, Set the Maximum retry to avoid station reconnecting to the AP unlimited,
in case the AP is really inexistent. in case the AP is really inexistent.
Set to -1 for infinite retries.
choice EXAMPLE_WIFI_SCAN_METHOD choice EXAMPLE_WIFI_SCAN_METHOD
prompt "WiFi Scan Method" prompt "WiFi Scan Method"
@@ -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) int32_t event_id, void *event_data)
{ {
s_retry_num++; 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); ESP_LOGI(TAG, "WiFi Connect failed %d times, stop reconnect.", s_retry_num);
/* let example_wifi_sta_do_connect() return */ /* let example_wifi_sta_do_connect() return */
if (s_semph_get_ip_addrs) { if (s_semph_get_ip_addrs) {
@@ -176,7 +176,7 @@ esp_err_t example_wifi_sta_do_connect(wifi_config_t wifi_config, bool wait)
#if CONFIG_EXAMPLE_CONNECT_IPV6 #if CONFIG_EXAMPLE_CONNECT_IPV6
xSemaphoreTake(s_semph_get_ip6_addrs, portMAX_DELAY); xSemaphoreTake(s_semph_get_ip6_addrs, portMAX_DELAY);
#endif #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; return ESP_FAIL;
} }
} }