17.02.2020, 19:13
(This post was last modified: 17.02.2020, 23:40 by benanderson_475.)
Hi,
Why do you try Http post command to a tcp socket??
Try this, i have it working on Sony 2019 tv with no auth required as such (apart from the Xauth-psk as defined in the tv settings) also the protocol is well documented here
https://pro-bravia.sony.net/develop/inte...index.html
i just started learning lua so im sure there are some improvements to make to this script.
Change ip adress below to match tv and update ["X-Auth-PSK"] = "123456789", with your pre shared key from the tv
Why do you try Http post command to a tcp socket??
Try this, i have it working on Sony 2019 tv with no auth required as such (apart from the Xauth-psk as defined in the tv settings) also the protocol is well documented here
https://pro-bravia.sony.net/develop/inte...index.html
i just started learning lua so im sure there are some improvements to make to this script.
Change ip adress below to match tv and update ["X-Auth-PSK"] = "123456789", with your pre shared key from the tv
Code:
local http = require("socket.http")
local ltn12 = require("ltn12")
require('json')
local path_system = "http://192.168.1.21/sony/system"
local path_avContent = 'http://192.168.1.21/sony/avContent'
local payl = {
Pwr_on = [[ {"method": "setPowerStatus","id": 55,"params": [{"status": true}],"version": "1.0"} ]], --/system
Pwr_off = [[ {"method": "setPowerStatus","id": 55,"params": [{"status": false}],"version": "1.0"} ]], --/system
Pwr_req = [[ {"method": "getPowerStatus","id": 50,"params": [],"version": "1.0"} ]], --/system
Pwr_Get_system = [[{"method": "getSystemInformation","id": 33,"params": [],"version": "1.0"}]],
Set_input_hdmi3 = [[ {"method": "setPlayContent","id": 101,"params": [{"uri": "extInput:hdmi?port=3"}],"version": "1.0"} ]], --/avContent
Set_req = [[ {"method": "getPlayingContentInfo","id": 103,"params": [],"version": "1.0"} ]], --/avContent
vol_set = [[ {"method": "setAudioVolume","id": 98,"params": [{"volume": "5","ui": "on","target": "speaker"}],"version": "1.2"} ]], -- /audio
vol_req = [[ {"method": "getVolumeInformation", "id": 33, "params": [], "version": "1.0"} ]], -- /audio
reboot = [[ {"method": "requestReboot","id": 10,"params": [],"version": "1.0"} ]] --/system
}
--********///////////// Main Command ////////////********--
function sony_do_cmd(sony_cmd) -- 'Pwr_on' , 'Pwr_off' for power on call function, sony_do_cmd('Pwr_on')
-- is pwr command set url
pwr = string.match(sony_cmd, "Pwr_")
set = string.match(sony_cmd, "Set_")
if pwr then
path = path_system
payload = payl[sony_cmd]
end
if set then
path = path_avContent
payload = payl[sony_cmd]
end
local response_body = { }
local res, code, response_headers, status = http.request
{
url = path,
method = "POST",
headers =
{
["Accept"] = "*/*",
["Content-Type"] = "application/x-www-form-urlencoded",
["X-Auth-PSK"] = "123456789",
["Content-Length"] = payload:len()
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(response_body)
}
log(json.decode(response_body))
end