WiFi.ping does not detect responding machine

I’m trying to detect whether a machine in the network is up, by sending a PING request through WiFi.ping(). Unfortunately it always returns zero, even though another laptop which is also connected to the same access point is able to ping the machine correctly. Oddly, if I ping the gateway, that works. Any ideas what could be happening?

Hi @pombeirp

Can you ping a well known host on the Internet?

Are you sure you have the correct IP address for the host you are pinging?

Are you sure your router will route ping requests? Some don’t since ping has been used in DOS attacks.

If you share your code here with a minimal failing case we might be able to help you debug.

Hi @bko, thanks for you quick reply.

I am able to ping google.com for instance, as well as my gateway. The router does route ping requests, because I am able to ping the exact same machine using the same WiFi connection using either a laptop or an Android phone.

If you care to take a look, my project is up on hackster.io, but I believe the problem will be hard to reproduce. It seems like some kind of incompatibility between my machine and the Spark Core. It just puzzled me because this is the first time I have a problem pinging this machine.

##UPDATE
SOLVED - once I pinged the Spark Core from 192.168.0.29, then the Core was able to start pinging that machine successfully (as per the last post here). I just don’t understand the difference of behavior between the Core and any other device I’ve tried (Android phones, laptops, etc).

The Android app communication appears in Wireshark, but the Spark Core doesn’t:

Glad it is working for you albeit strangely! ICMP echo (ping) depends on ARP to get the MAC address of the target computer.

Is it possible that your router did not have an IP/MAC address pair for the “.29” machine? Could the DHCP-assigned address have expired?

Can you see ARP requests for the MAC address of the “.29” machine in wireshark coming from the core?

The Spark core TI CC3000 does have an ARP cache to hold MAC/IP address pairs but it is not very large compared to a regular computer. If your router cannot tell the core the MAC address for IP address 192.168.0.29, then no hosts should be able to find it, but that does not appear to be the case here.

Unfortunately it doesn’t survive resets. I do see ARP requests from the Core (192.168.0.19) in Wireshark, as seen below, so I don’t see what can be missing for it to be able to ping correctly.

Hi @pombeirp

That ARP exchange looks right so maybe that is not it.

You can pass a second argument to ping that says how many attempts it should do (the default is 5). Maybe you could try 100?

Hi @bko,

That didn’t help. It still returns zero.

What version firmware are you using? I found that 1.28 always needs to be pinged back before it can see any lan devices, but 1.29 seems to have this problem fixed, for me anyways.

Hi @mtnbrit, I am using 1.29 ("cc3000_patch_version": "1.29").

Hi @bko. In another attempt to eliminate causes, I wanted to know if there could be something on my 192.168.0.29 machine that would prevent the ping from working. So I tried pinging my Android phone and got exactly the same behavior: I could only get ping to work on the Spark once the Android phone pinged the Spark once.

HI @pombeirp

If your core can ping google but not a local host (unless that host pinging your core first), I think the problem is most likely in your router. There is no difference in the core between pinging google and pinging a local host.

the big difference is google is reachable through the gateway which is probably always reachable due to the cloud connection keeping the arp entry fresh.

With WiFi, if you can’t talk to the access point/gateway, you can’t talk to anyone.