27.02.2023, 14:57
(27.02.2023, 13:40)admin Wrote: It seems that you need to send KEY_HOME first to get the access token. Then add this token to the query string for further calls: ...samsung.remote.control?name=NAME&token=TOKEN
Add another client:receive() after sending the key and log the results.
This is the script so far:
Code:
host = '192.168.126.54'
port = 8001
name = 'SamsungTvRemote'
b64 = require('encdec').base64enc
ws = require('user.websocket')
json = require('json')
url = 'ws://' .. host .. ':' .. port .. '/api/v2/channels/samsung.remote.control?name=' .. b64(name)
client, err = ws.client('sync', 10)
res, err = client:connect(url)
if not res then
log('connection failed', err)
return
end
data, _, _, opcode, err = client:receive()
resp = json.pdecode(data)
log(resp)
if type(resp) ~= 'table' or resp.event ~= 'ms.channel.connect' then
log('invalid response', data, err)
client:close()
return
end
key = 'KEY_HOME'
payload = json.encode({
method = 'ms.remote.control',
params = {
Cmd = 'Click',
DataOfCmd = key,
Option = 'false',
TypeOfRemote = 'SendRemoteKey'
}
})
client:send(payload)
data, _, _, opcode, err = client:receive()
resp = json.pdecode(data)
log(resp)
client:close()
The result is this:
Samsung TV websocket 27.02.2023 15:54:54
* table:
["event"]
* string: ms.channel.unauthorized
-----------------------------------------------------
Samsung TV websocket 27.02.2023 15:54:54
* arg: 1
* string: invalid response
* arg: 2
* string: {"event":"ms.channel.unauthorized"}
* arg: 3
* nil