Page 1 of 1

Lua Ping presence script keeps running

Posted: Friday 19 August 2016 12:40
by desertdog
I am using this basic lua ping presence script which works fine except it keeps sending a ping every second. Scripts are normally fired once every minute, so how do I stop this script after one ping? Even beter would be if this script only ran once every 5 or 10 minutes. How do I achieve that?

Code: Select all

commandArray = {}

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

return commandArray

Re: Lua Ping presence script keeps running

Posted: Friday 19 August 2016 12:45
by jvdz
Is this created with the internal Editor? If so, you probably have All in the dorpdownbox under LUA and need to change that to "Time".
I wouldn't recommend to have this script ran with the eventsystem as that is single threaded and could create a delay for other events.

Jos

ps, I would also add a test whether the switch actually needs to be changed:

Code: Select all

commandArray = {}

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

return commandArray