Checking Internet connectivity using ESP32
Posted: Fri Jul 24, 2020 12:04 pm
I have used "dns_gethostbyname()" to resolve the DNS url to check if the internet (net) is available on the wifi AP that ESP32 was connected. The solutions works. In the call-back function, I check if ipaddr == NULL then the net is not available.
I tried it using "google.com" first. It reported the net is available.
Next, I disabled the internet connection by removing the WAN connection to my AP.
The problem is that, dns_gethostbyname() kept on reporting the net was available. I think it could resolve the DNS locally.
Further, I tried the example with "amazon.com" & it started to report no Internet, correctly.
I connected the physical WAN cable to the AP & tried "amazon.com", it showed the net was available, correctly.
Again after removing the WAN cable from AP, so as to disconnect internet from wifi, I tried the example with "amazon.com" & it showed the net connected, which was wrong.
I think, once DNS is resolved online, AP saves a copy & on subsequent call to resolve DNS, it does not need internet.
So resolving DNS using dns_gethostbyname() may not yield correct answer every time.
Does anyone have a solution to this.
I tried it using "google.com" first. It reported the net is available.
Next, I disabled the internet connection by removing the WAN connection to my AP.
The problem is that, dns_gethostbyname() kept on reporting the net was available. I think it could resolve the DNS locally.
Further, I tried the example with "amazon.com" & it started to report no Internet, correctly.
I connected the physical WAN cable to the AP & tried "amazon.com", it showed the net was available, correctly.
Again after removing the WAN cable from AP, so as to disconnect internet from wifi, I tried the example with "amazon.com" & it showed the net connected, which was wrong.
I think, once DNS is resolved online, AP saves a copy & on subsequent call to resolve DNS, it does not need internet.
So resolving DNS using dns_gethostbyname() may not yield correct answer every time.
Does anyone have a solution to this.