Author Topic: Multiple commands in HTTP string  (Read 573 times)

Offline amino

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Multiple commands in HTTP string
« on: February 18, 2017, 07:33:00 am »
Hi

Is there any way to combine multiple commands in a single HTTP request string. For example:

http://192.168.1.107:3480/data_request?id=variableset&DeviceNum=35&serviceId=urn:micasaverde-com:serviceId:GenericSensor1&Variable=CurrentLevel&Value=0.6723
http://192.168.1.107:3480/data_request?id=variableset&DeviceNum=35&serviceId=urn:micasaverde-com:serviceId:HaDevice1&Variable=BatteryLevel&Value=45

Is it possible to combine the above two HTTP requests into a single one that sets the batteryLevel and CurrentLevel?

I'd Appreciate any feedback.

Thank you


Offline akbooer

  • Master Member
  • *******
  • Posts: 4892
  • Karma: +207/-67
  • "Less is more"
Re: Multiple commands in HTTP string
« Reply #1 on: February 18, 2017, 07:54:25 am »
No, it's not.

...although you could easily write your own HTTP handler with whatever parameters you need.

See: http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_register_handler

It's very simple to do that and there are examples of this in the forum already.



Edit: see fully worked example here: http://forum.micasaverde.com/index.php/topic,39814.msg296454.html#msg296454
« Last Edit: February 18, 2017, 08:00:17 am by akbooer »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9368
  • Karma: +704/-129
    • RTS Services Plugins
Re: Multiple commands in HTTP string
« Reply #2 on: February 18, 2017, 07:58:33 am »
You can use the RunLUA request and send two lines of code to set the two variables.

Offline amino

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Multiple commands in HTTP string
« Reply #3 on: February 18, 2017, 09:14:57 am »
Thank you.

I'll look closely at both options.

I tried to look for some information on the "RunLUA" request but could not find any, either on the forum or a Google Search. Do you know of any examples or documentation?

Offline akbooer

  • Master Member
  • *******
  • Posts: 4892
  • Karma: +207/-67
  • "Less is more"
Re: Multiple commands in HTTP string
« Reply #4 on: February 18, 2017, 12:25:39 pm »
I tried to look for some information on the "RunLUA" request but could not find any, either on the forum or a Google Search. Do you know of any examples or documentation?

Documented (albeit briefly) here:
http://wiki.micasaverde.com/index.php/Luup_UPnP_Variables_and_Actions#HomeAutomationGateway1

Actually, that's more like 'mentioned' rather than 'documented', but it is a simple action request with the 'code' parameter for your Lua, and serviceId:

Code: [Select]
urn:micasaverde-com:serviceId:HomeAutomationGateway1
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline amino

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Multiple commands in HTTP string
« Reply #5 on: February 18, 2017, 07:43:57 pm »
Thanks! Looks like RunLua may do the job. However I'm unsure of the syntax. I can't figure out if the Lua Code needs to be enclosed in Quotes or Braces. I tried both as well as none but I get an "Error: code failed". Just to try  out "RunLua", I have some simple Lua code to turn on Device 3:

http://192.168.1.107:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="1"},3)

Returns "Error: Code Failed"

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9368
  • Karma: +704/-129
    • RTS Services Plugins
Re: Multiple commands in HTTP string
« Reply #6 on: February 18, 2017, 08:08:48 pm »
You will have to URL Encode the LUA code you want to run.

Offline amino

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Multiple commands in HTTP string
« Reply #7 on: February 19, 2017, 08:18:30 am »
Yes, the browser (Chrome), I was testing the HTTP request on will automatically encode the URL before sending it to the Server. I was using the wrong device number and hence the error.

In case others are interested in this very sparsely documented feature, here is a sample HTTP request that uses RunLua to run two Lua statements (turns two devices off):  -Lua code is shown URL encoded -

 http://192.168.1.107:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=luup.call_action(%22urn:upnp-org:serviceId:SwitchPower1%22,%22SetTarget%22,{newTargetValue=%221%22},16);luup.call_action(%22urn:upnp-org:serviceId:SwitchPower1%22,%22SetTarget%22,{newTargetValue=%221%22},28)

Thanks for help in getting this figured out.