ping with lua and switch

Moderator: leecollings

Post Reply
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

ping with lua and switch

Post 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 :?
User avatar
jvdz
Posts: 2266
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: ping with lua and switch

Post by jvdz »

Have a look here before trying reinventing this : http://domoticz.com/wiki/Presence_detection :)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: ping with lua and switch

Post by Derik »

Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
maomanna
Posts: 94
Joined: Monday 30 November 2015 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: ping with lua and switch

Post 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
User avatar
jvdz
Posts: 2266
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: ping with lua and switch

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: ping with lua and switch

Post 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
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: ping with lua and switch

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: ping with lua and switch

Post by tiga »

ok thanks i will try these out
sploutchi
Posts: 9
Joined: Friday 11 July 2014 10:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: ping with lua and switch

Post by sploutchi »

Hi tiga,

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

Enjoy :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest