27.02.2023, 16:06
(27.02.2023, 15:49)admin Wrote: Add comments to this check:
Code:-- if type(resp) ~= 'table' or resp.event ~= 'ms.channel.connect' then
-- log('invalid response', data, err)
-- client:close()
-- return
-- end
I have a working script now using wss over port 8002. Only issue is that the TV keeps asking to accept the connection and it seems the token is changing all the time as i got a new one so now and then while testing.
Code:
host = '192.168.126.54'
port = 8002
name = 'MyRemote'
token = 16687249
b64 = require('encdec').base64enc
ws = require('user.websocket')
json = require('json')
url = 'wss://' .. host .. ':' .. port .. '/api/v2/channels/samsung.remote.control?name=' .. b64(name) .. '&token=' .. token
client, err = ws.client('sync', 10)
res, err = client:connect(url)
key = 'KEY_MUTE'
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()