Merge pull request #146 from bbouabou/fix/wifi-reconnect

Fix WiFi never reconnecting after boot without network, and watchdog crash
pull/102/head
Miroslav Pivovarsky 2026-10-28 08:59:06 +01:00 committed by GitHub
commit 71ec50c840
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View File

@ -129,7 +129,7 @@ void setup() {
ESP_ERROR_CHECK(esp_task_wdt_add(Task_SystemTelemetry));
xTaskCreatePinnedToCore(System_TaskSysLed, "SystemLed", 2000, NULL, 7, &Task_SysLed, 0); /*function, description, stack size, parameters, priority, task handle, core*/
ESP_ERROR_CHECK(esp_task_wdt_add(Task_SysLed));
xTaskCreatePinnedToCore(System_TaskWiFiWatchdog, "WiFiWatchdog", 2200, NULL, 8, &Task_WiFiWatchdog, 0); /*function, description, stack size, parameters, priority, task handle, core*/
xTaskCreatePinnedToCore(System_TaskWiFiWatchdog, "WiFiWatchdog", 4096, NULL, 8, &Task_WiFiWatchdog, 0); /*function, description, stack size, parameters, priority, task handle, core*/
ESP_ERROR_CHECK(esp_task_wdt_add(Task_WiFiWatchdog));
//xTaskCreatePinnedToCore(System_TaskSdCardRemove, "SdCardRemove", 3000, NULL, 9, &Task_SdCardFileRemove, 0); /*function, description, stack size, parameters, priority, task handle, core*/
//esp_task_wdt_add(Task_SdCardFileRemove);

View File

@ -115,7 +115,9 @@ void WiFiMngt::Init() {
log->AddEvent(LogLevel_Info, "WiFi network IP Address: http://" + WiFi.localIP().toString());
#endif
} else {
log->AddEvent(LogLevel_Warning, "Wifi unavailable. Skip connecting to WiFi: " + WifiSsid);
/* SSID not found, connect anyway and retry in WiFiReconnect() */
log->AddEvent(LogLevel_Warning, "Wifi unavailable at boot: " + WifiSsid + ". Will keep retrying in background");
WiFiStaConnect();
}
} else {
ScanWiFiNetwork();
@ -185,6 +187,10 @@ void WiFiMngt::WiFiReconnect() {
log->AddEvent(LogLevel_Warning, F("Disconnect from WiFi"));
WiFi.reconnect();
log->AddEvent(LogLevel_Warning, F("Reconnecting to WiFi. STA"));
} else if ((WiFi.status() != WL_CONNECTED) && (FirstConnected == false) && (true == config->CheckActifeWifiCfgFlag())) {
/* not connected since boot, retry connection to STA */
log->AddEvent(LogLevel_Warning, "Not connected to WiFi since boot. Retrying connection to: " + WifiSsid);
WiFiStaConnect();
} else if (WiFi.status() == WL_CONNECTED) {
char cstr[150];
sprintf(cstr, "Wifi connected. SSID: %s, BSSID: %s, RSSI: %d dBm, IP: %s, TX power: %s", WiFi.SSID().c_str(), WiFi.BSSIDstr().c_str(), WiFi.RSSI(), WiFi.localIP().toString().c_str(), TranslateTxPower(WiFi.getTxPower()).c_str()); //print 3 digits
@ -425,12 +431,7 @@ void WiFiMngt::WiFiWatchdog() {
log->AddEvent(LogLevel_Verbose, "Time: " + String(currentMillis - TaskWdg_previousMillis) + "/" + String(WIFI_STA_WDG_TIMEOUT));
if (false == StartStaWdg) {
if (ScanWifiNetwork(WifiSsid) >= 1) {
log->AddEvent(LogLevel_Warning, F("WiFi STA connection lost. Start watchdog timer!"));
} else {
log->AddEvent(LogLevel_Warning, F("WiFi STA connection lost. No available network!"));
}
log->AddEvent(LogLevel_Warning, F("WiFi STA connection lost. Start watchdog timer!"));
StartStaWdg = true;
TaskWdg_previousMillis = currentMillis;
}