It worked initially, but since about 2.2.7.121 if the destination does not respond it returns all zeros - just coded around it in my driver ([Release] Hubitat Ping)
@bcopeland. I tried @thebearmay code as well and none of my ip's are responding with this command, always getting 0's. I know these ips should be responding as I have verified with several other machines on the same network. I did notice that if the ip is not on the network causing the ip to not respond it takes alot longer for the 0's to come back. To me that means the pings are actually responding because the responses cause it to move on to the next ping quicker causing the result to come back quicker at which point the data is not being returned.
@thebearmay thanks for the driver, that was what I was working on but yours is way better and done too.
@bcopeland It appears you have a timeout of 10 seconds on the ICMP ping. I thought I would use the ping to test if a device is powered on or off, but with a 10 second timeout, my driver is busy for 10 seconds and really slowing down the system. Any chance of a configurable timeout? In my case, I would like to drop this way down to milliseconds, since I am using this on a LAN only.
[update] So, it's not 10 seconds... it appears to be based on system load. it's actually about 3 seconds. Still, it would be nice if we can declare the timeout. Even 3 seconds can be a problem. I am playing with the intervals to see what a good ping interval would be, that won't put a heavy load on the hub.
In my experiments, what I learned is that if the host is still in the ARP cache, then you will receive non-zero value for packetsTransmitted and packetLoss if the host of offline. Once the host is purged from the ARP cache, then the system returns a HostUnreachable, and ping returns all zeros.
Because of this, I am checking if packets failed = 100% or packetsTransmitted = 0, then assume the host is down. Based on my test results, I think this logic makes sense.
This works great on my C7, but the same code isn't working on my C5. Any update if this is C7 only or is it a bug that it doesn't work on the C5? Both are running 2.2.7.128.