Hi All,
So I have been trying to get a TCPSocket connection to my Anthem receiver using the code below.
Each time I try to connect it returns "connection refused"
The odd thing is - when I go to the Command Prompt on the same laptop I can use telnet using the same details without an issue.
Any ideas?
Thanks
QA Code:
local host = "10.0.0.40"
local port = 14900
function QuickApp:onInit()
self:debug("onInit")
self:connect()
self:debug("onInit - connect()")
end
function QuickApp:onDataReceived(data)
self:debug("onDataReceived")
self:debug("onDataReceived", data)
end
function QuickApp:waitForResponseFunction()
self.sock:read({ -- reading a data package from the socket
success = function(data)
self:onDataReceived(data) -- handling of received data
self:waitForResponseFunction() -- looping of data readout
end,
error = function() -- a function that will be called in case of an error when trying to receive data, e.g. disconnecting a socket
self:debug("response error")
self.sock:close() -- socket closed
--fibaro.setTimeout(5000, function() self:connect() end) -- re-connection attempt (every 5s)
end
})
end
function QuickApp:connect()
self:debug("connect() - HOST: " .. host .. " PORT: " .. port)
self.sock = net.TCPSocket() -- creation of a TCPSocket instance
self:debug("CONNECT() - self.sock = net.TCPSocket()")
self.sock:connect(host, port, { -- connection to the device with the specified IP and port
success = function() -- the function will be triggered if the connection is correct
self:debug("connected")
self:send("SOCKET IS - " , self.sock)
self:waitForResponseFunction() -- launching a data readout "loop"
end,
error = function(err) -- a function that will be triggered in case of an incorrect connection, e.g. timeout
self:debug("connection error:",err)
self.sock:close() -- closing the socket
self:debug("socket closed")
--fibaro.setTimeout(5000, function() self:connect() end) -- re-connection attempt (every 5s)
end,
})
self:debug("connect() - connecting")
end
function QuickApp:onDisconnect()
self:debug("Anthem onDisconnect");
self.sock:close()
end
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: onInit
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: connect() - HOST: 10.0.0.40 PORT: 14900
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: CONNECT() - self.sock = net.TCPSocket()
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: connect() - connecting
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: onInit - connect()
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: connection error: Connection refused
[10.07.2024] [16:21:25] [DEBUG] [QUICKAPP282]: socket closed
C:\Users\anth_>telnet 10.0.0.40 14900
Z1VOL?; is the query and Z1VOL-40; is the response from the amplifier.