Skip to content

Commit

Permalink
Implement WiFi reconnect
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Abász committed Sep 1, 2023
1 parent 0ace170 commit ca9a4ea
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/peripherals/network.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit ca9a4ea

Please sign in to comment.