Pinger with Asynchronous shell
Posted: Wednesday 17 May 2023 16:38
I found a several Pinger in the forum:
Here is one code.
Notes:
- Built in domoticz pinger
- 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)
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.
Code: Select all
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
}