Lua script hangs waiting for Curl / help needed
Posted: Monday 17 December 2018 16:47
Hi
I have a couple of LUA scripts that sometimes dont get respons and then just waiting and hangs my system.
I want to have a set timeout that if i dont get respons within X seconds then terminate the script optional terminate and give a pushnotice.
below is my Script anyone that can assist me ?
/Peter
local switch_door = 'EntreDörr'
commandArray = {}
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config=assert(io.popen('curl "http://192.168.x.x:8180/api/states/lock.entren"'))
local s = config:read('*all')
config:close()
local JsonData = json:decode(s)
if JsonData.state == "locked" then
commandArray[switch_door]='On'
else
commandArray[switch_door]='Off'
end
return commandArray
I have a couple of LUA scripts that sometimes dont get respons and then just waiting and hangs my system.
I want to have a set timeout that if i dont get respons within X seconds then terminate the script optional terminate and give a pushnotice.
below is my Script anyone that can assist me ?
/Peter
local switch_door = 'EntreDörr'
commandArray = {}
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config=assert(io.popen('curl "http://192.168.x.x:8180/api/states/lock.entren"'))
local s = config:read('*all')
config:close()
local JsonData = json:decode(s)
if JsonData.state == "locked" then
commandArray[switch_door]='On'
else
commandArray[switch_door]='Off'
end
return commandArray