fix(plip): robust WiFi on mesh/DFS network

STA config: channel=0 (all-channel scan), WIFI_ALL_CHANNEL_SCAN,
WIFI_CONNECT_AP_BY_SIGNAL, failure_retry_cnt=5.
Disconnect handler: retry on every disconnect event, including during
initial association — previously the first failure at boot caused an
immediate abort and a ~30s timeout before IP was acquired.
Validated on hardware: connects reliably on ch1, RSSI -32, IP in ~2.5s.
This commit is contained in:
clement
2026-06-15 22:27:01 +02:00
parent aa7ae277ed
commit 3c0eb75465
+16 -4
View File
@@ -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);