24.02.2023, 14:45
(24.02.2023, 14:13)admin Wrote: This API uses websocket/JSON. You can use this example as a starting point: https://forum.logicmachine.net/showthrea...1#pid16331
Got this so far but i'm strugling with the payload. What's the correct way to send the commands?
Code:
host = '192.168.126.54'
port = 8001
name = 'SamsungTvRemote'
if not client then
ws = require('user.websocket')
json = require('json')
url = 'ws://'..host..':'..port..'/api/v2/channels/samsung.remote.control?name='..name
client, err = ws.client('sync', 10)
res, err = client:connect(url)
log( res, err)
if res then
client:send(json.encode({
payload = [[
'method': 'ms.remote.control',
'params': {
'Cmd': 'Click',
'DataOfCmd': key,
'Option': 'false',
'TypeOfRemote': 'SendRemoteKey'
}
]]
}))
client:send(json.encode({
payload = [['KEY_VOLUP']]
}))
else
log('connection failed: ' .. tostring(err))
client:close()
client = nil
end
else
data, _, _, opcode, err = client:receive()
if data then
data = json.pdecode(data)
if data then
log(data)
end
else
log('receive failed: ' .. tostring(err))
client:close()
client = nil
end
end