feat(protocol_examples_common): support infinite retries for example_handler_on_wifi_disconnect

This commit is contained in:
Tan Yan Quan
2026-03-13 16:15:44 +08:00
parent 35f6c201ad
commit 2a2811d5e6
2 changed files with 3 additions and 2 deletions
@@ -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"
@@ -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;
}
}