Websocket APIs to communicate with samsung smart tv

I am trying to communicate with my Samsung smart TV and I found on internet that it works with HTTP request.

There is some Samsung smart TV API on GitHub (even some in python) but they didn't work with my TV. Apparently, I have a not so common TV model.

Currently, I am stuck because I don't have the same answer from my TV when I am trying to do the same thing with two different websocket API.

WSCAT

$ wscat -c wss://192.168.1.20:8002/api/v2/channels/samsung.remote.control?name=dGVzdA== -n --no-color
(node:4547) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.

A pop-up appears on my TV asking me for the remote control authorization. Then I received a token in my terminal but I don't understand how I can retrieve it in bash.

Connected (press CTRL+C to quit)
< {"data":{"clients":[{"attributes":{"name":"dGVzdA=="},"connectTime":1601072715580,"deviceName":"dGVzdA==","id":"84a3df72-1910-447d-9b62-084b8435f1d","isHost":false}],"id":"84a3df72-1910-447d-9b62-084b8435f1d","token":"11235326"},"event":"ms.channel.connect"}
> 

Python API

>>> import websocket, ssl
>>> uri = 'wss://192.168.1.20:8002/api/v2/channels/samsung.remote.control?name=dGVzdA=='
>>> ws = websocket.create_connection(uri, sslopt={"cert_reqs": ssl.CERT_NONE})

No pop-up appears on my TV. I tried the recv method on websocket but it never ends. So I tried the send method with a payload to decrease TV's sound volume.

>>> payload = '{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_VOLDOWN","Option":False,"TypeOfRemote":"SendRemoteKey"}}'
>>> ws.send(payload)
145

It answers me the code 145 and nothing is done on my TV.

Python API & WSCAT

First, I connect to my TV using wscat, I accept the connection on my TV.
Then, I connect using Python websocket API.
Finally, when I send the Volume down payload to the TV, the Python3 console still answers me the code 145, but my TV accepts my payload and the volume decrease.
No need of the token received with wscat ¯\_(ツ)_/¯ ?

Is there someone here able to understand and explain me this madness ?



from Recent Questions - Stack Overflow https://ift.tt/2S3CFip
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation