Page 1 of 1

ping with lua and switch

Posted: Friday 01 July 2016 20:57
by tiga
hello, i am running a little ping test.
i have a virtual switch made to see the status of my tablet (testping).
this is the script i use

Code: Select all

commandArray = {}

ping_success=os.execute('ping -c1 192.168.0.113') --tablet
if ping_success then
print("tablet online")
commandArray['testping']='On'
else
print("tablet offline")
commandArray['testping']='Off' 
end

return commandArray
i do this in lua becouse the standard "system alive checker" does give valse info.

the script works fine but....i want my virtual switch to change only if the ping result changes
in other words the "last seen" time not updated every 30 or what seconds....


can anyone help me?

hmmm not working fine afterall.when i am offline i get:
Error: EventSystem: Warning!, lua script test ping has been running for more than 10 seconds

HELP :?

Re: ping with lua and switch

Posted: Friday 01 July 2016 21:39
by jvdz
Have a look here before trying reinventing this : http://domoticz.com/wiki/Presence_detection :)

Jos

Re: ping with lua and switch

Posted: Saturday 02 July 2016 11:08
by Derik

Re: ping with lua and switch

Posted: Sunday 03 July 2016 19:08
by maomanna
I don't understand the two answers.

The topicstarter ask for a ping script in lua, not in bash or python.

By using lua, you can adjust the sript easily in the webgui.
Otherwise you always have to do it by ssh

Re: ping with lua and switch

Posted: Sunday 03 July 2016 19:29
by jvdz
maomanna wrote:I don't understand the two answers.

The topicstarter ask for a ping script in lua, not in bash or python.

By using lua, you can adjust the sript easily in the webgui.
Otherwise you always have to do it by ssh
True, but I would never put this function in the Event queue as it is single threaded and could make the eventsystem respond slow to other events during the processing of this function.
One could obvious still do the check in LUA but I would then schedule it as a crontab job.

Jos

Re: ping with lua and switch

Posted: Monday 04 July 2016 8:39
by dannybloe
I'd use dzVents for this. You can use the system-alive checker plugin and use a persistent variable in your script that increases everytime a time-out occurs (the checker triggers a switch which will trigger you script). You can then threshold it and only send a notification if you have a number of consecutive time-outs in a row. Works like a charm.

Something like this:

Code: Select all

return {
	active = true, 
	on = {
		'checkerSwitch', -- name of the switch that is triggered by the system-alive checker plugin
	},
	data = {
		timeOuts = { initial = 0 }
	},
	execute = function(domoticz, checkerSwitch)

		if (checkerSwitch.state == 'On') then
			domoticz.data.timeOuts = domoticz.data.timeOuts + 1
		else
			domoticz.data.timeOuts = 0 -- reset
		end

		if (domoticz.data.timeOuts > 5) then
			domoticz.notify('Oh my, the device is not responding anymore', domoticz.PRIORITY_HIGH)
		end

	end
}

Re: ping with lua and switch

Posted: Monday 04 July 2016 21:14
by dannybloe
I updated dzVents to 1.1.1 and it now contains a generic script example how to notify when a system-alive checker device is not responding anymore while preventing false negatives.

Re: ping with lua and switch

Posted: Friday 08 July 2016 20:58
by tiga
ok thanks i will try these out

Re: ping with lua and switch

Posted: Tuesday 12 July 2016 13:55
by sploutchi
Hi tiga,

I wrote an article on this subject : http://debrouilhome.fr/2015/07/domoticz ... n-lua.html

Enjoy :)