fix(wifi): send http response before channel switch and prevent reconnect race
All checks were successful
ESP32 Build & Release / build (push) Successful in 1m11s

This commit is contained in:
2026-09-12 15:41:58 +02:00
parent 15b83e7318
commit c3bc42fe94
2 changed files with 50 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ static char s_sta_ip[20] = "No Wi-Fi";
static char s_active_ssid[WIFI_SSID_MAX_LEN + 1] = {0};
static SemaphoreHandle_t s_wifi_mux = NULL;
static SemaphoreHandle_t s_net_lock = NULL;
static bool s_manual_disconnect = false;
/* ------------------------------------------------------------------ */
@@ -184,7 +185,7 @@ static void wifi_event_handler(void *arg, esp_event_base_t base, int32_t id, voi
if (s_wifi_group) {
xEventGroupClearBits(s_wifi_group, WIFI_CONNECTED_BIT);
}
if (s_active_ssid[0] != '\0' && s_retry_count < WIFI_RETRY_MAX) {
if (!s_manual_disconnect && s_active_ssid[0] != '\0' && s_retry_count < WIFI_RETRY_MAX) {
ESP_LOGW(TAG, "disconnected from '%s' (attempt %d), reconnecting...", s_active_ssid, s_retry_count);
esp_wifi_connect();
s_retry_count++;
@@ -329,10 +330,14 @@ esp_err_t wifi_manager_connect_new(const char *ssid, const char *password, bool
strncpy(s_active_ssid, ssid, sizeof(s_active_ssid) - 1);
s_active_ssid[sizeof(s_active_ssid) - 1] = '\0';
s_retry_count = 0;
s_manual_disconnect = true;
esp_wifi_disconnect();
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg));
s_manual_disconnect = false;
esp_err_t set_err = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg);
if (set_err != ESP_OK) {
ESP_LOGE(TAG, "esp_wifi_set_config failed: %s", esp_err_to_name(set_err));
return set_err;
}
esp_err_t ret = esp_wifi_connect();
if (save_to_nvs) {
@@ -481,9 +486,9 @@ esp_err_t wifi_manager_start(void)
strncpy(s_active_ssid, target_ssid, sizeof(s_active_ssid) - 1);
s_active_ssid[sizeof(s_active_ssid) - 1] = '\0';
s_retry_count = 0;
s_manual_disconnect = true;
esp_wifi_disconnect();
s_manual_disconnect = false;
esp_err_t err = esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_wifi_set_config failed: %s", esp_err_to_name(err));