Fastest way to check internet connection with ESP32 Arduino

Viewed 5559

Update: I know, the WIFI AP is still on & active in this case and the chip should not know about the change, but the question is still open. How should I check the connectivity?

In my project, the internet connection is really important.

After some testing, I have experienced that if I plug out the ethernet cable from my router the ESP32 still thinks, that it is still connected to WIFI, even the

WiFi.status() == WL_CONNECTED

is always true in this case.

So, I have tried out pinging google.com to examine the connection. This works but takes ages to get back the result.

How should I check the connectivity with the lowest resource cost and time?

2 Answers

Even WiFi.status() is unreliable due to the not documented details by Espressif. The API is error prone as the issues on github show.
So actually the question is . what do you really want to check? - in my definition internet connection means my line (or aerial) connectionto my ISP is unbroken. This includes

  • my AP
  • my router
  • the ISPs fiber converter in my basement,
  • the line itself and the
  • ISPs gateway

This is what I use to determine wether a connection is open. I ping the IP address of the ISP gateway server. So you save time (no DNS resolution, no hops over nodes on the internet.
If you mean wether a certain service on a defined server is available, thats slow but then you are 100% sure.
Just a clarification: "ESP32 still thinks, that it is still connected to WIFI" - YES that has to be true because according to the API this ensures client to AP connection and not AP connection to some where else. Normally a good configured router informs its clients about connection loss (in this case the connected AP(s)) and these notify (depending on their config) their clients (or sometimes not or very late)

Technically that result is correct because you are still connected to wifi! Just because you unplug the ethernet cable doesn't mean your wifi stops. All it means is that your wifi can't get to the internet. You can try pinging your isp's dns server. It's a lot closer to you than Google is. Just the ramblings of an old man...

Related