Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to check internet connection with ESP32 Arduino

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?

like image 728
gemboly Avatar asked Sep 17 '25 13:09

gemboly


1 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)

like image 90
Codebreaker007 Avatar answered Sep 20 '25 08:09

Codebreaker007