Checking Internet connectivity using ESP32

MihirShah
Posts: 6
Joined: Sat Apr 18, 2020 7:00 am

Checking Internet connectivity using ESP32

Postby MihirShah » 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.

Agree007
Posts: 103
Joined: Mon Sep 18, 2017 7:11 pm
Location: Copenhagen

Re: Checking Internet connectivity using ESP32

Postby Agree007 » Fri Jul 24, 2020 4:44 pm

I think it is your DNS cache on your access point which need to be cleared.
If you just want to test it you network is up runnining or down, you can use http get and check og you get the correct reply or use ip ping, know there is some ping library out there.

MihirShah
Posts: 6
Joined: Sat Apr 18, 2020 7:00 am

Re: Checking Internet connectivity using ESP32

Postby MihirShah » Sat Jul 25, 2020 12:34 pm

Thanks for the reply.

DNS cache on the access point will not be in our control, once the devices are deployed to different customers !

As you suggested, http get or ping to an internet resource could be better way out.

Agree007
Posts: 103
Joined: Mon Sep 18, 2017 7:11 pm
Location: Copenhagen

Re: Checking Internet connectivity using ESP32

Postby Agree007 » Sat Jul 25, 2020 6:48 pm

When you cant use DNS, then you have the other optioner, I have used http get and IT works, have seen a ping lib, but not testede any.

MihirShah
Posts: 6
Joined: Sat Apr 18, 2020 7:00 am

Re: Checking Internet connectivity using ESP32

Postby MihirShah » Sun Jul 26, 2020 9:28 am

Yes. Good suggestion. 8-)

Who is online

Users browsing this forum: Baidu [Spider] and 81 guests