Page 1 of 1

Pinger with Asynchronous shell

Posted: Wednesday 17 May 2023 16:38
by benp
I found a several Pinger in the forum:
  • 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)
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.

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
}

Re: Pinger with Asynchronous shell

Posted: Wednesday 17 May 2023 16:42
by Kedi
I use the internal System Alive Checker (15 devices) and that works fine for several years now, and is 'flexible' enough.

Re: Pinger with Asynchronous shell

Posted: Friday 26 May 2023 11:04
by benp
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).

Re: Pinger with Asynchronous shell

Posted: Friday 26 May 2023 13:21
by Kedi
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.