I wrote this lua script to process TV channel processing, basically, it takes a string e.g. 7.1xxxxx and passed to multistring and splits the characters into individual variables which are then evaluated with an IF conditional which fires an infrared signal command when true. I found the x’s are needed as place holders since there are 6 variables to accommodate a channel such as 102.1 and none of the variables get populated if the string at least 6 characters. Reactor triggers the script on a value change on the multi-string variable and I have tried to run the lua in both reactor and passing it off to luup using a native UI7 scene.
It works well, however, I will get and intermittent luup restart every now and then, enough to be a problem. I am a novice at lua so put this together with trial and error. I have no idea is there is a better or more efficient way. I have read in the past that using luup sleep is not a great idea but I need a delay so the IR signals dont step on each other.
I guess at this point I am trying to get to the bottom of the luup restarts.
Script is as follows:
local channel, ts = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable1", 477)
d1, d2, d3, d4, d5, d6 = channel:match("(.)(.)(.)(.)(.)(.)")
if (d1=="1") then
--[[Sony Digit 1----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1125" .. "\r\n")
end
if (d1=="2") then
--[[Sony Digit 2----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d1=="3") then
--[[Sony Digit 3----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d1=="4") then
--[[Sony Digit 4----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d1=="5") then
--[[Sony Digit 5----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d1=="6") then
--[[Sony Digit 6----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d1=="7") then
--[[Sony Digit 7----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d1=="8") then
--[[Sony Digit 8----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1035" .. "\r\n")
end
if (d1=="9") then
--[[Sony Digit 9----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d1=="0") then
--[[Sony Digit 0----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
luup.sleep(1500)
if (d2==".") then
--[[Sony Digit Separator----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,48,24,48,24,24,24,24,24,48,24,48,24,48,24,24,24,48,24,24,24,24,24,48,770" .. "\r\n")
end
if (d2=="1") then
--[[Sony Digit 1----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1125" .. "\r\n")
end
if (d2=="2") then
--[[Sony Digit 2----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d2=="3") then
--[[Sony Digit 3----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d2=="4") then
--[[Sony Digit 4----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d2=="5") then
--[[Sony Digit 5----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d2=="6") then
--[[Sony Digit 6----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d2=="7") then
--[[Sony Digit 7----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d2=="8") then
--[[Sony Digit 8----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1035" .. "\r\n")
end
if (d2=="9") then
--[[Sony Digit 9----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d2=="0") then
--[[Sony Digit 0----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
luup.sleep(1500)
if (d3=="x") then
tcp:close()
return
end
if (d3==".") then
--[[Sony Digit Separator----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,48,24,48,24,24,24,24,24,48,24,48,24,48,24,24,24,48,24,24,24,24,24,48,770" .. "\r\n")
end
if (d3=="1") then
--[[Sony Digit 1----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1125" .. "\r\n")
end
if (d3=="2") then
--[[Sony Digit 2----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d3=="3") then
--[[Sony Digit 3----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d3=="4") then
--[[Sony Digit 4----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d3=="5") then
--[[Sony Digit 5----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d3=="6") then
--[[Sony Digit 6----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d3=="7") then
--[[Sony Digit 7----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d3=="8") then
--[[Sony Digit 8----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1035" .. "\r\n")
end
if (d3=="9") then
--[[Sony Digit 9----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d3=="0") then
--[[Sony Digit 0----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
luup.sleep(1500)
if (d4=="x") then
tcp:close()
return
end
if (d4==".") then
--[[Sony Digit Separator----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,48,24,48,24,24,24,24,24,48,24,48,24,48,24,24,24,48,24,24,24,24,24,48,770" .. "\r\n")
end
if (d4=="1") then
--[[Sony Digit 1----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1125" .. "\r\n")
end
if (d4=="2") then
--[[Sony Digit 2----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d4=="3") then
--[[Sony Digit 3----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d4=="4") then
--[[Sony Digit 4----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d4=="5") then
--[[Sony Digit 5----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d4=="6") then
--[[Sony Digit 6----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d4=="7") then
--[[Sony Digit 7----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d4=="8") then
--[[Sony Digit 8----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1035" .. "\r\n")
end
if (d4=="9") then
--[[Sony Digit 9----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d4=="0") then
--[[Sony Digit 0----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
luup.sleep(1500)
if (d5=="x") then
tcp:close()
return
end
if (d5=="1") then
--[[Sony Digit 1----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1125" .. "\r\n")
end
if (d5=="2") then
--[[Sony Digit 2----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d5=="3") then
--[[Sony Digit 3----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d5=="4") then
--[[Sony Digit 4----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d5=="5") then
--[[Sony Digit 5----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d5=="6") then
--[[Sony Digit 6----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d5=="7") then
--[[Sony Digit 7----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d5=="8") then
--[[Sony Digit 8----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1035" .. "\r\n")
end
if (d5=="9") then
--[[Sony Digit 9----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d5=="0") then
--[[Sony Digit 0----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
luup.sleep(1500)
if (d6=="x") then
tcp:close()
return
end
if (d6=="1") then
--[[Sony Digit 1----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1125" .. "\r\n")
end
if (d6=="2") then
--[[Sony Digit 2----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,24,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d6=="3") then
--[[Sony Digit 3----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,24,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d6=="4") then
--[[Sony Digit 4----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,97,24,48,24,48,24,24,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d6=="5") then
--[[Sony Digit 5----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d6=="6") then
--[[Sony Digit 6----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d6=="7") then
--[[Sony Digit 7----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
if (d6=="8") then
--[[Sony Digit 8----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,48,24,48,24,24,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1035" .. "\r\n")
end
if (d6=="9") then
--[[Sony Digit 9----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1080" .. "\r\n")
end
if (d6=="0") then
--[[Sony Digit 0----]]
local socket = require("socket")
tcp = assert(socket.connect("192.168.255.204", 4998))
tcp:send("sendir,1:3,1,40000,3,1,96,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1058" .. "\r\n")
end
luup.sleep(1500)
tcp:close()