This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Sony Simple IP Protocol
#1
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.

Attached Files
.pdf   Steuerungsprotokoll_1.pdf (Size: 239.61 KB / Downloads: 126)
Reply
#2
TCP function reference:
http://w3.impa.br/~diego/software/luasocket/tcp.html

Basic example:
Code:
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()
Reply
#3
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
Reply
#4
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()
Reply
#5
(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?

Thank you very much.
Reply
#6
Its not work with firewall 4/2017 of sony tv bravia. Can you help me?
Reply
#7
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?
Reply
#8
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()
sockConfusedettimeout(1)
a=sock:connect(ip,20060)
if giatri==1 then
b=sockConfusedend(on)
alert('send OK')
else
b=sockConfusedend(off)
alert('send OK')
end
sock:close()
end
------------------------------------------
function check_tv()
require('socket')
sock=socket.tcp()
sockConfusedettimeout(2)
ip = '192.168.1.16'
cmd = '*SEPOWR################\n'
a=sock:connect(ip,52323)
if a==1 then
b=sockConfusedend(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
--------------------

Am I wrong?
Sad....
Reply
#9
Above doesn't work for me, so i used this:

Code:
-- tv standby
require('user.sony')
sendCmd('192.168.x.xxx', cmd_OFF) -- define your ip

and the library
Code:
--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
Reply
#10
Code:
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!
Reply


Forum Jump: