Author Topic: Sony TV REST API  (Read 5538 times)

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Sony TV REST API
« on: February 27, 2016, 04:14:09 pm »
So this has been bought over here from the "what did you do with your vera today" thread as think I was annoying a few people over there.. but cybrmage was helping me out - so hopefully he will find me here...

I have a curl script which works but want to get into a function
Code: [Select]
curl --silent -XPOST http://192.168.1.xxx/sony/IRCC -d "<?xml version=\"1.0\"?><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>"AAAAAQAAAAEAAAATAw=="</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' -H "Cookie: auth=xxx" -o /dev/null

I have updated the URL in the below as with the original reccomendation i got a 404 and the url below is the one i use in a curl scripts which works


so essentially I want to send commands from my vera to my Sony Bravia 2015 android tv.
Code: [Select]
local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local SONY_IP = "192.168.1.225"
local AUTH_CODE = "75071BA72588155AD9FABC47EBDD353BA4ED40D7"
local IRCC_CODE = "AAAAAQAAAAEAAAAUAw=="
local REQUEST = "<?xml version=\"1.0\"?><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>"
REQUEST=REQUEST .. IRCC_CODE
REQUEST = REQUEST.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"
local SONY_URL = "http://"..SONY_IP.."/local_api.php?getDeviceList=true"

rBody, rCode, rHeaders, rStatus = http.request(
{
method = "POST",
url = SONY_URL,
headers = {
["Content-Type"] = "text/xml; charset=UTF-8",
["SOAPACTION"] = "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC",
["Cookie"] = "auth="..AUTH_CODE
},
source = ltn12.source.string(REQUEST),
sink = ltn12.sink.table(respBody),
redirect = false
}
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")

i get the following in the log

Code: [Select]
0 02/27/16 21:19:12.518 luup_log:0: http response - code [500] html [

    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 
   
      s:Client
      UPnPError
     
       
          401
          Invalid Action
       
     
   
 
] <0x71dd2520>
04 02/27/16 21:19:20.209 <0x769d2520>
02 02/27/16 21:19:20.209 Device_Basic::AddPoll 10 poll list ful
« Last Edit: February 27, 2016, 04:30:23 pm by trouty00 »

Offline cybrmage

  • Hero Member
  • *****
  • Posts: 1002
  • Karma: +96/-5
Re: Sony TV REST API
« Reply #1 on: February 28, 2016, 01:33:10 pm »
I have updated the URL in the below as with the original reccomendation i got a 404 and the url below is the one i use in a curl scripts which works

The URL in the script is the original URL from your original request...

You need to update it to point to the IRCC endpoint (the current URL points to a UPnP endpoint)

Also, I'm not sure about the auth header... A quick search shows it should be "X-Auth-PSK", not "Cookie". And, looking at the code I wrote for my Samsung TV (which also uses SOAP), the SOAP requests may need more headers (which may have been automatically added by curl command from the command prompt)...




Try:
Code: [Select]
local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local SONY_IP = "192.168.1.225"
local AUTH_CODE = "75071BA72588155AD9FABC47EBDD353BA4ED40D7"
local IRCC_CODE = "AAAAAQAAAAEAAAAUAw=="
local REQUEST = "<?xml version=\"1.0\"?><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>"..IRCC_CODE.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"

rBody, rCode, rHeaders, rStatus = http.request(
{
method = "POST",
url = SONY_URL,
headers = {
["Host"] = SONY_IP,
["Content-Type"] = "text/xml; charset=\"UTF-8\"0",
["Content-Length"] = tostring(#REQUEST)
["SOAPACTION"] = "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC",
["X-Auth-PSK"] = AUTH_CODE,
["Cookie"] = "auth="..AUTH_CODE
},
source = ltn12.source.string(REQUEST),
sink = ltn12.sink.table(respBody),
redirect = false
}
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")
« Last Edit: February 28, 2016, 01:36:20 pm by cybrmage »
EVL3Vista - Wink Connect - Caseta Connect - Venstar Colortouch - WiFi UDP Switch Controller - MyQGateway

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Re: Sony TV REST API
« Reply #2 on: February 28, 2016, 03:37:35 pm »
hmmm, the auth code seems to be a mix between the type of tv. running from curl it works fine with the cookie but never the PSK (pre shared key version)


tried with both as per below commenting out each option and  still no joy.

Code: [Select]
local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local SONY_IP = "192.168.1.225"
local AUTH_CODE1 = "1111"
local AUTH_CODE = "75071BA72588155AD9FABC47EBDD353BA4ED40D7"
local IRCC_CODE = "AAAAAQAAAAEAAAAUAw=="
local REQUEST = "<?xml version=\"1.0\"?><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>"..IRCC_CODE.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"

rBody, rCode, rHeaders, rStatus = http.request(
{
method = "POST",
url = SONY_URL,
headers = {
["Host"] = SONY_IP,
["Content-Type"] = "text/xml; charset=\"UTF-8\"0",
["Content-Length"] = tostring(#REQUEST),
["SOAPACTION"] = "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC",
["X-Auth-PSK"] = AUTH_CODE1,
--["Cookie"] = "auth="..AUTH_CODE
},
source = ltn12.source.string(REQUEST),
sink = ltn12.sink.table(respBody),
redirect = false
}
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")
always see the same error in the log
Code: [Select]
50 02/28/16 20:23:03.974 luup_log:0: http response - code [500] html [

    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 
   
      s:Client
      UPnPError
     
       
          401
          Invalid Action
       
     
   
 
] <0x70f85520>

edit-- so seems like an authorization issue. I have actually just got the PSK to work via curl but it is passed in a different way
Code: [Select]
-H "X-Auth-PSK:1111"  vs 
-H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"'

i dont really understand the construct here but guessing is it something to do with the x-auth not being a defined something or other and just need to send the whole thing as a header - sorry if im not making sense, i made an observation and am guessing..

« Last Edit: February 28, 2016, 04:04:49 pm by trouty00 »

Offline Brientim

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2494
  • Karma: +77/-7
Re: Sony TV REST API
« Reply #3 on: February 28, 2016, 03:47:05 pm »
They was some previous comments a while ago which eluded to another forum.

https://www.domoticz.com/forum/viewtopic.php?t=8301

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Re: Sony TV REST API
« Reply #4 on: February 28, 2016, 04:07:30 pm »
yeah i saw all this but they just seem to be sending the curl command - i know im close with this, just this slight issue need to get past..

Offline cybrmage

  • Hero Member
  • *****
  • Posts: 1002
  • Karma: +96/-5
Re: Sony TV REST API
« Reply #5 on: February 28, 2016, 06:01:22 pm »
yeah i saw all this but they just seem to be sending the curl command - i know im close with this, just this slight issue need to get past..

Ok... so... The curl command work.... Modify the curl command... change "--silent" to "-v -v",run the command and post the output... It should show exactly what is going on with the curl command and we can see how it differs from the http.request...
EVL3Vista - Wink Connect - Caseta Connect - Venstar Colortouch - WiFi UDP Switch Controller - MyQGateway

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Re: Sony TV REST API
« Reply #6 on: February 29, 2016, 09:52:20 am »
here we are

Code: [Select]
curl -v -v -XPOST http://192.168.1.225/sony/IRCC -H "X-Auth-PSK:11
11" -d "<?xml version=\"1.0\"?><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>"
AAAAAQAAAAEAAAAUAw=="</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Conte
nt-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:
IRCC:1#X_SendIRCC"'
* About to connect() to 192.168.1.225 port 80 (#0)
*   Trying 192.168.1.225...
* Adding handle: conn: 0x50570
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x50570) send_pipe: 1, recv_pipe: 0
* Connected to 192.168.1.225 (192.168.1.225) port 80 (#0)
> POST /sony/IRCC HTTP/1.1
> User-Agent: curl/7.32.0
> Host: 192.168.1.225
> Accept: */*
> X-Auth-PSK:1111
> Content-Type: text/xml; charset=UTF-8
> SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"
> Content-Length: 291
>
* upload completely sent off: 291 out of 291 bytes
< HTTP/1.1 200 OK
< Content-Type: text/xml; charset="utf-8"
< Content-Length: 292
< Connection: keep-alive
< Date: Mon, 29 Feb 2016 14:51:30 GMT+00:00
< Ext:
* Server Android/5.1.1 UPnP/1.0 IRCC/1.0 is not blacklisted
< Server: Android/5.1.1 UPnP/1.0 IRCC/1.0
<
<?xml version="1.0"?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:X_SendIRCCResponse xmlns:u="urn:schemas-sony-com:service:IRCC:1">
    </u:X_SendIRCCResponse>
  </s:Body>
* Connection #0 to host 192.168.1.225 left intact

Offline cybrmage

  • Hero Member
  • *****
  • Posts: 1002
  • Karma: +96/-5
Re: Sony TV REST API
« Reply #7 on: February 29, 2016, 12:04:02 pm »
Code: [Select]

local SONY_IP = "192.168.1.225"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "1111"
local IRCC_CODE = "AAAAAQAAAAEAAAAUAw=="

local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local REQUEST = "<?xml version=\"1.0\"?><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\">\"".. IRCC_CODE .. "\"</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"

rBody, rCode, rHeaders, rStatus = http.request(
{
method = "POST",
url = SONY_URL,
headers = {
["User-Agent"] = "curl/7.32.0",
["Host"] = SONY_IP,
["Accept"] = "*/*",
["X-Auth-PSK"] = AUTH_CODE,
["Content-Type"] = "text/xml; charset=UTF-8",
["Content-Length"] = tostring(#REQUEST),
["SOAPACTION"] = "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\""
},
source = ltn12.source.string(REQUEST),
sink = ltn12.sink.table(respBody),
redirect = false
}
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")

« Last Edit: February 29, 2016, 12:09:20 pm by cybrmage »
EVL3Vista - Wink Connect - Caseta Connect - Venstar Colortouch - WiFi UDP Switch Controller - MyQGateway

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Re: Sony TV REST API
« Reply #8 on: February 29, 2016, 02:25:45 pm »
still getting the same error  ??? ???

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Re: Sony TV REST API
« Reply #9 on: March 04, 2016, 02:33:32 pm »
gave up in the end and am just using os.execute
Code: [Select]
os.execute([[curl --silent -XPOST http://ip.ip.ip.ip/sony/IRCC -H "X-Auth-PSK:****" -d "<?xml version=\"1.0\"?><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>"AAAAAQAAAAEAAAAvAw=="</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"']])

Offline asdf1nit

  • Newbie
  • *
  • Posts: 14
  • Karma: +2/-0
Re: Sony TV REST API
« Reply #10 on: February 09, 2017, 08:30:26 pm »
I wanted to do the same thing and make a plugin and found this. Did you ever get any farther with it? I'm going to play around with this and see what I can do but I haven't worked on the vera or with lua before so it'll be a learning experience. I Have read all the forum post both here and for other HA platforms about doing this and even have the python and bash versions working but I really want this as a plugin to the vera.

Offline asdf1nit

  • Newbie
  • *
  • Posts: 14
  • Karma: +2/-0
Re: Sony TV REST API
« Reply #11 on: February 09, 2017, 10:43:18 pm »
Ok it works. There were a couple errors in the local REQUEST string. I'm going to play with this some more and try to figure out a gui and get a plugin hammered out. It'll probably take me a little while but this function was the meat of the whole thing so thank you @trouty00 and @cybrmage for you work. I would have taken me a long while to figure that out(I couldn't find any documentation on sending soap request).


Code: [Select]
local SONY_IP = "10.0.1.5"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "2020"
local IRCC = "AAAAAQAAAAEAAAAuAw=="

local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local REQUEST = "<?xml version=\"1.0\"?><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>"..IRCC.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"

rBody, rCode, rHeaders, rStatus = http.request(
{
method = "POST",
url = SONY_URL,
headers = {
["User-Agent"] = "curl/7.38.0",
["Host"] = SONY_IP,
["Accept"] = "*/*",
["X-Auth-PSK"] = AUTH_CODE,
["Content-Type"] = "text/xml; charset=UTF-8",
["Content-Length"] = tostring(#REQUEST),
["SOAPACTION"] = "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\""
},
source = ltn12.source.string(REQUEST),
sink = ltn12.sink.table(respBody),
redirect = false
}
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")

And here's the LuaUpnp.log output
 
Code: [Select]
08      02/09/17 21:49:39.922   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x71e00520>
08      02/09/17 21:49:39.922   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x71e00520>
08      02/09/17 21:49:39.922   JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x71e00520>
08      02/09/17 21:49:39.923   JobHandler_LuaUPnP::HandleActionRequest argument Code=local SONY_IP = "10.0.1.5"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "2020"
local IRCC = "AAAAAQAAAAEAAAAuAw=="

local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local REQUEST = "<?xml version=\"1.0\"?><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>"..IRCC.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"

rBody, rCode, rHeaders, rStatus = http.request(
        {
                method = "POST",
                url = SONY_URL,
                headers = {
                        ["User-Agent"] = "curl/7.38.0",
                        ["Host"] = SONY_IP,
                        ["Accept"] = "*/*",
                        ["X-Auth-PSK"] = AUTH_CODE,
                        ["Content-Type"] = "text/xml; charset=UTF-8",
                        ["Content-Length"] = tostring(#REQUEST),
                        ["SOAPACTION"] = "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\""
                },
                source = ltn12.source.string(REQUEST),
                sink = ltn12.sink.table(respBody),
                redirect = false
        }
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]") <0x71e00520>
50      02/09/17 21:49:39.938   luup_log:0: http response - code [200] html [<?xml version="1.0"?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:X_SendIRCCResponse xmlns:u="urn:schemas-sony-com:service:IRCC:1">
    </u:X_SendIRCCResponse>
  </s:Body>
</s:Envelope>] <0x71e00520>
« Last Edit: February 09, 2017, 10:52:39 pm by asdf1nit »

Offline asdf1nit

  • Newbie
  • *
  • Posts: 14
  • Karma: +2/-0
Re: Sony TV REST API
« Reply #12 on: February 10, 2017, 12:38:33 am »
And Just to make it easy to send commands
Code: [Select]
command = {
PowerOff="AAAAAQAAAAEAAAAvAw==",
["PowerOn"]="AAAAAQAAAAEAAAAuAw==",
["VolumeUp"]="AAAAAQAAAAEAAAASAw==",
["VolumeDown"]="AAAAAQAAAAEAAAATAw==",
["Mute"]="AAAAAQAAAAEAAAAUAw==",
["Input"]="AAAAAQAAAAEAAAAlAw==",
["GGuide"]="AAAAAQAAAAEAAAAOAw==",
["EPG"]="AAAAAgAAAKQAAABbAw==",
["Favorites"]="AAAAAgAAAHcAAAB2Aw==",
["Display"]="AAAAAQAAAAEAAAA6Aw==",
["Home"]="AAAAAQAAAAEAAABgAw==",
["Options"]="AAAAAgAAAJcAAAA2Aw==",
["Return"]="AAAAAgAAAJcAAAAjAw==",
["Up"]="AAAAAQAAAAEAAAB0Aw==",
["Down"]="AAAAAQAAAAEAAAB1Aw==",
["Right"]="AAAAAQAAAAEAAAAzAw==",
["Left"]="AAAAAQAAAAEAAAA0Aw==",
["Confirm"]="AAAAAQAAAAEAAABlAw==",
["Red"]="AAAAAgAAAJcAAAAlAw==",
["Green"]="AAAAAgAAAJcAAAAmAw==",
["Yellow"]="AAAAAgAAAJcAAAAnAw==",
["Blue"]="AAAAAgAAAJcAAAAkAw==",
["Num1"]="AAAAAQAAAAEAAAAAAw==",
["Num2"]="AAAAAQAAAAEAAAABAw==",
["Num3"]="AAAAAQAAAAEAAAACAw==",
["Num4"]="AAAAAQAAAAEAAAADAw==",
["Num5"]="AAAAAQAAAAEAAAAEAw==",
["Num6"]="AAAAAQAAAAEAAAAFAw==",
["Num7"]="AAAAAQAAAAEAAAAGAw==",
["Num8"]="AAAAAQAAAAEAAAAHAw==",
["Num9"]="AAAAAQAAAAEAAAAIAw==",
["Num0"]="AAAAAQAAAAEAAAAJAw==",
["Num11"]="AAAAAQAAAAEAAAAKAw==",
["Num12"]="AAAAAQAAAAEAAAALAw==",
["Tv"]="AAAAAQAAAAEAAAAkAw==",
["Hdmi1"]="AAAAAgAAABoAAABaAw==",
["Hdmi2"]="AAAAAgAAABoAAABbAw==",
["Hdmi3"]="AAAAAgAAABoAAABcAw==",
["Hdmi4"]="AAAAAgAAABoAAABdAw==",
["Google"]="AAAAAgAAAMQAAAA7Aw==",
["ActionMenu"]="AAAAAgAAAMQAAABLAw==",
["ChannelUp"]="AAAAAQAAAAEAAAAQAw==",
["ChannelDown"]="AAAAAQAAAAEAAAARAw==",
["SubTitle"]="AAAAAgAAAJcAAAAoAw==",
["ClosedCaption"]="AAAAAgAAAKQAAAAQAw==",
["Enter"]="AAAAAQAAAAEAAAALAw==",
["DOT"]="AAAAAgAAAJcAAAAdAw==",
["Analog"]="AAAAAgAAAHcAAAANAw==",
["Teletext"]="AAAAAQAAAAEAAAA/Aw==",
["Exit"]="AAAAAQAAAAEAAABjAw==",
["Analog2"]="AAAAAQAAAAEAAAA4Aw==",
["AD"]="AAAAAgAAABoAAAA7Aw==",
["Digital"]="AAAAAgAAAJcAAAAyAw==",
["Analog"]="AAAAAgAAAJcAAAAuAw==",
["BS"]="AAAAAgAAAJcAAAAsAw==",
["CS"]="AAAAAgAAAJcAAAArAw==",
["BSCS"]="AAAAAgAAAJcAAAAQAw==",
["Ddata"]="AAAAAgAAAJcAAAAVAw==",
["PicOff"]="AAAAAQAAAAEAAAA+Aw==",
["Tv_Radio"]="AAAAAgAAABoAAABXAw==",
["Theater"]="AAAAAgAAAHcAAABgAw==",
["SEN"]="AAAAAgAAABoAAAB9Aw==",
["InternetWidgets"]="AAAAAgAAABoAAAB6Aw==",
["InternetVideo"]="AAAAAgAAABoAAAB5Aw==",
["Netflix"]="AAAAAgAAABoAAAB8Aw==",
["SceneSelect"]="AAAAAgAAABoAAAB4Aw==",
["Mode3D"]="AAAAAgAAAHcAAABNAw==",
["iManual"]="AAAAAgAAABoAAAB7Aw==",
["Audio"]="AAAAAQAAAAEAAAAXAw==",
["Wide"]="AAAAAgAAAKQAAAA9Aw==",
["Jump"]="AAAAAQAAAAEAAAA7Aw==",
["PAP"]="AAAAAgAAAKQAAAB3Aw==",
["MyEPG"]="AAAAAgAAAHcAAABrAw==",
["ProgramDescription"]="AAAAAgAAAJcAAAAWAw==",
["WriteChapter"]="AAAAAgAAAHcAAABsAw==",
["TrackID"]="AAAAAgAAABoAAAB+Aw==",
["TenKey"]="AAAAAgAAAJcAAAAMAw==",
["AppliCast"]="AAAAAgAAABoAAABvAw==",
["acTVila"]="AAAAAgAAABoAAAByAw==",
["DeleteVideo"]="AAAAAgAAAHcAAAAfAw==",
["PhotoFrame"]="AAAAAgAAABoAAABVAw==",
["TvPause"]="AAAAAgAAABoAAABnAw==",
["KeyPad"]="AAAAAgAAABoAAAB1Aw==",
["Media"]="AAAAAgAAAJcAAAA4Aw==",
["SyncMenu"]="AAAAAgAAABoAAABYAw==",
["Forward"]="AAAAAgAAAJcAAAAcAw==",
["Play"]="AAAAAgAAAJcAAAAaAw==",
["Rewind"]="AAAAAgAAAJcAAAAbAw==",
["Prev"]="AAAAAgAAAJcAAAA8Aw==",
["Stop"]="AAAAAgAAAJcAAAAYAw==",
["Next"]="AAAAAgAAAJcAAAA9Aw==",
["Rec"]="AAAAAgAAAJcAAAAgAw==",
["Pause"]="AAAAAgAAAJcAAAAZAw==",
["Eject"]="AAAAAgAAAJcAAABIAw==",
["FlashPlus"]="AAAAAgAAAJcAAAB4Aw==",
["FlashMinus"]="AAAAAgAAAJcAAAB5Aw==",
["TopMenu"]="AAAAAgAAABoAAABgAw==",
["PopUpMenu"]="AAAAAgAAABoAAABhAw==",
["RakurakuStart"]="AAAAAgAAAHcAAABqAw==",
["OneTouchTimeRec"]="AAAAAgAAABoAAABkAw==",
["OneTouchView"]="AAAAAgAAABoAAABlAw==",
["OneTouchRec"]="AAAAAgAAABoAAABiAw==",
["OneTouchStop"]="AAAAAgAAABoAAABjAw==",
["DUX"]="AAAAAgAAABoAAABzAw==",
["FootballMode"]="AAAAAgAAABoAAAB2Aw==",
["Social"]="AAAAAgAAABoAAAB0Aw=="}


function SendCommand(Command)
local SONY_IP = "10.0.1.5"
local SONY_URL = "http://"..SONY_IP.."/sony/IRCC"
local AUTH_CODE = "2020"
local http = require("socket.http")
local ltn12 = require("ltn12")
local respBody = {}
local REQUEST = "<?xml version=\"1.0\"?><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>"..Command.."</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"

rBody, rCode, rHeaders, rStatus = http.request(
{
method = "POST",
url = SONY_URL,
headers = {
["User-Agent"] = "curl/7.38.0",
["Host"] = SONY_IP,
["Accept"] = "*/*",
["X-Auth-PSK"] = AUTH_CODE,
["Content-Type"] = "text/xml; charset=UTF-8",
["Content-Length"] = tostring(#REQUEST),
["SOAPACTION"] = "\"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC\""
},
source = ltn12.source.string(REQUEST),
sink = ltn12.sink.table(respBody),
redirect = false
}
)
luup.log("http response - code ["..(rCode or "NIL").."] html ["..(table.concat(respBody,"") or "NIL").."]")
end

SendCommand(command["VolumeUp"])

Offline trouty00

  • Full Member
  • ***
  • Posts: 206
  • Karma: +2/-1
Re: Sony TV REST API
« Reply #13 on: February 23, 2017, 01:11:45 pm »
great work, are you still working on a plugin or just going to use the code. will probbaly look at tweaking my lua code to incorporate this rather tan the os request i was using.

Stu

Offline Quixote

  • Full Member
  • ***
  • Posts: 241
  • Karma: +8/-32
Re: Sony TV REST API
« Reply #14 on: March 15, 2017, 11:58:38 pm »
This looks pretty interesting.
What model TVs will this work with? I have a Sony KDL-55W802A that I was hoping to control over my LAN.
My "Karma" has been modified by 2 or 3 douchebags that didn't like that I criticized the plugin that they worship. I'm not actually a bad person.