Finding corrupt LUUP Code

Is there any way of determining which scene holds a corrupted code, other than the notification that there is a corrupt code somewhere?

Yesterday I disabled three scenes via my phone app. Didn’t think anything was amiss, seeing as how the scenes that I disabled did not run. Later in the day, other scenes did not run. I logged into my VeraPlus on my PC and saw that there was a notice that there was a corrupt code.

I went to the three scenes and found all the LUUP code that was supposed to be in the three scenes was just a bunch of garbage. I had to delete the scenes in order to get my other scenes working again. (I’ve go the scene code in a text file for just this type of event)

In the past when this has happened, I was able to go back to the most recent scene I had worked on and found the corrupt code. I imagine at some point, other scenes will be corrupted without my direct interaction. I would need to find those scenes, without editing each scene that contains code.

running a VeraPlus, 1.7.2608

It would not be too difficult to write a piece of Lua code to request each of the scene Lua code parts and attempt to compile each one.

However, in the circumstances, I’d be much more concerned about finding out the root cause of the corruption rather than constantly trying to fix it.

Finding the root cause would be great, but after going through the process of working with Vera and having limited success on other LUUP corruption issues, I guess I’m just tired of trying to find out why. If I know the action that caused the corruption, it seems easier just to avoid that action. It’s too bad there are all these annoying bugs in the operating system for Vera. Nothing fatal, so far, just annoying.

I don’t use the phone app very often, so that’s easy to avoid. The past issue had been my attempt to disable a scene via my PC which caused the corruption. Vera fixed that issue as far as I can tell.

The issue before this is Vera replacing spaces in scene names with %20. No solution to that issue was forthcoming.

So I’m looking for a way to identify the corruption, not cure it. Writing a LUUP code to do the identification of a corrupt LUUP code seems circular to me, though it might be the only way to do this.

Whilst it would be most convenient to do this on the Vera in question, there’s no problem in doing so from a remote machine either, since in both cases the scene code would be retrieved with an HTTP request.

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.