Hi, need to controll Epson projector (send PWR On, PWR Off, PWR?) messages
For controllinhg Epson, need to send a command for establishing connection (0x450x530x430x2F0x560x0500x2E0x6E0x650x740x100x030x000x000x000x00) and after that send the command for interogating power status (0x500x570x520x3f0x0d)
Testing this from Hercules utility, works great
When coding in LUA, after sending first command, when trying to send second command I get Connection reset by peer error
If sending just first command, I get a proper response, so, no error in connection or command string
Here is my code:
function QuickApp:onInit()
self:debug("onInit")
self.ip = self:getVariable("ip")
self.port = tonumber(self:getVariable("port"))
self.sock = net.TCPSocket()
end
function QuickApp:parseData(str)
while true do
if string.find(str, '0x') then
i,j = string.find(str, '0x')
str = string.sub(str, 1, i - 1) .. self:fromhex(string.sub(str, i + 2, j +2)) .. string.sub(str, j + 3)
else
return str
end
end
end
function QuickApp:fromhex(str)
return (str:gsub('..', function(cc)
return string.char(tonumber(cc, 16))
end))
end
function QuickApp:connect(successCallback)
print("connecting:", self.ip, self.port)
self.sock:connect(self.ip, self.port, {
success = function()
self:debug("connected")
successCallback()
end,
error = function(err)
self.sock:close()
self:debug("connection error connect", err)
end,
})
end
function QuickApp:init(event)
--self:connect()
self:send("0x450x530x430x2F0x560x0500x2E0x6E0x650x740x100x030x000x000x000x00", true, "0x500x570x520x3f0x0d")
end
function QuickApp:send(dataToSend, waitForResponse, pwr)
self:connect(function()
local dataConverted = self:parseData(dataToSend)
local pwrConverted = self:parseData(pwr)
self.sock:write(dataConverted)
fibaro.setTimeout(1000, function() self.sock:write(pwrConverted) end)
self.sock:read({
success = function(data)
self:debug("response data:", data)
--self.sock:close()
end,
error = function(err)
self:debug("response error wait ", err)
--self.sock:close()
end
})
fibaro.setTimeout(1000, function() self.sock:write(pwrConverted) end)
self.sock:read({
success = function(data)
self:debug("response data:", data)
--self.sock:close()
end,
error = function(err)
self:debug("response error wait ", err)
--self.sock:close()
end
})
end)
end
Looks like the connection is closed after frist call, but do not know how to keep alive, tried everything
Can anybody help me?
Regards