@akbooer said in Using luup.call_delay() in the browser code test boxes:
but have forgotten the details of how Vera behaved!
Just to remind you; badly.
OK not surprised I'm going around in circles - I should know better by now. I modified the example code to write to the log, instead of the UI. In Vera, in either Vera's UI or AltUI the log shows:
LuaInterface::CallFunction_Timer-5 function delayTest failed [string "local altui_device = 5..."]:10: bad argument #1 to 'insert' (table expected, got string)
Using AltUI with openLuup, I get similar, where 0x27151d0 is the called function (as printed by the test code):
luup.delay_callback:: function: 0x27151d0 ERROR: [string "RunLua"]:10: bad argument #1 to 'insert' (table expected, got string)
OK so then I test it in one of openLuup's three console test windows (I came across these just recently) and as expected with your code; it all works! I think I figured it had all failed because I never saw the test code printed in the log. Your console test windows just show this, rather than listing the code:
openLuup.server:: POST /data_request?id=XMLHttpRequest&action=submit_lua&codename=LuaTestCode2 HTTP/1.1 tcp{client}: 0x33b3328
So it can be made to work - looks like altUI and Vera UI need to pass the function reference, not the function name string? Or whatever is needed.
Out of interest I have noted that luup.call_delay can use sub one second delays in openLuup as previously mentioned on the Vera forum. I'm unsure if Vera can or can't.
I did some tests and found on a rasPi that occasionally, a one second delay could be well over one second on occasions (have seen two seconds). There could be any number of reasons for this - just measuring the time alone affects the timing (I used socket.gettime()). Plus with different things happening at the same time, it can get weird. But I do have a plugin that runs code every minute and receives/handles a lot of bytes, one by on, via the infamous Vera "'incoming" feature. I should probably rewrite that plugin code one day, if I can rember how it all worked.
There may even be an argument to code a finite reduction in all delays by some fudge factor representing the delay processing time eg say 20 milliseconds but that's getting too pedantic.