How can I tell if my Wifi link is still alive?

IraSch
Posts: 3
Joined: Wed Dec 02, 2020 10:35 pm

How can I tell if my Wifi link is still alive?

Postby IraSch » Sun May 02, 2021 2:59 pm

I have a project that works well. It functions in both the server capacity (accepts web requests from the user) and as a client (goes out to retrieve info as needed based on a user request).

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); 
    }
  }  


Who is online

Users browsing this forum: No registered users and 87 guests