detect Wifi disconnection and reconnect

This commit is contained in:
Nicu Hodos 2022-03-06 15:43:18 +01:00
parent 9bb11299d2
commit f93f4bd5f2

View File

@ -6,7 +6,11 @@
namespace Wifi {
WiFiEventHandler stationConnectedHandler;
WiFiEventHandler stationDisconnectedHandler;
void reconnect();
Task tWifiReconnect(1 * TASK_MINUTE, TASK_FOREVER, reconnect, &ts);
String currentSSID;
String currentPsk;
@ -14,6 +18,12 @@ namespace Wifi {
stationConnectedHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP& e) {
Serial.println("Reconnected to network.");
tWifiConnected.restart();
tWifiReconnect.cancel();
});
stationDisconnectedHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected& e) {
Serial.println("Disconnected from network.");
tWifiReconnect.restartDelayed();
});