Lua pinger : commandArray = {} + os.execute('ping -c1 -w1 ' .. ip) (my old one until yesterder with possible 10s error)
Dzvents pinger with s.execute('ping -c1 -w1 ' .. ip)
But not the dzvents with Asynchronous shell
Here is one code.
Notes:
'device1' 'device2' 'rainbow' ... must exist as Switches or an error will occur!
The code is ready to use for raspberry and IPV4.
For others configs, you must adapt domoticz.utils.stringSplit from what you see in the ping command line!
Maybe somebody will find a more flexible solution.
return
{
on =
{
timer ={'every 1 minutes'},
shellCommandResponses ={'shell'}
},
execute = function(domoticz, item)
local ping={}
ping['192.168.0.2']='device1'
ping['192.168.0.3']='device2'
--ping['192.168.0.6']='rainbow'
--ping['192.168.0.7']='old phone'
ping['192.168.0.8']='new phone'
ping['192.168.0.9']='esp8266-co2'
ping['192.168.0.10']='wiz1'
--ping['192.168.0.11']='ESP32-firebeetle'
--ping['192.168.0.12']='nodeMCU'
if item.isTimer then
for ip, switch in pairs(ping) do
domoticz.executeShellCommand(
{
command = 'ping -c1 -w1 ' .. ip,
callback = 'shell',
timeout = 2,
})
end
else
local dataTable=domoticz.utils.stringSplit(item.data)
if (item.ok) then
domoticz.devices(ping[dataTable[2]]).switchOn()
else
domoticz.devices(ping[dataTable[2]]).switchOff()
end
end
end
}
Kedi wrote: ↑Wednesday 17 May 2023 16:42
I use the internal System Alive Checker (15 devices) and that works fine for several years now, and is 'flexible' enough.
Yes, System Alive Checker(Built in domoticz pinger) is easy to use but some can prefer code because:
It is easier to copy (my case, from one domoticz to another)
They want to do something else with it
This code is an update of the lua version with several existing fork. For example this one: https://www.easydomoticz.com/forum/viewtopic.php?t=2904
I used the lua version since 2016 but it had sometime time out (more than 10s) because lost ping are too long when too much devices, that's why I write this Asynchronous pinger(no timeout because asynchronous).
I use the internal System Alive Checker and use dzVents triggers on the devices if the are alive or not.
Less complicated and just 1 time job since 2015 and less overhead.
But your solution works.
Logic will get you from A to B. Imagination will take you everywhere.