Hello, we are trying to communicate a Sony TV via TCP and we have a document made by sony that explains the protocol we should use. My question is how we can do to make this control via lua scripts, thank you very much.
Thank you very much. It works fine. Now I try to read TV status via Resident Script but doesn't work, I tryied to use the Denon TCP status Scrip from examples but doesn't work.
In Alert page appears Connection Ok and Connection Timeout alternately.
You have to send enquiry command, then you can parse the response to get status info.
Code:
require('socket')
-- bravia IP
ip = '192.168.1.23'
-- power-status
cmd = '*SEPOWR################\n'
sock = socket.tcp()
sock:settimeout(3)
res, err = sock:connect(ip, 20060)
if res then
res, err = sock:send(cmd)
if res then
res, err = sock:receive()
if res then
alert('receive OK: ' .. tostring(res))
else
alert('receive failed: ' .. tostring(err))
end
else
alert('send failed: ' .. tostring(err))
end
else
alert('connect failed: ' .. tostring(err))
end
25.02.2016, 19:53 (This post was last modified: 25.02.2016, 19:58 by josep.)
(25.02.2016, 09:37)admin Wrote: You have to send enquiry command, then you can parse the response to get status info.
Code:
require('socket')
-- bravia IP
ip = '192.168.1.23'
-- power-status
cmd = '*SEPOWR################\n'
sock = socket.tcp()
sock:settimeout(3)
res, err = sock:connect(ip, 20060)
if res then
res, err = sock:send(cmd)
if res then
res, err = sock:receive()
if res then
alert('receive OK: ' .. tostring(res))
else
alert('receive failed: ' .. tostring(err))
end
else
alert('send failed: ' .. tostring(err))
end
else
alert('connect failed: ' .. tostring(err))
end
sock:close()
Hi, I'm trying this but doesn't work. Appears a error like that:
"attempt to call method 'revieve' ( anil value)"
I have two more questions,
first. It's possible to extract volume value from TCP response of TV and convert this value to a KNX 1 byte value?
and the second question, if the tv awnser automactilly the status when you send 'power on', for example, it's possible to read this value without force the status query, and can I read the responses separately by \n?
It works but only when TV is on(not in standby mode). After switching off TV script receive nothing only timeout or connection refused. In documentation there is such info:
"TCP connections are kept among requests but they are disconnected by server if no command is sent from client in 30 seconds."
So I tried sending every 20 seconds ask for power status. But it is not enough.
How can I keep the connection? And also could someone prepare a sample for establishing TCP connection which can receive some info from TV only on event?
Please help me !
I use the code above to turn the TV on and off but it does not work?
My television is sony bravia 79' X900B.
Does anyone know how to turn it off via HTTP?
----------------
require('socket')
ip = '192.168.1.16'
-- power-on =1, off=0
on = '*SCPOWR0000000000000001\n'
off= '*SCPOWR0000000000000000\n' --SCIRCC0000000000000001
sock=socket.tcp()
sockettimeout(1)
a=sock:connect(ip,20060)
if giatri==1 then
b=sockend(on)
alert('send OK')
else
b=sockend(off)
alert('send OK')
end
sock:close()
end
------------------------------------------
function check_tv()
require('socket')
sock=socket.tcp()
sockettimeout(2)
ip = '192.168.1.16'
cmd = '*SEPOWR################\n'
a=sock:connect(ip,52323)
if a==1 then
b=sockend(cmd)
if b==24 then
c=sock:receive()
if c=="*SAPOWR0000000000000001" then
alert("tivi đã bật")
return 1
else
alert("tivi đã tắt")
return 0
end
else
alert("Send failed: ")
end
else
alert("connect failed")
end
sock:close()
end
--------------------
-- IR power off command, must be 24 chars long
cmd = '*SCIRCC0000000000000000\n'
-- power-on
-- cmd = '*SCPOWR0000000000000001\n'
sock = socket.tcp()
sock:settimeout(3)
res, err = sock:connect(ip, 20060)
if res then
res, err = sock:send(cmd)
if res then
alert('send OK')
else
alert('send failed: ' .. tostring(err))
end
else
alert('connect failed: ' .. tostring(err))
end
sock:close()
This Code had an error regarding my Bravia, to turn off.
cmd = '*SCIRCC0000000000000000\n'
do not work at all, i had to replace IRCC with POWR
cmd = '*SCPOWR0000000000000000\n'
That did make it work!