Lua code working in test window but not in vera scene

Hello,

I am on a Vera lite with the latest UI 7. I am trying to create a scene to send a command to another HA controller. (Domoticz in this case). My single line of code is very simple, all it does is send an http request to control a switch.

luup.inet.wget(‘http://user:pw@192.168.1.5:8084/json.htm?type=command&param=switchlight&idx=58&switchcmd=On’)

The string above works perfectly fine if I use it in the test Luup code window. However I want to use this code in normal scene so I pasted the string into the Lua section of the scene I created specifically for this. When I try to run the scene, nothing happens. I then went back into the scene editor and found out that a couple of characters had dissapeared from the string:

somewhere in the middle of the string the following characters ‘&param’ have been replaced by ‘?’ rendering my command incorrect, as shown below.

luup.inet.wget(‘http://user:pw@192.168.1.5:8084/json.htm?type=command?m=switchlight&idx=58&switchcmd=On’)

I tried to place the string inside quotes like this “” but the issue keeps coming back as soon as my scene is saved.

Has anyone seen this before? Any suggestions to do this in a different way?

Thanks a lot,

Jacques

You are running into a url encoding issue…

In your command string, replace the ampersand (“&”) with “%26”.

luup.inet.wget('http://user:pw@192.168.1.5:8084/json.htm?type=command&param=switchlight&idx=58&switchcmd=On')

becomes

luup.inet.wget('http://user:pw@192.168.1.5:8084/json.htm?type=command%26param=switchlight%26idx=58%26switchcmd=On')

Thanks cybrmage!

I tried to replace the (“&”) character with (“%26”) but that didn’t work. Then I tested the same string with the curl command below:

os.execute('curl -k "http://user:pw@192.168.1.5:8084/json.htm?type=command&param=switchlight&idx=58&switchcmd=On"')

This now works! -:slight_smile:

However the thing I don’t get is that there are 3 (‘&’) in my string and only one of them gets replaced by this character (“?”) while the other 2 remain unchanged. This happens directly after saving the scene and running it for the first time. At the second run of the scene the (“&”) character gets replaced by (“?”) but strangely the scene continuous to work correctly. ???

Could this be a bug?

In any case thanks again for your suggestion because it got me finally to a working scene.

cheers,

Jacques