[2.2.7] ICMP Ping for Apps and Drivers

hubitat.helper.NetworkUtils.ping(String IPAddress)
hubitat.helper.NetworkUtils.ping(String IPAddress, Integer count)

returns

hubitat.helper.NetworkUtils.PingData:
Double rttAvg
Double rttMin
Double rttMax
Integer packetsTransmitted
Integer packetsReceived
Integer packetLoss

Count has a maximum of 5 and defaults to 3.

Example usage:

hubitat.helper.NetworkUtils.PingData pingData = hubitat.helper.NetworkUtils.ping("192.168.1.1", 5)

Example return:

PingData(rttAvg: 1.035, rttMin: 0.732, rttMax: 1.245, packetsTransmitted: 3, packetsReceived: 3, packetLoss: 0)
16 Likes

@bcopeland. Hi I am not getting good data returned, just all 0's. I am running 2.2.7.126.

Returned Example:
PingData(rttAvg: 0.0, rttMin: 0.0, rttMax: 0.0, packetsTransmitted: 0, packetsReceived: 0, packetLoss: 0)

Code --------

def CheckDevice() {

hubitat.helper.NetworkUtils.PingData pingData = hubitat.helper.NetworkUtils.ping("192.168.1.1", 5)

log.info pingData

}

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.

1 Like

@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.

Thanks

Wondering the same thing. @bcopeland, any thoughts?

I'm going to be testing this .. There is a different version of ping running on C7 as it has to support IPv6, but it should have worked..

2 Likes

Any update on this? Still doesn't work on a C-5 - 2.2.8.156

@bcopeland

Shoot.. Thanks for reminding me.. I’ll get that fixed for 2.2.9

1 Like

Bob, what are the units for these values. (micro seconds?)

milliseconds

4 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.