Page 1 of 1

LUA scripts hangs

Posted: Saturday 15 July 2017 21:33
by madrian
I have a Dimmer switch and I want to set level when It's turned on (by default it's only switching on, without level change):

Code: Select all

 if devicechanged[DomDevice] then
   
      lastValue = os.execute ("php /home//domoticz/userscripts/bedled.php")
      print(lastValue)

   print("dev " .. devicechanged[DomDevice]);

   if(devicechanged[DomDevice]=='On') then
      commandArray[DomDevice] = 'Set Level 40' --test
      return commandArray
   end
end
(bedled.php output is a json processor, which outputs the last value of the dimmer, example 43)

Result?

Code: Select all

2017-07-15 21:45:38.149  Error: EventSystem: Warning!, lua script /home/madrian/domoticz/scripts/lua/script_device_BEDLED.lua has been running for more than 10 seconds
2017-07-15 21:45:28.140  (LED) Lighting 5 (BEDLED)
2017-07-15 21:45:38.239  LUA: exit
2017-07-15 21:45:38.240  LUA: 0
2017-07-15 21:45:38.240  LUA: dev Set Level: 37 %
:evil:

Domoticz freezes.

I even tried to decode JSON directly in LUA, same problem:

Code: Select all

local address = '192.168.1.54:8080'
url   = 'curl "http://'..address..'/json.htm?type=devices&rid=25"'
local config=assert(io.popen(url)
local location = config:read('*all')
config:close()
local jsonLocation = json:decode(result)

Re: LUA scripts hangs

Posted: Saturday 15 July 2017 22:01
by jvdz
Similar reports have been made about os.execute() not properly ending and returning but hanging for 10 seconds.
Just add an & at the end of the commandline to have it return right away, but of course you miss the return code.

Code: Select all

lastValue = os.execute ("php /home//domoticz/userscripts/bedled.php &")
Jos