diff --git a/plip_voice/main/net.c b/plip_voice/main/net.c index 2d7414d..c7e8eba 100644 --- a/plip_voice/main/net.c +++ b/plip_voice/main/net.c @@ -83,10 +83,13 @@ static void wifi_event_handler(void *arg, esp_event_base_t base, if (base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { esp_wifi_connect(); } else if (base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { - if (!s_connected) return; /* still in initial connect loop */ - ESP_LOGW(TAG, "WiFi disconnected, reconnecting..."); + /* Retry on EVERY disconnect, including failures during the initial boot + * attempt: on a mesh the first association frequently fails (wrong node + * picked / channel roam) and must be retried, otherwise the boot connect + * just times out. Previously the initial loop gave up on first failure. */ s_connected = false; - vTaskDelay(pdMS_TO_TICKS(2000)); + ESP_LOGW(TAG, "WiFi disconnected/assoc failed, reconnecting..."); + vTaskDelay(pdMS_TO_TICKS(1500)); esp_wifi_connect(); } else if (base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t *ev = (ip_event_got_ip_t *)data; @@ -684,7 +687,16 @@ esp_err_t net_init(void) .sta = { .threshold.authmode = (strlen(pwd) == 0) ? WIFI_AUTH_OPEN : WIFI_AUTH_WPA2_PSK, - .channel = CONFIG_PLIP_WIFI_CHANNEL, + /* Mesh-friendly association. A fixed .channel breaks on mesh APs + * (Freebox/Orange "Les cils") that roam channels via band-steering + * and DFS: if the node isn't on that channel at boot, association + * silently fails. So scan ALL channels (channel=0) and connect to + * the STRONGEST node broadcasting our SSID. The PLIP talks HTTP to + * the gateway, not ESP-NOW, so there is no co-channel constraint. */ + .channel = 0, + .scan_method = WIFI_ALL_CHANNEL_SCAN, + .sort_method = WIFI_CONNECT_AP_BY_SIGNAL, + .failure_retry_cnt = 5, }, }; strncpy((char *)wcfg.sta.ssid, ssid, sizeof(wcfg.sta.ssid) - 1);