Resolved: Lua in XML doesn't run

I’m trying to reproduce Somfy device, and while all the code runs OK within Test Luup Code context, the same code placed into Luup XMLs doesn’t seems to be invoked ever. I realized that by seeng none of my debug prints, and after I “removed” child nodes from Test Luup Code - they never re-appeared after restart even though startup code is there.

<root>
−
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
−
<device>
<deviceType>urn:somfy-com:device:blinds:1</deviceType>
<friendlyName>Somfy Blind Controller</friendlyName>
<manufacturer>Somfy</manufacturer>
<manufacturerURL>http://www.somfy.com</manufacturerURL>
<modelDescription>16 port RS232 to Somfy blind interface</modelDescription>
<modelName>1810686</modelName>
<modelNumber>1.0</modelNumber>
<protocol>raw</protocol>
<handleChildren>1</handleChildren>
−
<implemenationList>
<implementationFile>I_SomfyBlinds.xml</implementationFile>
</implemenationList>
<presentationURL/>
</device>
</root>
<implementation>
−
<settings>
<protocol>crlf</protocol>
</settings>
−
<functions>

	function lug_startup(lul_device)
		local lul_ID = lug_device[lul_device].ID
		lu_log("ID is " .. lul_ID)
		child_devices = lu_chdev_start(lul_device);
		for i=1,16 do
			s=string.format("%02d", i)
			if( string.find (lul_ID,s)~=nill ) then
				lu_log("Adding blind "..s)
				lu_chdev_append(lul_device,child_devices,s,"Blind #"..s,"urn:schemas-upnp-org:device:BinaryLight:1","","","",true)
			end
		end
		lu_chdev_sync(lul_device,child_devices)
	end
  
</functions>
−
<incoming>
−
<lua>

      lu_log("Received: " .. tostring(lul_data))
    
</lua>
</incoming>
<startup>
	lug_startup
  </startup>
−
<actionList>
−
<action>
<serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId>
<name>SetTarget</name>
−
<run>

		lu_log("DDDDDDDD")
		local lul_command = '!' .. lug_device[lul_device].ID .. 'U'
		local lul_reverse = lu_GetVariable("urn:micasaverde-com:serviceId:HaDevice1","ReverseOnOff",lul_device)
		if( lul_settings.newTargetValue=="1" or (lul_settings.newTargetValue=="0" and lul_reverse=="1") ) then
			lul_command = '!' .. lug_device[lul_device].ID .. 'D'
		end
		lu_log(">>>>>>>>>>>>trying to send the command: " .. tostring(lul_command),1)
		if lu_iop_send(lul_command)==false then
			lu_log("cannot send: " .. tostring(lul_command),1)
			lu_SetCommFailure(true)
			return false
		end
     
</run>
</action>
</actionList>
</implementation>

I just added 2 more debug lines, which will be in any version >765; I’ll try to build another tonight or tomorrow. Turn on verbose logging and grep for:

JobHandler_LuaUPnP::ParseAllImplementations

or

Device_LuaUPnP::MatchupImplementations

The first will list all implementation xml files that are loaded in the system. The 2nd will list every device and indicate which implementation file is bound to that device. This will tell us if it’s not finding the file, or maybe failing to parse or something. Also in the current release you can grep for:

LuImplementation::Parse

If the implementation file doesn’t load because it’s not found, or there’s a syntax error, you’ll see a log entry with that in it.

After upgrade to 770 my lua stuff doesn’t seem to be started, I submit ticket: 842

Update: After that I reset Vera to factory settings, recreated the “Somfy” device (serial port finally appeared), added lu_log prints to lug_startup, and I still see none of them in the log, which means lug_startup doesn’t run.

However, in LuaUPnP.log I found the following
lug_startup
failed attempt to call a nil value[[0m <0x402>

Any ideas?

Try using the following

<startup>lug_startup</startup>

no spaces, no return characters, just the line above.

Mine won’t run unless I write it exactly like that. If I put in “one” return character, like:

<startup>lug_startup </startup>

then [tt]lug_startup()[/tt] wont run. It seems a little overly sensitive to “whitespace” characters.

Woo-hoo! Thank you so much, guessed!

I remember this kind of problem back in 2004, old app config I worked with, but since then parsers appear to evolve quite well…

MCV: Can we make the XML Parsing and/or Usage of the [tt][/tt] element less sensitive to whitespaces? Once people start using XML editors they’re likely to run into this problem a few times.

I hit it because my editor was trying to format it nicely (by default).

done