4

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?

gemboly
  • 63
  • 1
  • 6
  • Have you solved the problem in the meanwhile? I am looking for a solution too. I implemented a ping to google.com, which is working well but takes a lot of time. Also, google.com is not available everywhere. So my devices didn't work in China for example. – user14665305 Mar 15 '23 at 00:21
  • Hi @user14665305, For me pinging the DNS nameserver of Google (8.8.8.8) solved the problem. I only ping it 2 times. This is the package that I am using: https://github.com/marian-craciunescu/ESP32Ping `const IPAddress remote_ip(8, 8, 8, 8); ... Ping.ping(remote_ip, 2);` Maybe you should search for a better host to ping in your area if Google is not that stable. – gemboly Mar 16 '23 at 07:46

2 Answers2

2

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)

Codebreaker007
  • 2,911
  • 1
  • 10
  • 22
2

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...