LUA scripts hangs

Moderator: leecollings

Post Reply
madrian
Posts: 231
Joined: Saturday 27 August 2016 1:18
Target OS: -
Domoticz version:
Contact:

LUA scripts hangs

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

Re: LUA scripts hangs

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest