From cfac5b0a05a96d7c9fcd2ca092e0da6653dcf0c6 Mon Sep 17 00:00:00 2001 From: Ulrich Meine Date: Thu, 23 Apr 2026 23:06:05 +0200 Subject: [PATCH] Fix Wifi AP shutdown during client WiFi reconnect attempt --- lib/gwwifi/GwWifi.cpp | 44 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/gwwifi/GwWifi.cpp b/lib/gwwifi/GwWifi.cpp index f4a81ce..34415b0 100644 --- a/lib/gwwifi/GwWifi.cpp +++ b/lib/gwwifi/GwWifi.cpp @@ -143,30 +143,34 @@ void GwWifi::loop(){ delay(300); - if (acquireMutex()){ - esp_err_t stopErr=esp_wifi_stop(); - releaseMutex(); - if (stopErr != ESP_OK){ - LOG_DEBUG(GwLog::ERROR,"GwWifi: esp_wifi_stop failed: %d",(int)stopErr); + if (!apActive) { + if (acquireMutex()){ + esp_err_t stopErr=esp_wifi_stop(); + releaseMutex(); + if (stopErr != ESP_OK){ + LOG_DEBUG(GwLog::ERROR,"GwWifi: esp_wifi_stop failed: %d",(int)stopErr); + } } - } - else{ - LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (stop)"); - } - - delay(100); - - if (acquireMutex()){ - esp_err_t startErr=esp_wifi_start(); - releaseMutex(); - if (startErr != ESP_OK){ - LOG_DEBUG(GwLog::ERROR,"GwWifi: esp_wifi_start failed: %d",(int)startErr); + else{ + LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (stop)"); } + + delay(100); + + if (acquireMutex()){ + esp_err_t startErr=esp_wifi_start(); + releaseMutex(); + if (startErr != ESP_OK){ + LOG_DEBUG(GwLog::ERROR,"GwWifi: esp_wifi_start failed: %d",(int)startErr); + } + connectInternal(); + } + else{ + LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (start)"); + } + } else { connectInternal(); } - else{ - LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (start)"); - } } } else{