dancol90 / ESP8266Ping

Ping library for ESP8266 Arduino core
GNU Lesser General Public License v2.1
265 stars 136 forks source link

Can't use domain name, must use IP address #23

Open SteveRMann opened 5 years ago

SteveRMann commented 5 years ago

I wrote a sketch for a Wemos D1 Mini that pings three of my local IP devices (router, MQTT broker and Home Assistant Pi) plus one external location, like google.com, amazon.com, for example. It repeats every five seconds. If a ping passes, a green LED is lit, else a red LED. I randomize my external IP addresses so not to look like a DOS attack. It could be 30-seconds between pings of the same host.

The basic idea is that I want to be able to tell at a glance if my local devices, router and the WWW are functioning.

It works just fine.. If I ping

Ping.ping(172.217.11.14)

... every five seconds, it runs forever with no issue. However, if I ping

Ping.ping(google.com)

...after about 10-15 minutes I will crash out with "ESP Exception (9) and wdt reset ". The Wemos will restart and start running again for about 10-15 minutes. Repeat.

When I replace google.com with their IP address, 172.217.11.14, it runs forever without problems.

If I read correctly, Exception (9) means that the code has attempted to write to address space that the program doesn't have permission to use. (I can force the same crash by creating a char array for five characters and writing six characters to it.)

I am stumped.

gusdleon commented 4 years ago

Sorry the Library ESP8266Ping only works with IP's, but....

You can use WiFi.hostByName(DOMAIN,IP);

to resolve any domain to their IP Where DOMAIN it's the Host or Domain you want to ping and IP it's the IP of that domain

more info Here

I hope this stills relevant to you.

EDIT: my bad, you can use domains to but they need to be a string so you can instead of Ping.ping(google.com); use Ping.ping("google.com");