detect Wifi disconnection and reconnect
This commit is contained in:
parent
9bb11299d2
commit
f93f4bd5f2
10
src/wifi.h
10
src/wifi.h
@ -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();
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user