From ca9a4eaa75148ce8ff7636ff0ac9a1edc7de97f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=A1sz?= <> Date: Fri, 1 Sep 2023 22:30:21 +0200 Subject: [PATCH] Implement WiFi reconnect Implement Wifi reconnection feature so in case of connection loss the web server can recover. This fixes an issue where some routers sometimes drop the connection straight after IP assignment eventually leaving the web server without connection while showing everything ok in the logs --- src/peripherals/network.service.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/peripherals/network.service.cpp b/src/peripherals/network.service.cpp index 195adf0..3757e2e 100644 --- a/src/peripherals/network.service.cpp +++ b/src/peripherals/network.service.cpp @@ -69,6 +69,12 @@ void NetworkService::setup() auto const deviceName = Configurations::deviceName + "-(" + string(eepromService.getBleServiceFlag() == BleServiceFlag::CscService ? "CSC)" : "CPS)"); WiFi.setHostname(deviceName.c_str()); WiFi.mode(WIFI_STA); + WiFi.onEvent([&](WiFiEvent_t event, WiFiEventInfo_t info) + { + Log.traceln("Wifi disconnected, trying to reconnect"); + WiFi.reconnect(); + isWifiConnected = true; }, + WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED); WiFi.begin(Configurations::ssid.c_str(), Configurations::passphrase.c_str()); Log.infoln("Connecting to wifi: %s", Configurations::ssid.c_str());