This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LM5 Resident scripts can rarely freeze
#1
Yesterday, my client give me the feedback that function OFF isn't now working. This function works in Resident 0s and its switch off near all lights in home and delays switch off of the lights on stairs. And script was halted, its status was "green" but this was a day so if it will be switched on at day it starts, do simple job and immediately disable itself so it was not working. I've found similar issue on other LM a few times but it was connected with HTTP or calculating statuses and small CPU power of devices. At this time this occured on LM5 with 20180523 firmware. I think it should be for sure solved, at least distinguish if some script is halted.

This is a script (if during day it immediatelly should switch of):

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
-- Gdy noc, wtedy wyłącz całe oświetlenie wewn. oprócz korytarza i schodów, które wyłącz z opóźnieniem (od wywołania lub ostatniego ruchu w strefie dziennej). -- Gdy dzień, wtedy całe oświetlenie wewn. if not disableScript then  -- wstępna konfiguracja  disableScript = function()    grp.checkupdate("OFF_signalling", false)    script.disable(_SCRIPTNAME)  end    grp.checkupdate("OFF_signalling", true)    grp.write("OFF_Natychmiast", false)  grp.write("OFF_Później", not day) -- jeśli noc wtedy włącz oświetlenie orientacyjne m.in. schody end offset = grp.getvalue("OFF_Czas świecenia") day = grp.getvalue("Dzień") if day then  disableScript()     return     end waitFromLastMotion = grp.getvalue("OFF_odliczaj od ruchu") if waitFromLastMotion then  local motionInDayZone = grp.find("Ruch w strefie dziennej_status")  local lastMotion = motionInDayZone.updatetime  local motion = motionInDayZone.value  local elapsed = os.time() - lastMotion    if not motion and elapsed >= offset then      -- wyłącz oświetlenie korytarza    grp.write("OFF_Później", false)    disableScript()  elseif motion then    os.sleep(offset + 1)  else    -- odczekaj tyle co pozostało do 45    os.sleep(offset - elapsed + 1)  end else  os.sleep(offset)  -- wyłącz oświetlenie korytarza  grp.write("OFF_Później", false)  disableScript() end
Done is better than perfect
Reply
#2
Try adding log calls before sleep (with sleep time to make sure that script is not just sleeping for too long) and disableScript. At least you will know where exactly your script stops working.
Reply
#3
Thanks for response?

I can check this from OFF_signalling variable. But this I can check only in the future because now was updated.

How os.sleep() works? Maybe there is some edge case and some mechanism cannot go back to script after os.sleep exceeded? Offset is 45s now and it is a number from 0-255.
Done is better than perfect
Reply
#4
os.sleep calls C nanosleep internally. It has a built-in check that sleep time must be positive, so the issue is not there.
Reply


Forum Jump: