Help for novice on Device and Implementation files

Hi guys,

I am trying to do a little plugin, but I am struggling just to create an empty plugin.

I created a Device and an Implementation file using the Panasonic example. I have stripped it down to basicly nothing and I still get errors. Could somebody guide me, please?

Device File (D_Test1.xml:

<?xml version="1.0"?> 1 0
<implementationList>
    <implementationFile>I_Test1.xml</implementationFile>
</implementationList>

<serviceList>

  <service>
    <serviceType>urn:micasaverde-com:service:Volume:1</serviceType>
    <serviceId>urn:micasaverde-com:serviceId:Volume1</serviceId>
    <SCPDURL>S_Volume1.xml</SCPDURL>
  </service>

</serviceList>

Implementation file (I_Test1.xml):

<?xml version="1.0"?> urn:micasaverde-com:serviceId:Volume1 Mute luup.log('Test: now in mute...')

/ankere

The snippets look correct, but you’re going to need to define “Errors” (in detail) as that’s a broad term when you’re talking about Luup programming and Device setup.

hi guessed,

Sorry, but that doesn’t make ane sence to me… ???

I dont know how to do that and what it would do for my test plugin. Could you be so kind to elaborate?

/ankere

I’m referring to this part of your original post. You mentioned you “still get errors”, but you left out all the details associated with what those errors are, where you saw them, what you did before you saw them, etc. There’s a long list of things that can go wrong, so these details are critical to any diagnosis/recommendation on next-steps.

Start with Screenshots of these perhaps, as that might tell a bigger story than any textual descriptions…

Hi,

I got it working if my luup code is without CR, etc. but it is hard to maintain then. Is it because I use a standard notepad as editor on win 7? What is the prefered editor on win?

/ankere

Your plugin is working as designed. Proof:

root@MiOS_XXXXX:/tmp/log/cmh# tail -f LuaUPnP.log | grep mute
50      11/18/11 23:04:46.220   luup_log:86: Test:  now in mute... <0x2c0c>

Wordpad should do the trick on Windows.

[quote=“Ap15e, post:6, topic:169580”]Your plugin is working as designed. Proof:

root@MiOS_XXXXX:/tmp/log/cmh# tail -f LuaUPnP.log | grep mute
50      11/18/11 23:04:46.220   luup_log:86: Test:  now in mute... <0x2c0c>

Wordpad should do the trick on Windows.[/quote]

Thanks! I am using wordpad, but it seems that my luup code is teasing me…

Could someone pls help me on this:

  1. Do I need to recreate a device when the device file is changed and newly uploaded?
  2. Do I need to recreate a device when the implementation file is changed and newly uploaded?
  3. Do I need to recreate a scene to check the functionality or can I reuse if no canges has been made in the available actions?
  4. Am I correct that running a scene → advanced → pick a device is the easiest way of ‘debugging’ a plugin action?

Regards

/ankereu

1. Do I need to recreate a device when the device file is changed and newly uploaded?

No, just restart LuaUPnP (serveral times).

2. Do I need to recreate a device when the implementation file is changed and newly uploaded?

No, just restart LuaUPnP (serveral times).

There is no easy way to remove variables from a device, so depending on the changes to your code it may be
advisable to remove and recreate the device.

3. Do I need to recreate a scene to check the functionality or can I reuse if no canges has been made in the available actions?

No need to recreate the scene.

4. Am I correct that running a scene -> advanced -> pick a device is the easiest way of 'debugging' a plugin action?

Depends on your requirements - [tt]luup.log[/tt], [tt]WAI[/tt], and

[tt]http://wiki.micasaverde.com/index.php/Luup_Debugging
http://wiki.micasaverde.com/index.php/ZWave_Debugging
http://wiki.micasaverde.com/index.php/Luup_Scenes_Events
http://wiki.micasaverde.com/index.php/Luup_Requests
[/tt]

come to mind.

Hi again,

Now I am okay with the syntax in the Implementation file and have found what is my problem.

Within the XML implementation file I try to put together a SOAP request. The SOAP request works fine in a separate scene, but the vera XML parser seems to fail as XML tags (used for the SOAP request) are inside the functions tag in the Implementation file.

I can see in the log the following:
01 Jobhandler_LuaUPnP::ParseAllImplementations failed to parse I_Test1.xml <0x400>
01 LuImplementation:: Parse cant parse xml /etc/cmh-ludl//I_Test1.xml <0x400>

My best guess is that I cannot have XML tags like this inside the Implementation xml file:

local req = ‘<?xml version="1.0" encoding="utf-8"?>’ …
‘<s:Envelope xmlns:s=“Error”>’ …
‘<s:Body>’ …
‘<u:’ … action … ’ xmlns:u=“’ … servicetype … '”>’ …
arguments …
‘</u:’ … action … ‘>’ …
‘</s:Body>’ …
‘</s:Envelope>’

/ankere

A Luup implementation file must be a valid XML document ([tt]The W3C Markup Validation Service). You have to escape the offending characters ([tt]http://forum.micasaverde.com/index.php/topic,6826.msg43502.html#msg43502[/tt]).

Hi AP15e

Thanks a lot - I got passed that and am able to put together my SOAP request now… :slight_smile:

/ankere

If you’re going to be working a lot with XML, there are a few extra Lua constructs that’ll simplify things for you:

[ul][li]Lua supports a “Block” of string, delimited by [[ … ]]
You can see this in the Phone plugin codebase:

http://code.mios.com/trac/mios_smartphones/browser/L_sPhoneUI.lua#L32

This makes the block of string look a little more natural, and it will preserve line-breaks (etc) as you wrap the block over multiple lines. It can help improve the readability of the overall code.

[/li]
[li]Lua has library like functionality, put all your code into a .lua file.
In Luup, device files are constrained by the XML characters. You can put the bulk of the Lua code into a separate, plain-text, Library file (.lua) and then include it into your Device file (using [tt]require(…)[/tt])

You can see @mcvflorin do this in his Alarm implementation file:
I_VistaAlarmPanel1.xml in trunk – Honeywell Ademco Vista Alarm Panels via AD2USB

which references the [now separate] plain-text implementation/library file:
L_VistaAlarmPanel1.lua in trunk – Honeywell Ademco Vista Alarm Panels via AD2USB
[/li][/ul]