samsungctl
samsungctl copied to clipboard
QSeries
Will this code work on a 2018 Q series? I have been trying to get this code to run and cannot get thru all the errors that are happening for me.
Show what you have tried and which errors you get!
I've just tried the using samsungctl on a Q series:
If I do:
curl http://192.168.0.10:8001/api/v2
Then the TV pops up with a "Give smart device access prompt", if how ever I run samsungctl as below, no popup shows.
$ samsungctl --host 192.168.0.10 --method websocket KEY_MENU
Returns
Traceback (most recent call last): File "/home/jumbotron/.local/bin/samsungctl", line 11, in
sys.exit(main()) File "/home/jumbotron/.local/lib/python3.6/site-packages/samsungctl/main.py", line 110, in main with Remote(config) as remote: File "/home/jumbotron/.local/lib/python3.6/site-packages/samsungctl/remote.py", line 11, in init self.remote = RemoteWebsocket(config) File "/home/jumbotron/.local/lib/python3.6/site-packages/samsungctl/remote_websocket.py", line 30, in init self._read_response() File "/home/jumbotron/.local/lib/python3.6/site-packages/samsungctl/remote_websocket.py", line 72, in _read_response raise exceptions.UnhandledResponse(response) samsungctl.exceptions.UnhandledResponse: {'event': 'ms.channel.unauthorized'}
This is basically the same things I have tried except I used Chrome web socket tool to send the commands. Get the same result however. It allows me to authorize but then all commands return: 'event': 'ms.channel.unauthorized
So I actually got something working, but without using samsungctl.
First off the remote control endpoint is only availiable on using secure websocket.
Secondly it needs ?token=<8 didgit number>
added to the URL, where the eight digit number is returned after the device is allowed access using dialog the pop up on the tv.
using ws client I get an initial response of:
06:48:15 -> (json)
{ "data": { "clients": [ { "attributes": { "name": null }, "connectTime": 1567075825828, "deviceName": "Smart Device", "id": "1194e510-7e44-48f2-a15a-6c35d992d125", "isHost": false } ], "id": "1194e510-7e44-48f2-a15a-6c35d992d125" }, "event": "ms.channel.connect" }
but no commands i send after this seem to work. always get unauthorized.
@jbro - when exactly do you get that 8 digit number? What do you do to get that token?
If you connect to the remote control endpoint on secure websocket like:
$ wscat -n --connect wss://192.168.0.10:8002/api/v2/channels/samsung.remote.control
Then a little dialog pops up on the tv, that asks you if you want to allow the device, after pressing allow some json like below is returned containing the token:
> connected (press CTRL+C to quit)
< {"data":{"clients":[{"attributes":{"name":null},"connectTime":1567087962961,"deviceName":"Smart Device","id":"c8f69ec8-8379-4a29-8c80-43446c0a2c7","isHost":false}],"id":"c8f69ec8-8379-4a29-8c80-43446c0a2c7","token":"16131682"},"event":"ms.channel.connect"}
Thank you.
I will try this again today.
After getting the token and I am connected to the display can you please verify the format of the commands sent. I believe they are sent in a json format but want to confirm. Can you provide a sample of how the command is sent.
Thank you.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Jesper Brix Rosenkilde [email protected] Sent: Thursday, August 29, 2019 10:16:05 AM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
If you connect to the remote control endpoint on secure websocket like:
$ wscat -n --connect wss://192.168.0.10:8002/api/v2/channels/samsung.remote.control
Then a little dialog pops up on the tv, that asks you if you want to allow the device, after pressing allow some json like below is returned containing the token:
connected (press CTRL+C to quit) < {"data":{"clients":[{"attributes":{"name":null},"connectTime":1567087962961,"deviceName":"Smart Device","id":"c8f69ec8-8379-4a29-8c80-43446c0a2c7","isHost":false}],"id":"c8f69ec8-8379-4a29-8c80-43446c0a2c7","token":"16131682"},"event":"ms.channel.connect"}
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGTHY4H2KC4YRIA5PATQG7K2LA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5OUDVQ%23issuecomment-526205398&data=02%7C01%7C%7Cd4862d39c8804e36201508d72c8b6ec6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637026849672283214&sdata=PGsQgd%2BB5Irqb8kw2U4Ucjp7ynLYNTXSTK90%2Bted%2Bn8%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGT6T6HO744ADTOLJRDQG7K2LANCNFSM4HQL6ZSQ&data=02%7C01%7C%7Cd4862d39c8804e36201508d72c8b6ec6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637026849672283214&sdata=H%2BAI0q5gStA2DxjqwW%2B2siAK6o5gXycl6INydnEeXNY%3D&reserved=0.
This is what I'm using, it's not pretty but it works:
#!/usr/bin/env python3
import websocket
import ssl
import sys
import os
tv_ip = '192.168.0.10'
if sys.argv[1] == 'on':
if os.system("ping -c 1 " + tv_ip) is 0:
ws = websocket.create_connection('wss://192.168.0.10:8002/api/v2/channels/samsung.remote.control?name=anVtYm90cm9u&token=12368079', sslopt={"cert_reqs": ssl.CERT_NONE})
ws.send('{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_POWER","Option":false,"TypeOfRemote":"SendRemoteKey"}}"')
ws.send('{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_HDMI","Option":false,"TypeOfRemote":"SendRemoteKey"}}"')
else:
os.system('sudo etherwake -i enp4s0 c0:48:e6:19:4e:4e')
if sys.argv[1] == 'off':
ws = websocket.create_connection('wss://192.168.0.10:8002/api/v2/channels/samsung.remote.control?name=anVtYm90cm9u&token=12368079', sslopt={"cert_reqs": ssl.CERT_NONE})
ws.send('{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_POWER","Option":false,"TypeOfRemote":"SendRemoteKey"}}"')
Thank you.
I will try this with ws client tonight then try to get the code working.
So basically
- Connect and get token.
- Then disconnect
- Connect with name and token
- Then should be able to send the command json strings.
Does this sound correct?
Get Outlook for iOShttps://aka.ms/o0ukef
From: Jesper Brix Rosenkilde [email protected] Sent: Thursday, August 29, 2019 10:21:57 AM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
This is what I'm using, it's not pretty but it works:
#!/usr/bin/env python3 import websocket import ssl import sys import os
tv_ip = '192.168.0.10'
if sys.argv[1] == 'on': if os.system("ping -c 1 " + tv_ip) is 0: ws = websocket.create_connection('wss://192.168.0.10:8002/api/v2/channels/samsung.remote.control?name=anVtYm90cm9u&token=12368079', sslopt={"cert_reqs": ssl.CERT_NONE}) ws.send('{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_POWER","Option":false,"TypeOfRemote":"SendRemoteKey"}}"') ws.send('{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_HDMI","Option":false,"TypeOfRemote":"SendRemoteKey"}}"') else: os.system('sudo etherwake -i enp4s0 c0:48:e6:19:4e:4e')
if sys.argv[1] == 'off': ws = websocket.create_connection('wss://192.168.0.10:8002/api/v2/channels/samsung.remote.control?name=anVtYm90cm9u&token=12368079', sslopt={"cert_reqs": ssl.CERT_NONE}) ws.send('{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_POWER","Option":false,"TypeOfRemote":"SendRemoteKey"}}"')
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGVGAXNEQZZSYD3YYUDQG7LQLA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5OU2BA%23issuecomment-526208260&data=02%7C01%7C%7Cb52f2671a0f8477e6af708d72c8c40ad%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637026853195677448&sdata=H90iEXwLF8qllsUF3OLmQRmzVq3XuqRQOF%2BDLArkh5A%3D&reserved=0, or mute the threadhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGV4DRH7JNF4JD24QJLQG7LQLANCNFSM4HQL6ZSQ&data=02%7C01%7C%7Cb52f2671a0f8477e6af708d72c8c40ad%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637026853195687460&sdata=BJ8nSpXQLvnLAIUDpuHiCAuGNUAeFO07GvCpYUBc9jg%3D&reserved=0.
Sounds very reasonable, maybe you should use the name when getting the token, I don't know if it is a pair.
Sounds good. I will test this tonight and let you know how it works out for me.
Thank you for all your help on this. It’s been a painful process.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Jesper Brix Rosenkilde [email protected] Sent: Thursday, August 29, 2019 10:30:11 AM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
Sounds very reasonable, maybe you should use the name when getting the token, I don't know if it is a pair.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGSFILRAYAGQOCQIPULQG7MPHA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5OVZZI%23issuecomment-526212325&data=02%7C01%7C%7C3ab0182974444bbbbbf908d72c8d66ac%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637026858126388573&sdata=ZCqDPu2CW42xeaKliyELX8mzM5vfTjNT%2BnXtimxwtoA%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGTVRN5WCYBFWT5GXATQG7MPHANCNFSM4HQL6ZSQ&data=02%7C01%7C%7C3ab0182974444bbbbbf908d72c8d66ac%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637026858126388573&sdata=COjZOhquL1YTnq9LkDYzggLeawF1ed%2FV%2FFlLHJATfgc%3D&reserved=0.
No problem, let me know when you have it in master, then I'll test it out :)
any time I try wss// it will not connect. I have to use ws// on port 8001
here are my results....sadly still no success
21:41:12 Connecting to "ws://10.0.0.244:8001/api/v2/channels/ms.remote.control?name="ChrisRemote""
21:41:12 Successfull connected to "ws://10.0.0.244:8001/api/v2/channels/ms.remote.control?name="ChrisRemote""
21:41:12 -> (json)
{ "data": { "clients": [ { "attributes": { "name": ""ChrisRemote"" }, "connectTime": 1567129408905, "deviceName": ""ChrisRemote"", "id": "c2273afe-ce5f-426-a39-bfaee018976a", "isHost": false } ], "id": "c2273afe-ce5f-426-a39-bfaee018976a" }, "event": "ms.channel.connect" } 21:41:18 <- (json)
{ "method": "ms.remote.control", "params": { "Cmd": "Click", "DataOfCmd": "KEY_POWER", "Option": false, "TypeOfRemote": "SendRemoteKey" } } 21:41:18 -> (json)
{ "data": { "message": "unrecognized method value : ms.remote.control" }, "event": "ms.error" }
if I format the request using samsung.remote.control:
21:46:41 Connecting to "ws://10.0.0.244:8001/api/v2/channels/samsung.remote.control"
21:46:41 Successfull connected to "ws://10.0.0.244:8001/api/v2/channels/samsung.remote.control"
21:46:41 -> (json)
{ "event": "ms.channel.unauthorized" } 21:46:41 Connection to "ws://10.0.0.244:8001/api/v2/channels/samsung.remote.control" closed
21:46:41 Error: (1006)
Oh yeah forgot to mention wss runs on port 8002, see my code above.
I tried wss on port 8002.
Result:
06:15:09 Connecting to "wss://10.0.0.244:8002/api/v2/channels/samsung.remote.control"
06:15:09 Connection to "wss://10.0.0.244:8002/api/v2/channels/samsung.remote.control" closed
06:15:09 Error: (1006)
Seems my display actively refuses a connection on that port. Only port that does anything is 8001
I don't know if this is after a certain version of either the TV or firmware. My TV is a Q7 I think running the newest firmware as of last week.
Mine is a Q6. Firmware should be up to date
Get Outlook for iOShttps://aka.ms/o0ukef
From: Jesper Brix Rosenkilde [email protected] Sent: Friday, August 30, 2019 9:39:33 AM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
I don't know if this is after a certain version of either the TV or firmware. My TV is a Q7 I think running the newest firmware as of last week.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGXKZBTCCU3UNZCS3ADQHEPJLA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5RVYZA%23issuecomment-526605412&data=02%7C01%7C%7C5301e0271956494ac9ff08d72d4f7e66%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637027691747897224&sdata=RvnGiCqONTZRw4%2Fl8lYMHOo9nqPqYgXtw8FrEe1HkSM%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGQKJQJF7AXRTGJZKHTQHEPJLANCNFSM4HQL6ZSQ&data=02%7C01%7C%7C5301e0271956494ac9ff08d72d4f7e66%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637027691747907241&sdata=n2EdgsMO5o8BnXmaioV0n4e1AWKhpdX%2Fg%2BEzjfHxo90%3D&reserved=0.
I have a Q8, and would like get this working on mine. Be happy to try it out on my Q8. I'm a bit confuse as to which branch and which repo I should actually pull from. (i.e. which is the latest)
There is the yours samsungctl , and one by Kdschlossar (which I believe a fork of yours)
I've been trying this on my linux machine to get it to work, but in the end I would like to get this working on my HASSIO based Home Assistant. planning to use the AppDaemon add-on so I can use python to call this package
I'm currently using your master branch. I'll try the wscat or ws I see if I can get the token.
Any other suggestion let me know. Thanks
HI,
So, i have a UE43RU7400UXXU. Which is officially a series 7 TV. My API version is 2.0.25. I've all other code that i've seen online not to work, as i never got a token.
Now, the below code seems to work.
To get a token:
const WebSocket = require('ws');
function base64Encode(aStr) {
return Buffer.from(aStr).toString('base64');
};
var appname = base64Encode("SamsungTvRemote2");
var baseURL = "wss://192.168.1.22:8002/api/v2/channels/samsung.remote.control?name=" + appname
function getToken() {
var uri = baseURL;
console.log('URL: ' + uri)
let ws = new WebSocket(uri, {
rejectUnauthorized: false
});
ws.on('message', (response) => {
console.log("SOCKET 1 RECEIVED: " + response);
var data = JSON.parse(response);
if (data.event === "ms.channel.connect") {
console.log("YOUR TOKEN IS:" + data.data.token);
}
})
}
` When you run this, the TV will ask you for 'permission' for the app. The name will be the same as above "SamsungTvRemote2". After you approve that (click Allow), then you'll get the token from the K2. It can also time-out at this point, so don't be slow as a snail :)
After that, the following code will work to do 'volume down' const WebSocket = require('ws');
function base64Encode(aStr) {
return Buffer.from(aStr).toString('base64');
};
var appname = base64Encode("SamsungTvRemote2");
var baseURL = "wss://192.168.1.22:8002/api/v2/channels/samsung.remote.control?name=" + appname
var token = 22936467; # REPLACE WITH YOUR TOKEN
function doStuff() {
uri = baseURL+"&token="+token;
console.log('URL: ' + uri)
ws = new WebSocket(uri, {
rejectUnauthorized: false
});
ws.on('message', (response) => {
console.log("SOCKET 2 RECEIVED:" + response);
var data = JSON.parse(response);
var cmd = {
method: 'ms.remote.control',
params: {
Cmd: 'Click',
DataOfCmd: 'KEY_VOLDOWN',
Option: 'false',
TypeOfRemote: 'SendRemoteKey'
}
}
var str = JSON.stringify(cmd);
console.log('SOCKET 2 SEND:' + str);
ws.send(str);
});
}
doStuff();
For me, this works. I'm not sure how long this token lasts. I tend to power down the TV every night, not sure if it forgets the code. THe token i got last week didn't work.
cyclops1982,
I was all excited to try this out, until I realized this wasn't python. Darn. What language is this? Go?
I'll see if I can convert it to python and get it to work.
I will try to convert to C# for my application. Seems very straight forward. I will try it first in a ws client and see if it connects and get a token. Will keep everyone posted.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Brissey [email protected] Sent: Sunday, September 8, 2019 12:01:37 PM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
cyclops1982,
I was all excited to try this out, until I realized this wasn't python. Darn. What language is this? Go?
I'll see if I can convert it to python and get it to work.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGSFEDGESAQYHPYLG5LQIUOWDA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6FTG2Q%23issuecomment-529216362&data=02%7C01%7C%7C1c0f5bd555b14782785608d73475d49e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637035552985279565&sdata=x867fdMQQvdBdPSpwEsoW1DebsT1jknqIud6CDRmGb8%3D&reserved=0, or mute the threadhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGTEWW26AX3B66IHZVLQIUOWDANCNFSM4HQL6ZSQ&data=02%7C01%7C%7C1c0f5bd555b14782785608d73475d49e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637035552985289576&sdata=W97rMP%2FkU%2BHG%2FHC%2BkGPgiSE0Ib6GilSP7qgT7fqW5Wc%3D&reserved=0.
My display refuses any connection on port 8002.
Can connect to port 8001 but no command seems to work using WS client.
I connect but any time a connection is successful I get:
21:14:06 Connecting to "ws://10.0.0.80:8001/api/v2/channels/ms.remote.control"
21:14:06 Successfull connected to "ws://10.0.0.80:8001/api/v2/channels/ms.remote.control"
21:14:06 -> (json)
{
"data": {
"clients": [
{
"attributes": {
"name": null
},
"connectTime": 1567991805347,
"deviceName": "Smart Device",
"id": "2d7bc5e3-782d-4f94-bbb-32322b828c9d",
"isHost": false
}
],
"id": "2d7bc5e3-782d-4f94-bbb-32322b828c9d"
},
"event": "ms.channel.connect"
}
This is the most I have ever been able to get from the display.
Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10
From: Chris M Sent: Sunday, September 8, 2019 8:36:27 PM To: Ape/samsungctl [email protected]; Ape/samsungctl [email protected] Cc: Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
I will try to convert to C# for my application. Seems very straight forward. I will try it first in a ws client and see if it connects and get a token. Will keep everyone posted.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Brissey [email protected] Sent: Sunday, September 8, 2019 12:01:37 PM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
cyclops1982,
I was all excited to try this out, until I realized this wasn't python. Darn. What language is this? Go?
I'll see if I can convert it to python and get it to work.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGSFEDGESAQYHPYLG5LQIUOWDA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6FTG2Q%23issuecomment-529216362&data=02%7C01%7C%7C1c0f5bd555b14782785608d73475d49e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637035552985279565&sdata=x867fdMQQvdBdPSpwEsoW1DebsT1jknqIud6CDRmGb8%3D&reserved=0, or mute the threadhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGTEWW26AX3B66IHZVLQIUOWDANCNFSM4HQL6ZSQ&data=02%7C01%7C%7C1c0f5bd555b14782785608d73475d49e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637035552985289576&sdata=W97rMP%2FkU%2BHG%2FHC%2BkGPgiSE0Ib6GilSP7qgT7fqW5Wc%3D&reserved=0.
Cyclops1982, et.al.,
Based on your code I cobbled together a python 3.X web-client to see if I could get a token back from my Samsung Q8FN
I can now get my TV to display the pop-up to give permission for my device to be connected. And when I do I do get a token back!!! (got to be fast on that remote button press to allow)
response: {"data":{"clients":[{"attributes":{"name":"SamsungTvRemote2"},"connectTime":1568005339390,"deviceName":"SamsungTvRemote2","id":"81177dfe-2c84-4ec9-a614-7f2a4a81fad","isHost":false}],"id":"81177dfe-2c84-4ec9-a614-7f2a4a81fad","token":"14517545"},"event":"ms.channel.connect"}
I still have a few issues, when I go to the external device list (on the TV) for devices that have been allowed to connect. The entry which should have the name of the device shows [Invalid UTF-8] So I either forgot some option or the encoding is not quite right. The code is just gets the the token
I also noticed, in my case at least, the TV must be TV source (i.e. not in app like YouTube or Netflix for the pop-up to occur. I also had my AVR off as well (may not be necessary)
If you run this code more than once be sure to delete the device from the Samsung's TV External Device List! Otherwise you'll probably get some sort of connection refused error.
here is the python code:
import base64 import sys import re try: import thread except ImportError: import _thread as thread import time import websocket import ssl
appname = 'SamsungTvRemote2' baseURL = "wss://192.168.1.23:8002/api/v2/channels/samsung.remote.control?name=" + appname
def on_message(ws, message): print('on_message') print(message)
def on_error(ws, error): print('on_error') print(error)
def on_close(ws): print('on_close') print("### closed ###")
def on_open(ws): def run(*args): for i in range(3): time.sleep(1) ws.send("Hello %d" % i) time.sleep(2) ws.close() print("thread terminating...") thread.start_new_thread(run, ())
if name == "main": websocket.enableTrace(True) uri = baseURL; print('URL: ' + uri) print("") ws = websocket.WebSocketApp(uri, on_message = on_message, on_error = on_error, on_close = on_close)
ws.on_open = on_open
# disable of the SSL Cert requirement
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
Hope this help others, and maybe someone can tell me why I get Invalid UTF-8 for a device in the TV external device list
For some reason all the indenting for the python got removed in the post. Sorry about that.
Do you know of any reason my display would refuse connection on wss port 8002. I can only connect ws on port 8001 and can never get a token.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Brissey [email protected] Sent: Monday, September 9, 2019 2:46:56 AM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
For some reason all the indenting for the python got removed in the post. Sorry about that.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGU242SFLQWMXCMCZKTQIXWOBA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6GNJPI%23issuecomment-529323197&data=02%7C01%7C%7C74ce0c7332e1489ab6a908d734f18235%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637036084178682335&sdata=Zg1PNIfdWl%2BE1vMfaxYuRIdo6Pk9fzgqiOMnWOrG4s4%3D&reserved=0, or mute the threadhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGRH33WK6MGPDWLPG2DQIXWOBANCNFSM4HQL6ZSQ&data=02%7C01%7C%7C74ce0c7332e1489ab6a908d734f18235%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637036084178692344&sdata=2%2BDMFh9PCR%2BbVCjDtbkdW2oPgFUyN3IIZ7U4flbz7o0%3D&reserved=0.
I'm not exactly sure except when I tried connected to 8002 it always refused connection until I specified the websocket not use use SSL Certificate. e.g. sslopt={"cert_reqs": ssl.CERT_NONE}. You don't have that port blocked by your router (not that it should). As I mentioned before my TV had to be in a specific configuration to observe the pop-up..... Also on occasion I need to power off and power on the TV before I get the prompt TV is a QN65Q8FNB My software version displayed is: T-KTM2AKUC-1270.6, BT-S if that is any help.....
Here's a example python that sends the KEY_MENU to the TV
I know, the indentation are all gone. Somebody tell how to get them to stay. Looks fine before I submit.
python 3.X code
``# -- coding: utf-8 -- import sys import re try: import thread except ImportError: import _thread as thread import time import websocket import ssl import json
def sendCmd(ws,keycmd): ''' json cmd format cmd = { 'method' : 'ms.remote.control', 'params': { 'Cmd': 'Click', 'DataOfCmd': 'KEY_MENU', 'Option': 'false', 'TypeOfRemote': 'SendRemoteKey' } } ''' cmddict = { 'method' : 'ms.remote.control' } paramdict = { 'Cmd': 'Click', 'DataOfCmd': 'Bogus_KEY', 'Option': 'false','TypeOfRemote': 'SendRemoteKey'} paramdict['DataOfCmd'] = keycmd cmddict['params'] = paramdict; json_str = json.dumps(cmddict) print(json_str) ws.send(json_str);
if name == "main": websocket.enableTrace(True) appname = "SamsungTvRemote2" base_url = "wss://192.168.1.23:8002/api/v2/channels/samsung.remote.control?name={}&token={}" token = "57216234" url = base_url.format(appname,token) # e.g. name=SamsungTvRemote2&token=47216513 print(url) ws = websocket.create_connection(url, sslopt={"cert_reqs": ssl.CERT_NONE}) #ws = None # bring up menu sendCmd(ws,'KEY_MENU') time.sleep(5) # close the menu sendCmd(ws,'KEY_MENU') ws.close()
@gbrissey The appname that you use, needs to be a base64 encoded string. That's why it's complaining about the UTF-8 issue. The javascript has a little base64encode method and that's waht's being used.
Once you have the token, does it stay the same? I've noticed that i can send a few commands but then it just responds with No Authorization. I've also noticed that turning off the TV and then ON again seems to 'forget' the previous code. Ideally - i'd like to just get one code once.
I wonder if it has to do with the fact that we use a websocket and/or not close it properly, or something like that?
About the code formatting: https://help.github.com/en/articles/creating-and-highlighting-code-blocks
Finally started to make some progress. I was using the WSC client in chrome to try and test connections and commands and could never get it to work. Built a simple connection in C# and now I can connect and get the token. Now just have to get logged back in with token and see if it will respond to any commands. Will post some code once I have something real to show.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Ruben [email protected] Sent: Tuesday, September 10, 2019 2:56:25 AM To: Ape/samsungctl [email protected] Cc: Cmac2016 [email protected]; Author [email protected] Subject: Re: [Ape/samsungctl] QSeries (#114)
@gbrisseyhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgbrissey&data=02%7C01%7C%7C9b02935e62e142081e4808d735bbff57%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637036953860094596&sdata=Y69wEQq8e6ygEoxWX3Hk0RPymET5VJIT%2BOkxRm8ZFeM%3D&reserved=0 The appname that you use, needs to be a base64 encoded string. That's why it's complaining about the UTF-8 issue. The javascript has a little base64encode method and that's waht's being used.
Once you have the token, does it stay the same? I've noticed that i can send a few commands but then it just responds with No Authorization. I've also noticed that turning off the TV and then ON again seems to 'forget' the previous code. Ideally - i'd like to just get one code once.
I wonder if it has to do with the fact that we use a websocket and/or not close it properly, or something like that?
About the code formatting: https://help.github.com/en/articles/creating-and-highlighting-code-blockshttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhelp.github.com%2Fen%2Farticles%2Fcreating-and-highlighting-code-blocks&data=02%7C01%7C%7C9b02935e62e142081e4808d735bbff57%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637036953860094596&sdata=HabV6p%2B%2Fyqkp0G7qjjokKsIDkjPnePzD6n30b1T%2B1Gg%3D&reserved=0
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FApe%2Fsamsungctl%2Fissues%2F114%3Femail_source%3Dnotifications%26email_token%3DAGA5EGRO5KSRUWAGXPCQEMLQI5AJTA5CNFSM4HQL6ZS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6KBRHQ%23issuecomment-529799326&data=02%7C01%7C%7C9b02935e62e142081e4808d735bbff57%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637036953860104600&sdata=GPCyiA2wNl76jGHh48%2FzplYNH5JbDrf3TJTTiYCGwQw%3D&reserved=0, or mute the threadhttps://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGA5EGSU2YCVWXNZ3ZOXEU3QI5AJTANCNFSM4HQL6ZSQ&data=02%7C01%7C%7C9b02935e62e142081e4808d735bbff57%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637036953860104600&sdata=Sw1aPR82F4AogujNpna%2B1KwcF%2BBD9SsxWLUoNVGwabw%3D&reserved=0.