Different behaviors with 2 different Websocket APIs but same request

﹥>﹥吖頭↗ 提交于 2021-02-11 14:54:49

问题


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

There is some Samsung smart TV API on GitHub 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 behavior when I am doing (or trying to do) the same thing with two different Websocket APIs.

WSCAT

$ wscat -c wss://192.168.1.20:8002/api/v2/channels/samsung.remote.control?name=dGVzdA== -n --no-color
Connected (press CTRL+C to quit)
< {[...]"token":"11235326"[...]}
> 

My TV displays a pop-up 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.

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 send method with a payload to decrease TV's sound volume.

>>> payload = '{[working payload]}'
>>> ws.send(payload)
145

It answers me "145" but nothing is done on my TV.

Both API

But, if I connect with wscat (choose authorize on pop-up), I can immediately control my TV with the Python API. Even if the python3 console still answers me "145" and without using the token given by wscat ¯\_(ツ)_/¯

Is there differences between those 2 creation of Websocket ?

来源:https://stackoverflow.com/questions/64072049/different-behaviors-with-2-different-websocket-apis-but-same-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!