Vera devices support the ability to register a handler that will be called when a certain URL is requested from the Vera device through HTTP protocol. You can register a (callback) function using register_handler Luup function call.

For example, the call luup.register_handler("room_request", "room") registers a callback function room_request that will be called when a request with id=lr_[registered_name] is triggered using data_request?id=lr_room URL.

The callback function gets request, parameters, and outputformat as parameters and returns the response with an optional content type.

Debugging Lua code in a request (register_handler) callback

The IDE provides two methods to debug Lua code for events triggered from the Vera device: scenes, plugins, watch, request, and others.

In this example we will be using the simpler method that doesn’t require specifying the IP address of the computer that runs the IDE:

  • Open a new editor tab in the IDE, add the following code and save it in a file.
function room_request (lul_request, lul_parameters, lul_outputformat)
  require('mobdebug').start() --<-- start debugging
  local lul_html =
    "<head><title>Main</title></head><body>" ..
    "Choose a room:</body>"
  require('mobdebug').done() --<-- stop debugging
  return lul_html, "text/html"
end
luup.register_handler("room_request", "room")
  • Start debugging in the IDE by selecting Project | Start Debugging and then run the script using Project | Continue.

  • Point your browser to the URL that sends “room” request. Make sure to change the IP address to the address of your Vera device.

You should now see the debugging suspended at the lul_html assignment line. You can then step through the code (and will see the values printed to the output window), inspect variables, and use other debugging functions.

This method only works until the Luup engine is restarted (and in some cases it can be restarted by the Vera device without warning). If you can’t get the debugging started in the IDE, try running the second step one more time.

brilliant. Well worth the investment. (JoeyD)

Using ZeroBrane is a breath of fresh air! I've gained more ground on the plug-in the past few hours than I had in the previous week. I attribute that to auto-completion and the ability to debug remotely; seldom ever leaving the IDE. (aechelon)

You ROCK!!! I'm simply amazed that this worked! I didn't expect to be able to debug [register_handler and variable_watch] event types! (Shawn C)

works really well... should be very helpful to people starting-out with Lua/Luup programming for Vera scenes and plugins. (RexBeckett)

Love the debugger, saving my life. (Troy Sandal)

I have been programming computers for about 35 years and I don't think I have ever seen an environment that is easier to get started with. (Adrian)

ZeroBrane Studio has got a working debugger, full IDE feature set, small footprint, and is completely customizable in lua. (Jonathan Shieh)