Return large variable arrays as JSON

I’m wanting to pass a set of parameters from the GUI to a Lua plugin, and return a set of data - preferably as a JSON array. Is it possible to have a variable handler in Lua that can process such a request rather than using the variable_set function and letting Vera handle the request? Alternatively, is there a better way to return large(ish) data sets to the GUI?

— Edit —
I’ve just come across luup.register_handler() which seems like it might be of use… I’ll have a play with this later.

Thanks.

Chris

luup.register_handler() totally works. I found out about it a week ago, and it’s already being used in rev 35 of the Caddx alarm plugin. You can go look at it for sample code, if you like.

Some limitations:

I don’t think you can set the MIME type or add any response headers, which means that this won’t work for “download file” buttons in your browser.

You can use the registered handler URL to pass parameters into Lua from the HTTP request, but only GET seems to work; you can’t POST. (Edit: wording changed for clarity.)

Registered handlers aren’t namespaced, so I think we developers need to cooperate on some kind of handler naming system so we don’t step on each others’ toes.

Thanks futzle,
I’ve been playing with this this morning, and haven’t yet managed to get it to work in my code. I’ve got the phone plugin installed, and can make that work and have also managed to extract a lot of interesting stuff out of Vera as JSON :slight_smile:

I’ll take a look at your code - I think my problem may be function scope, but I’ve referenced it in the I_.XML file (as I’ve done for other callbacks). In the log I just get JobHandler_LuaUPnP::REQ_Handler no handler for lr_myHandler.

Cheers
Chris