My issue is, how can I detect if the Wifi link has dropped? For example, if the router lost power or was reset?
I guess I could periodically go out and fire off a client request and if it failed, run the wifi link reset code. But that seems like a waste. And in order to detect the condition quickly, I'd need to fire off the client request way too frequently.
Below are pieces of the code to establish the connection and server, just for reference.
Thank you.
Code: Select all
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <WebServer.h>
#include <ESPmDNS.h>
.
.
.
WebServer server(1234);
WiFiClientSecure client;
.
.
.
while (NotConnected) {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Tries = 0;
while ((WiFi.status() != WL_CONNECTED) && (Tries < WifiTryLimit)) {
delay(500);
Serial.print(".");
Tries=Tries+1;
}
if (WiFi.status() == WL_CONNECTED) {
NotConnected = false;
if (MDNS.begin("esp32")) {
Serial.println("MDNS responder started.");
}
server.on("/", handleRoot);
server.on("/this", handleThis);
server.on("/that", handleThat);
server.onNotFound(handleNotFound);
server.begin();
} else {
Serial.print("WiFi resetting.");
WiFi.disconnect(); // jusst in case
delay(1000);
}
}