Hi,
In one of my plug-ins I encountered a strange problem which I want to share.
From the plug-in I have to send data over IP to another device on my home network.
Therefore I used the following code in the Vera device implementation file (I_xxx.xml):
local http = require(“socket.http”);
local strCmd = http.request(“http://10.0.0.155/command/invoke\?swid=/Tussenweid/Publiek/statusLampen&command=manualSet&arg=” … tostring(newStatus));
The above long line is actually only one line.
If I paste this code into the “Test Luup code (Lua)” it just runs fine.
Same code pasted into the I_xxx.xml causes Vera not to run this code.
While debugging my code, I commented out the long line, expecting lua to jump over this line, because it now is only a comment.
However, this seems not to be true, because lua still recognizes the ? and the & and refuses to run the program.
Changing the ? into \063 and & into \038 cures the problem.
Strange however, that even when commented out, using --, causes failure.
Regards.
[quote=“Snotneus, post:1, topic:168537”]Hi,
In one of my plug-ins I encountered a strange problem which I want to share.
From the plug-in I have to send data over IP to another device on my home network.
Therefore I used the following code in the Vera device implementation file (I_xxx.xml):
local http = require(“socket.http”);
local strCmd = http.request(“http://10.0.0.155/command/invoke\?swid=/Tussenweid/Publiek/statusLampen&command=manualSet&arg=” … tostring(newStatus));
The above long line is actually only one line.
If I paste this code into the “Test Luup code (Lua)” it just runs fine.
Same code pasted into the I_xxx.xml causes Vera not to run this code.
While debugging my code, I commented out the long line, expecting lua to jump over this line, because it now is only a comment.
However, this seems not to be true, because lua still recognizes the ? and the & and refuses to run the program.
Changing the ? into \063 and & into \038 cures the problem.
Strange however, that even when commented out, using --, causes failure.
Regards.[/quote]
@snotneus
I have encountered issues with special characters as well. LUA seems to have issues with it.
You might try to use escape characters (for instance space = %20) to work around this.
Let us know if that helped
Henk,
As decribed in my first post, using escape characters does cure the problem.
But to me it is very strange, that if the line is commented out using --, the special characters still cause problems.
Regards.
[quote=“Snotneus, post:3, topic:168537”]Henk,
As decribed in my first post, using escape characters does cure the problem.
But to me it is very strange, that if the line is commented out using --, the special characters still cause problems.
Regards.[/quote]
Did you check line breaks (cr/lf or others?)
Maybe theres a linebreak detected somewhere making your single line of code being split into more?
If not… im out of options…
Device declaration and implementation files must be valid XML documents.
The [tt]&[/tt] character, along with the [tt]<[/tt] character, must be [XML] escaped to ensure that the XML document remains valid. In this case the following type of substitutions need to be made:
[tt]&[/tt] → [tt]&[/tt]
[tt]<[/tt] → [tt]<[/tt]
Also note that you can use [tt]luup.inet.wget()[/tt] to do the same thing you’re doing with LuaSocket:
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_wget