Finding corrupt LUUP Code

This code, when run in the Lua TestCode window, will check all the scene Lua:

local json = require "dkjson"
for i,s in pairs (luup.scenes) do
    print (i, s.description)
    local _,j = luup.inet.wget ("127.0.0.1:3480/data_request?id=scene&action=list&scene=" .. i)
    local sc = json.decode (j)
    if sc and sc.lua then 
        local ok, err = loadstring (sc.lua, "scene_code_test")
        if ok then print ('',"ok") else print ('', err) end
    end
end

In order to see the printed output from this, you’d need to be running with AltUI. On my development machine this gives output like:

1 	toggle table
 	ok
2 	toggle bedside
 	ok
3 	Timer Test
 	ok
6 	Tuesday
 	ok
7 	Monday
 	ok
8 	Wednesday
 	ok
9 	Weekday
 	ok
10 	December
 	ok
11 	Sunset
 	ok
12 	Sunrise
 	ok
13 	Weekend
 	ok
14 	Delayed Actions
 	ok

If there was a syntax error, the ‘ok’ would be replaced by an appropriate error message.

Note: that this DOESN’T check the trigger Lua code, but could easily be modified to do so.

Wow, Thank you! I’ll give it a try this eve.

Where is the problem?

Scene 222

local dID = 36 – Device ID of Lumiere entree
local allow = true – true runs scene if switch is on, false blocks it
local status = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,dID)
return ((status == “1”) == allow)

Result:

222 Lumiere Entree Off
[string “scene_code_test”]:1: unexpected symbol near ‘’

I have many scene resulting like this
or some result like this:

221 Lumiere Principal Off
[string “scene_code_test”]:1: ‘=’ expected near ‘==’
187 A/C Maitres Off
[string “scene_code_test”]:1: ‘=’ expected near ‘+’

Don’t know. Let’s try and find out by printing out the Lua itself.

local json = require "dkjson"
for i,s in pairs (luup.scenes) do
    print (i, s.description)
    local _,j = luup.inet.wget ("127.0.0.1:3480/data_request?id=scene&action=list&scene=" .. i)
    local sc = json.decode (j)
    if sc and sc.lua then
        --print('', sc.lua)
        local ok, err = loadstring (sc.lua, "scene_code_test")
        if ok then 
            print ('',"ok") 
            print (sc.lua)
        else 
            print ('', err) 
        end
    end
end

I take it that SOME of your scenes are OK?

I’m slightly perturbed that the error line is always reported as 1.

Yes a lot are ok…
how can i send you the result?
it say:

The following error or errors occurred while posting this message:
The message exceeds the maximum allowed length (20000 characters).

Hi guys,

Just to ping in. If you are referring to the status bar error "Error in lua for scenes and event ". then you can look in user_data with the following command:

[font=arial][size=13px]VERALOCALIP/port_3480/data_request?id=user_data&output_format=xml[/size][/font]

[font=arial][size=13px]and search for: lua= [/size][/font]

[font=arial][size=13px]And if you see luup code that is NOT encoded and is shown in clear, then, that scene is the issue. Due to latest changes, LUA code in user_data data will show encoded in and it will show something like this : [/size][/font]

lua="aWYgKGx1dXAuaXNfbmlnaHQoKSkgdGhlbgogICAgIHJldHVybiB0cnVlCiAgZWxzZQogICAgIHJldHVybiBmYWxzZQogIGVuZA==" encoded_lua="1"

So in user_data.xml …

Correct:

lua="aWYgKGx1dXAuaXNfbmlnaHQoKSkgdGhlbgogICAgIHJldHVybiB0cnVlCiAgZWxzZQogICAgIHJldHVybiBmYWxzZQogIGVuZA==" encoded_lua="1"

NOT Correct

if (luup.is_night()) then return true else return false end

However, on Vera graphical user interface, the luup code will still be shown in clear. The mentioned change is for user_data only.

Also, XA44Owq26HxCq88 - you mention that you Deactivate scene from the mobile app. - We have discovered a recent bug in the iOS mobile app, which is conjunction with scenes that contain luup code, causes the scene to break, by removing the encoding from user_data,. We have reported this and it will be fixed with the upcoming update of the mobile app. So for the moment, avoid Deactivating the lua containing scenes, from the mobile app.

Solution:

Copy the code, somewhere safe → delete it from the scene → Save scene without code → edit the scene again → add the luup code again → double check user data, to make sure it shows encoded.

Hope this info is of help, and makes sense :slight_smile: but feel free to ask, is something is unclear.

Just realize copy each lua from Vera UI and paste to AltuI fixed and passed the Test
Thanks akbooer

Don’t know. Let’s try and find out by printing out the Lua itself.

local json = require "dkjson"
for i,s in pairs (luup.scenes) do
    print (i, s.description)
    local _,j = luup.inet.wget ("127.0.0.1:3480/data_request?id=scene&action=list&scene=" .. i)
    local sc = json.decode (j)
    if sc and sc.lua then
        --print('', sc.lua)
        local ok, err = loadstring (sc.lua, "scene_code_test")
        if ok then 
            print ('',"ok") 
            print (sc.lua)
        else 
            print ('', err) 
        end
    end
end

I take it that SOME of your scenes are OK?

I’m slightly perturbed that the error line is always reported as 1.[/quote]

And now how to check the trigger Lua code?

John, thanks for the tip about the recent bug found. However, I’m using an android phone, does the bug affect androids also?

And now how to check the trigger Lua code?

Triiggers are declarative … i.e. there is no explicit LUA code.
Every trigger has an underling luup.variable_watch that causes the declarations to be evaluated when the underlying data changes.
The code that does this is all part of the core of the Vera LUA system.
This same declarations are what cause notifications to be sent as well. In Vera a notification is a hidden scene.

[quote=“RichardTSchaefer, post:14, topic:196093”] And now how to check the trigger Lua code?
Triiggers are declarative … i.e. there is no explicit LUA code.
Every trigger has an underling luup.variable_watch that causes the declarations to be evaluated when the underlying data changes.
The code that does this is all part of the core of the Vera LUA system.
This same declarations are what cause notifications to be sent as well. In Vera a notification is a hidden scene.[/quote]

IIRC, each trigger allows the possibility of having its own additional Lua code. This is the sort of thing which allows you to identify which trigger has actually kicked off the scene - quite a common approach - or, indeed, cancel the trigger entirely before even getting to the scene.

I thought I read that this is something that was possible in UI5 but got deleted in UI7?

Yes, I really don’t use UI7. It may well be that the Vera UI doesn’t support it, but the underlying system still does (easy to try with AltUI?)

[quote=“akbooer, post:5, topic:196093”]This code, when run in the Lua TestCode window, will check all the scene Lua:

local json = require "dkjson"
for i,s in pairs (luup.scenes) do
    print (i, s.description)
    local _,j = luup.inet.wget ("127.0.0.1:3480/data_request?id=scene&action=list&scene=" .. i)
    local sc = json.decode (j)
    if sc and sc.lua then 
        local ok, err = loadstring (sc.lua, "scene_code_test")
        if ok then print ('',"ok") else print ('', err) end
    end
end

In order to see the printed output from this, you’d need to be running with AltUI. On my development machine this gives output like:

1 	toggle table
 	ok
2 	toggle bedside
 	ok
3 	Timer Test
 	ok
6 	Tuesday
 	ok
7 	Monday
 	ok
8 	Wednesday
 	ok
9 	Weekday
 	ok
10 	December
 	ok
11 	Sunset
 	ok
12 	Sunrise
 	ok
13 	Weekend
 	ok
14 	Delayed Actions
 	ok

If there was a syntax error, the ‘ok’ would be replaced by an appropriate error message.

Note: that this DOESN’T check the trigger Lua code, but could easily be modified to do so.[/quote]

After months of successful operation, my vera edge suddenly reports Error in Lua for scenes and events. It should be noted that exactly the same code is running on a VeraLite flawlessly for over a year albeit at an earlier firmware release.

  1. The issue was reported to technical support with remote enabled though without any tangiable result;
  2. The procedure described earlier in the chapter contributed by Sorin M. ▾ Community Manager, proposing to use: VERALOCALIP/port_3480/data_request?id=user_data&output_format=xml was followed but did not resolve the issue.
  3. Finally I followed the above route by installing AltUI and got as far as loading the code. I assume in order to run, you have to click just the submite button. However, this results in error message: Code excution failed & Lua Command execution on vera failed.(No handler). Search in the luaupnp log file on altui but could not find anything. Any guidance how to get this running?
  4. If all above fails, is the purchase of the ZEROBRANE Lua editor of any use?

Appreciate any feedback such that the unit can be put into service again.

“Error in Lua for scenes and events” seems to be absolutely rife at the moment. Possibly something to do with relatively recent firmware upgrades?

If you search you should find tonnes of references. There may be a corruption in some scene Lua somewhere, which breaks everything.

On the AltUI issue, you may be better posting a specific question on that sub forum.

There hasn’t been any recent firmware release though and this is a very strange one. I am suspicious of some library corruption of some sort.

Without picking through all of them, it seems like quite a few are simple errors that have just gone unnoticed for some time. A syntax error in scene or startup Lua wouldn’t impact the entire system until after a reload, so to the casual observer all may seem fine, until suddenly it’s not.

That still does not explain all of them, that is true, but given what we know about memory consumption and leaks, it’s not entirely surprising that after some random time, if memory is impacted, a sudden inability to execute Lua cleanly occurs. Many have said that a reboot of their system has resolved their issue, which for me makes some memory leak/exhaustion a high likelihood. Consider, there may be code paths rarely taken, that suddenly and just for the moment and circumstances of the day are more frequent. With big transitions going on at Vera, and a recent spate of downtime events for various subsystems, who knows what ripple effect we might see. For example, what if there’s a memory leak in the code that checks for plugin updates? If apps.mios.com or its loadshared aliases aren’t available, an error exit path is repeatedly taken as your Vera keeps retrying, but this path leaks memory or fails to return some other used resource (file handle, socket, etc.), eventually to destruction. This could even happen outside of LuaUPnP, in any of the numerous scripts and daemons that run in the system, slowly eroding some resource until LuaUPnP itself is affected.

Im still getting the random error but i cant pinpoint it

Hi

Have been having some intermittent issues recently so I tried this script but as this thread has not been updated for a while, I was just wondering if there had been any developments with the original code @akbooer created - everything reports line 1 still and all of my scenes with luup code report an error, when running the script ?

All scenes with errors below report ‘Success’ when manually run…

Print output extract.

1     Midnight Shutdown     
     ok   
       
2     Switch Matrix to Sky TV     
     [string "scene_code_test"]:1: unexpected symbol near ''     
3     Switch Matrix to Apple TV     
     [string "scene_code_test"]:1: unexpected symbol near ''     
4     Switch Matrix to NAS     
     [string "scene_code_test"]:1: '=' expected near '=='     
5     HDMI Matrix Input 4     
     [string "scene_code_test"]:1: unexpected symbol near ''     
6     HDMI Matrix LED OFF     
     [string "scene_code_test"]:1: unexpected symbol near ''     
7     HDMI Matrix LED ON     
     [string "scene_code_test"]:1: unexpected symbol near ''     
8     Turn Matrix Off     
     [string "scene_code_test"]:1: '=' expected near '=='     
9     Turn Matrix On     
     [string "scene_code_test"]:1: unexpected symbol near ''     
10     Night Light     
     ok     
     
11     Day Light     
     ok     
     
12     Turn Everything On     
     [string "scene_code_test"]:1: unexpected symbol near ''     
13     Turn Everything Off     
     [string "scene_code_test"]:1: '=' expected near '=='     
14     Dim Dining Room Lights to 50%     
18     Kids Bedtime Countdown     
     [string "scene_code_test"]:1: '=' expected near ''     
20     Kids Joke     
     [string "scene_code_test"]:1: unexpected symbol near ''   `

Have you tried the LuaView plugin by @rigpapa?

1 Like