Help with luup.call_delay()
-
I have this block of lua and I am using luup.call_delay to delay the sending of IR codes. it works as intended but I am trying to eliminate the use of luup.sleep for the delay before the tcp:close() as well. i cant figure out how to implement luup.call_delay() for the tcp:close() and keep the luup.call_delay intact for the delay between the IR codes.
Thanks in advance.
function Delay1() --[[HDMI Matrix B1--]] local socket = require("socket") tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,341,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,21,22,21,22,64,22,21,22,64,22,21,22,21,22,21,22,64,22,64,22,21,22,64,22,21,22,64,22,64,22,64,22,1493,341,85,22,3669" .. "\r\n") luup.sleep(1050) tcp:close() end luup.call_delay("Delay1", 1) function Delay2() --[[HDMI Matrix B2--]] local socket = require("socket") tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,343,171,21,21,22,21,22,21,22,21,21,21,22,21,22,21,21,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,21,21,22,21,22,21,21,22,21,21,22,63,22,21,22,63,22,63,22,63,22,1528,342,85,22,1528" .. "\r\n") luup.sleep(1050) tcp:close() end luup.call_delay("Delay2", 5)
-
I have this block of lua and I am using luup.call_delay to delay the sending of IR codes. it works as intended but I am trying to eliminate the use of luup.sleep for the delay before the tcp:close() as well. i cant figure out how to implement luup.call_delay() for the tcp:close() and keep the luup.call_delay intact for the delay between the IR codes.
Thanks in advance.
function Delay1() --[[HDMI Matrix B1--]] local socket = require("socket") tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,341,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,21,22,21,22,64,22,21,22,64,22,21,22,21,22,21,22,64,22,64,22,21,22,64,22,21,22,64,22,64,22,64,22,1493,341,85,22,3669" .. "\r\n") luup.sleep(1050) tcp:close() end luup.call_delay("Delay1", 1) function Delay2() --[[HDMI Matrix B2--]] local socket = require("socket") tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,343,171,21,21,22,21,22,21,22,21,21,21,22,21,22,21,21,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,21,21,22,21,22,21,21,22,21,21,22,63,22,21,22,63,22,63,22,63,22,1528,342,85,22,1528" .. "\r\n") luup.sleep(1050) tcp:close() end luup.call_delay("Delay2", 5)
You need to create another function which will be run after the delayed time. See the example for your first function below:
local socket = require("socket") function tcpclose(tcp) tcp:close() end function Delay1() --[[HDMI Matrix B1--]] tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,341,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,21,22,21,22,64,22,21,22,64,22,21,22,21,22,21,22,64,22,64,22,21,22,64,22,21,22,64,22,64,22,64,22,1493,341,85,22,3669" .. "\r\n") luup.call_delay("tcpclose", 1050, tcp) end luup.call_delay("Delay1", 1)