The latest openLuup development release has a new file in the openLuup/ folder: http_async.lua.
This now implements asynchronous HTTP and HTTPS requests (depending on which scheme is provided in the requested URL.) If you want to use it, you simply require it in your code like this:
local async = require "http_async"
It exports a single function require which works exactly as described earlier in this thread: openLuup: Asynchronous I/O - #6 by akbooer - openLuup - Ezlo Community (except for a change of name.)
For example:
local ok, err = async.request ("simple URL", "body of POST", myCallback)
I will be withdrawing the original openLuup syntax to call this function (luup.openLuup.async_request) in order to make any plugin which uses this transportable to Vera, since this new module can be copied to Vera and used in exactly the same way there.
I have done limited testing in Vera (quite amusing in the test window, because the function returns before the response arrives, so your callback routine needs to write to the log if you want to see the result!)
Example test code:
local async = require "http_async"
local ltn12 = require "ltn12"
local response_table = {}
local function request_callback (response, code, headers, statusline)
luup.log ("CALLBACK status code: " .. (code or '?'))
luup.log ("CALLBACK output length: " .. #table.concat (response_table))
end
local ok, err = async.request ({
url = "https://api.github.com/repos/akbooer/openLuup/contents",
sink = ltn12.sink.table (response_table),
protocol = "tlsv1_2",
}, request_callback)
print (ok, err or "all OK")
Giving this log output (you have to rush to the AltUI Misc > OsCommand page and tail the log)
50 05/11/19 12:56:53.317 luup_log:0: ALTUI: Evaluation of lua code returned: nil <0x7445d520>
50 05/11/19 12:56:54.107 luup_log:0: CALLBACK status code: 200 <0x7565d520>
50 05/11/19 12:56:54.107 luup_log:0: CALLBACK output length: 7421 <0x7565d520>
Huge thanks to @amg0 for suggesting that this module could be adapted to be used on Vera.