24.02.2016, 09:23
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.
Sony Simple IP Protocol
|
24.02.2016, 09:23
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.
24.02.2016, 11:45
TCP function reference:
http://w3.impa.br/~diego/software/luasocket/tcp.html Basic example: Code: 123456789101112131415161718192021222324252627 require('socket')
-- bravia IP
ip = '192.168.1.23'
-- 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()
24.02.2016, 14:39
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. Thanks
25.02.2016, 09:37
You have to send enquiry command, then you can parse the response to get status info.
Code: 12345678910111213141516171819202122232425262728293031 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()(25.02.2016, 09:37)admin Wrote: You have to send enquiry command, then you can parse the response to get status info. 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? Thank you very much.
22.05.2017, 15:46
Its not work with firewall 4/2017 of sony tv bravia. Can you help me?
08.06.2017, 16:24
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?
14.07.2017, 10:51
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() sock ![]() a=sock:connect(ip,20060) if giatri==1 then b=sock ![]() alert('send OK') else b=sock ![]() alert('send OK') end sock:close() end ------------------------------------------ function check_tv() require('socket') sock=socket.tcp() sock ![]() ip = '192.168.1.16' cmd = '*SEPOWR################\n' a=sock:connect(ip,52323) if a==1 then b=sock ![]() 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 -------------------- Am I wrong? ![]()
17.07.2017, 07:06
Above doesn't work for me, so i used this:
Code: 123 -- tv standby
require('user.sony')
sendCmd('192.168.x.xxx', cmd_OFF) -- define your ipand the library Code: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 --http://www.openremote.org/display/forums/Sony+TV+HTTP+control
--https://www.domoticz.com/forum/viewtopic.php?t=8301
--https://medium.com/@philw_/talking-to-your-sony-bravia-tv-over-http-with-google-now-tasker-xbmc-and-roku-7b71fe634966#.xwswvjd0p
-- wol(mac, ip, '60', port) --mac = '00:a0:96:7c:76:dd'
require('socket')
port = 80
--command
cmd_HDMI1 = 'AAAAAgAAABoAAABaAw=='
cmd_CH6 = 'AAAAAQAAAAEAAAAFAw=='
cmd_MUTE = 'AAAAAQAAAAEAAAAUAw=='
cmd_OFF = 'AAAAAQAAAAEAAAAvAw=='
function sendCmd(ip, ircmd)
soap = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1"><IRCCCode>'..ircmd..'</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>'
-- http request
reqs = 'POST /IRCC HTTP/1.1\r\n' ..
'CONNECTION: close\r\n' ..
'HOST: ' .. ip .. ':' .. port .. '\r\n' ..
'CONTENT-LENGTH: ' .. soap:len() .. '\r\n' ..
'CONTENT-TYPE: text/xml; charset="utf-8"\r\n' ..
'\r\n' .. soap
sock = socket.tcp()
sock:settimeout(3)
res, err = sock:connect(ip, port)
if res then
res, err = sock:send(reqs)
if res then
--log('send OK')
else
--log('send failed: ' .. tostring(err))
end
else
--log('connect failed: ' .. tostring(err))
end
sock:close()
end
13.07.2018, 07:04
Code: 123456789101112131415161718192021222324252627 require('socket')
-- bravia IP
ip = '192.168.1.23'
-- 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! |
« Next Oldest | Next Newest »
|