Author Topic: Multiple commands in HTTP string  (Read 1840 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


Online akbooer

  • Master Member
  • *******
  • Posts: 6041
  • Karma: +263/-69
  • "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, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10090
  • Karma: +762/-142
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?

Online akbooer

  • Master Member
  • *******
  • Posts: 6041
  • Karma: +263/-69
  • "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, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, 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: 10090
  • Karma: +762/-142
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.


Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2425
  • Karma: +33/-45
  • Life Moves Pretty Fast....
Re: Multiple commands in HTTP string
« Reply #8 on: September 23, 2017, 06:30:16 am »
The RunLua facility is pretty cool, ok so there?s hardly any documentation,  other than what is in the wiki but I can see some potential uses. For example (and to be confirmed), but theoretically it would allow an external product/service to directly inter act and update variables on Vera via a URL.

I?ve tried a couple of requests, some have been successfully others haven?t, so there maybe more to it than just url encoding some Lua Code.

I tried some print and luup.log requests but they failed e.g

Code: [Select]
http://192.168.1.234:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=print(%22Time:%20%22%20..%20os.date(%22%25X%20on%20%25A%20%25B%20%25d,%20%25Y%22))%0A%0Aprint(%22Timezone:%20%22%20..%20luup.timezone%20..%20%22%20hours%22)%0A%0Aprint(%22City:%20%22%20..%20luup.city)%0A%0Aprint(%22Latitude:%20%22%20..%20luup.latitude)%0A%0Aprint(%22Longitude:%20%22%20..%20luup.longitude)%0A%0Alocal%20srtime%20%3D%20os.date(%22%25c%22,luup.sunrise())%0A%0Aprint(%22Sunrise:%20%22%20..%20srtime)%0A%0Alocal%20sstime%20%3D%20os.date(%22%25c%22,luup.sunset())%0A%0Aprint(%22Sunset:%20%22%20..%20sstime)
I tried the following luup.variable_get in the hope it would return the value, but all I got was an OK

Code: [Select]
http://192.168.1.234:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=local%20daynight%20%3D%20204%20%20--%20daynight%20sensor%20device%20ID%0Alocal%20daynightstatus%20%3D%20luup.variable_get(%22urn:rts-services-com:serviceId:DayTime%22,%22Status%22,daynight)
The other Lua code I?ve tried where its just an action; to do something like turn lights on or off seems to work well.

I?m also currently not specifying a specific device ID as part of the RunLua URL structure, but that?s an option too to have the code run via that device.
« Last Edit: September 23, 2017, 06:44:34 am by parkerc »

Online akbooer

  • Master Member
  • *******
  • Posts: 6041
  • Karma: +263/-69
  • "Less is more"
Re: Multiple commands in HTTP string
« Reply #9 on: September 23, 2017, 06:52:16 am »
For example (and to be confirmed), but theoretically it would allow an external product/service to directly inter act and update variables on Vera via a URL.

No need for Lua code to do that, since there are already Luup HTTP requests to do all that sort of thing...

http://wiki.mios.com/index.php/Luup_Requests#variableset
http://wiki.mios.com/index.php/Luup_Requests#variableget
http://wiki.mios.com/index.php/Luup_Requests#action

...
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2425
  • Karma: +33/-45
  • Life Moves Pretty Fast....
Re: Multiple commands in HTTP string
« Reply #10 on: September 23, 2017, 07:27:56 am »
Agreed, I was thinking with the RunLua url you have a constant prefix to use, for whatever you wanted to do. But I take your point ..