27.02.2023, 06:58
Try this:
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)
if type(resp) ~= 'table' or resp.event ~= 'ms.channel.connect' then
log('invalid response', data, err)
client:close()
return
end
key = 'KEY_VOLUP'
payload = json.encode({
method = 'ms.remote.control',
params = {
Cmd = 'Click',
DataOfCmd = key,
Option = 'false',
TypeOfRemote = 'SendRemoteKey'
}
})
client:send(payload)
client:close()