We have moved at community.getvera.com

Author Topic: Host a webpage on veralite  (Read 9786 times)

Offline veravance

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Host a webpage on veralite
« on: April 07, 2012, 04:55:41 am »
Good evening,
I'd like to use the push of IPX800 to start a scene vera on a change of state of an entry.
I have a problem because the Path of the IPX can not contain a field as wide as is necessary to start an event of vera via http.
The idea would be to host a page directly on the command that would launch vera http (in this case more problems for the query length html).
Is it possible to use the vera as "webserver" and to host a html page?

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Host a webpage on veralite
« Reply #1 on: April 07, 2012, 06:15:26 am »
You could use http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_register_handler to register a HTML handler that runs your scene.

Offline veravance

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Re: Host a webpage on veralite
« Reply #2 on: April 07, 2012, 09:31:21 am »
Thanks for your answer
how can i use this code ?

luup.register_handler("lug_WapRequest","wap")
 
function lug_WapRequest (lul_request, lul_parameters, lul_outputformat)
    local lul_html = "<head>\n" ..
                     "<title>Main</title>\n" ..
                     "</head>\n" ..
                     "<body>\n" ..
                     "Choose a room:<br/>\n"
    return lul_html
end


I should use the  APPS=>Develop Apps=>Test Luup code (Lua)   to register my page the first time ?



Offline veravance

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Re: Host a webpage on veralite
« Reply #3 on: April 07, 2012, 10:41:28 am »
ok i have found the solution by puting the code in the Startup LUA.
Now i want to execute this command 
http://192.168.0.5:3480/data_request?id=lu_action&output_format=xml&DeviceNum=21&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0

Do you know the syntax to put this command in this code  ?
luup.register_handler("lug_WapRequest","wap")
 
function lug_WapRequest (lul_request, lul_parameters, lul_outputformat)
    local lul_html = "<head>\n" ..
                     "<title>Main</title>\n" ..
                     "</head>\n" ..
                     "<body>\n" ..
                     "Choose a room:<br/>\n"
    return lul_html
end

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Host a webpage on veralite
« Reply #4 on: April 07, 2012, 11:10:42 am »
Something like

Code: [Select]
luup.register_handler( "off21", "off21" )
 
function off21( lul_request, lul_parameters, lul_outputformat )
   local httpStatusCode, content = luup.inet.wget( 'http://192.168.0.5:3480/data_request?id=lu_action&output_format=xml&DeviceNum=21&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0' )
   return httpStatusCode
end

should do the trick (use http://192.168.0.5:3480/data_request?id=lr_off21 to switch off device #21).

An alternative would be to use a scene and to run the scene via RunScene (but the corresponding service id is rather long ...).

Edit:
Bugs corrected (see below).
« Last Edit: April 07, 2012, 06:48:07 pm by Ap15e »

Offline veravance

  • Sr. Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Re: Host a webpage on veralite
« Reply #5 on: April 07, 2012, 01:12:09 pm »
I have got this error  :(
ERROR : Error in lua for scenes and events
when i copy the code in the startup lua

i have already had this kind of error and it was the syntax who was wrong.
I tried delete some space but i didn't find the error ...

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Host a webpage on veralite
« Reply #6 on: April 07, 2012, 06:46:18 pm »
a. Replace all '21off' with 'off21'.
b. The correct URL is: http://192.168.0.5:3480/data_request?id=lr_off21

The handler doesn't survive a LuaUPnP restart, place the code in the 'Edit Startup Lua' window.
« Last Edit: April 07, 2012, 06:50:10 pm by Ap15e »