LUA, What is wrong in my code
Posted: Friday 24 June 2016 10:26
I get this message in Log
What I want to do is to Ping the Pi that handle the CGI and if Ping is not successful I want the script to exit.
This is my script
Code: Select all
2016-06-24 10:20:10.245 Error: EventSystem: Warning!, lua script larmstatus has been running for more than 10 seconds
2016-06-24 10:20:10.265 LUA: Ping failedThis is my script
Code: Select all
commandArray = {}
ping_success=os.execute('ping -c1 192.168.xxx.xxx')
if ping_success then
print("ping success")
time = os.date("%Y-%m-%d %H:%M:%S")
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
file = io.open("larm.txt", "a")
file:write(time.."\n")
local visonic=assert(io.popen('curl http://192.168.xxx.xxx/cgi-bin/jsongetxplstate.cgi'))
file:write("curl ok\n")
local status = visonic:read('*all')
visonic:close()
if status == "" then
--print("h")
file:write("empty\n")
file:write(status.."\n")
else
--print (status)
file:write(status.."\n")
local jsonStatus = json:decode(status)
print (jsonStatus)
--file:write(jsonStatus.."\n")
powermaxstatus = jsonStatus['pmaxstatus']
--print(powermaxstatus)
--print(otherdevices['Visonic Alarm Status'])
if (powermaxstatus == "disarmed" or powermaxstatus == "armed" or powermaxstatus == "armed-home" or powermaxstatus == "armed-away") then
if powermaxstatus == "disarmed" and otherdevices['Visonic Alarm Status'] == "On" then
print('<font color="blue">Visonic: Larmat av</font>')
commandArray['Visonic Alarm Status'] = "Off"
commandArray[1]={['SendEmail']='Avlarmat# #[email protected]'}
--commandArray[2]={['SendEmail']='Avlarmat# #[email protected]'}
end
if (powermaxstatus == "armed" or powermaxstatus == "armed-home" or powermaxstatus == "armed-away") and otherdevices['Visonic Alarm Status'] == "Off" then
print('<font color="red">Visonic: Larmat på</font>')
commandArray['Visonic Alarm Status']='On'
commandArray[1]={['SendEmail']='Pålarmat# #[email protected]'}
--commandArray[2]={['SendEmail']='Pålarmat# #[email protected]'}
end
end
end
file:close()
else
print('<font color="red">Ping failed</font>')
end
return commandArray