Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop branch updated #106

Open
kdschlosser opened this issue Feb 28, 2019 · 428 comments
Open

Develop branch updated #106

kdschlosser opened this issue Feb 28, 2019 · 428 comments

Comments

@kdschlosser
Copy link
Owner

OK folks I just updated the develop branch. I did a massive amount of code changes.

There is also a new file called RUN_ME.py. this is a test program. You can run this if you like it will prompt you if it needs user input as it runs. The program never reuses the same config file so pay attetion to your paired devices on the TV it's self. You will have to delete the pairings.

The test program tests every single aspect of the library. it is going to output to the console window. it is going to be a HUGE amount of data. so if you want to scroll back thn I would suggest increasing the buffer size to say 10K lines.

The program is also going to output everything to a series of files.
DO NOT POST ERRORS OR CREATE NEW ISSUES.

zip up the directory and attach the zip to a post here.

DO NOT CREATE AN ISSUE WITHOUT HAVING ATTACHED THE OUTPUT FROM THE TEST PROGRAM.

That is the only thing I am going to need to be able to solve any issues. you do not have to pass any parameters to the test program. it is going to do what it needs to do. If the program goes nuts and keeps on repeating the same error. please ctrl+c the thing to stop it. If the test program runs for longer then 60 seconds it is frozen. you will need to ctrl+c it or terminate thee process.

it is still going to output data to the file if it get stuck in an endless loop or if it freezes. so please attach the files.

@ghost
Copy link

ghost commented Feb 28, 2019

Getting error trying to install develop branch:

pip install git+git://github.com/kdschlosser/samsungctl@develop

Collecting git+git://github.com/kdschlosser/samsungctl@develop
  Cloning git://github.com/kdschlosser/samsungctl (to revision develop) to c:\users\user\appdata\local\temp\pip-req-build-8thd5o
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info\samsungctl.egg-info
    writing requirements to pip-egg-info\samsungctl.egg-info\requires.txt
    writing pip-egg-info\samsungctl.egg-info\PKG-INFO
    writing top-level names to pip-egg-info\samsungctl.egg-info\top_level.txt
    writing dependency_links to pip-egg-info\samsungctl.egg-info\dependency_links.txt
    writing entry points to pip-egg-info\samsungctl.egg-info\entry_points.txt
    writing manifest file 'pip-egg-info\samsungctl.egg-info\SOURCES.txt'
    c:\programdata\anaconda2\lib\site-packages\setuptools\dist.py:397: UserWarning: Normalizing '0.8.65b' to '0.8.65b0'
      normalized_version,
    error: package directory 'samsungctl\remote_encrypted\py3rijndael' does not exist

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\user\appdata\local\temp\pip-req-build-8thd5o\

@kdschlosser
Copy link
Owner Author

fixed

@ghost
Copy link

ghost commented Feb 28, 2019

Thanks! But now new issue:

samsungctl --host <ip> KEY_SOURCE

Traceback (most recent call last):
  File "c:\programdata\anaconda2\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\programdata\anaconda2\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\ProgramData\Anaconda2\Scripts\samsungctl.exe\__main__.py", line 5, in <module>
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\__init__.py", line 20, in <module>
    from .remote import Remote # NOQA
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\remote.py", line 7, in <module>
    from .remote_encrypted import RemoteEncrypted
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\remote_encrypted\__init__.py", line 24, in <module>
    from . import crypto # NOQA
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\remote_encrypted\crypto.py", line 6, in <module>
    from .aes import AES, AES_CIPHER, MODE_CBC
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\remote_encrypted\aes.py", line 3, in <module>
    from .keys import wbKey, transKey
ImportError: cannot import name transKey

@kdschlosser
Copy link
Owner Author

ok cool. I know there are going to be some issues. II will get them fixed

@kdschlosser
Copy link
Owner Author

fixed

@ghost
Copy link

ghost commented Feb 28, 2019

thanks for prompt reply. now issue is this:

samsungctl --host <ip> KEY_SOURCE
Traceback (most recent call last):
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\upnp\discover.py", line 99, in __init__
    sock.bind((local_address, 0))
  File "c:\programdata\anaconda2\lib\socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10049] The requested address is not valid in its context
169.254.119.51
Traceback (most recent call last):
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\upnp\discover.py", line 99, in __init__
    sock.bind((local_address, 0))
  File "c:\programdata\anaconda2\lib\socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10049] The requested address is not valid in its context
169.254.111.71
Traceback (most recent call last):
  File "c:\programdata\anaconda2\lib\site-packages\samsungctl\upnp\discover.py", line 99, in __init__
    sock.bind((local_address, 0))
  File "c:\programdata\anaconda2\lib\socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10049] The requested address is not valid in its context
169.254.217.193
Unable to discover any TV's

same if use --port 8002 --method websocket

@kdschlosser
Copy link
Owner Author

ok

@kdschlosser
Copy link
Owner Author

run the RUN_ME.py file do not use the command line for the moment.

@ghost
Copy link

ghost commented Feb 28, 2019

duplicate recursion messages excluded:

Run tests on TV UN65NU7300? ((y/n):y
SETTING UP REMOTE
Traceback (most recent call last):
  File "RUN_ME.py", line 197, in run_test
    remote = samsungctl.Remote(config)
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\remote.py", line 31, in __call__
    remote = RemoteWebsocket(config)
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\utils.py", line 24, in wrapper
    return func(*args, **kwargs)
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\remote_websocket.py", line 34, in __init__
    super(RemoteWebsocket, self).__init__(config)
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\utils.py", line 24, in wrapper
    return func(*args, **kwargs)
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\websocket_base.py", line 29, in __init__
    self._send_lock - threading.Lock()
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\upnp\__init__.py", line 31, in __getattr__
    if self.is_connected and item in self._devices:
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\upnp\__init__.py", line 31, in __getattr__
    if self.is_connected and item in self._devices:
  File "C:\ProgramData\Anaconda2\Lib\site-packages\samsungctl\upnp\__init__.py", line 31, in __getattr__
    if self.is_connected and item in self._devices:
RuntimeError: maximum recursion depth exceeded while calling a Python object

@kdschlosser
Copy link
Owner Author

ok I just updated the develop branch once again. so give it a go. use the RUNME.py file to run tests against the TV. It will test every available feature to make sure it is working. the test supports multiple TV's and it will ask if you want to run the tests for each TV it locates. it is going to ask to create \tests in the root of thee system drive on the machine the tests are run from. it is going to create a series of files in there. I need a copy of those file whether or not the tests ended. It may get stuck at the end of the tests. if it does (no output to the screen for more then 10 seconds) just kill the process or ctrl+c it. zip up the tests folder and attach it to a post. if you have the ability to run the tests from python 2.7 and python >= 3.5 that would be a huge help. just be sure to zip up the tests folder between running the tests.

Once you have paired the TV if you leave the .config files in the tests folder you will not have to pair the TV again. You do not need to delete the files in the folder either. the program will overwrite any files it needs to.

@Kryzek
Copy link

Kryzek commented Mar 6, 2019

tests.zip

@mlebrun
Copy link

mlebrun commented Mar 7, 2019

I downloaded the develop branch, installed but no matter what, I get this:

$ samsungctl --host 192.168.1.222 --name myremote KEY_VOLDOWN
127.0.0.1
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/upnp/discover.py", line 129, in run
    (IPV4_MCAST_GRP, 1900)
error: [Errno 49] Can't assign requested address
Unable to discover any TV's

Was just trying to get a simple command to work before running the suite. Seems like no matter what I pass, I keep getting Can't assign requested address?

@mlebrun
Copy link

mlebrun commented Mar 7, 2019

I've also tried samsungctl --host 192.168.1.222 --port 8001 --method websocket --interactive, and other variations. Always the same thing.

@Kryzek
Copy link

Kryzek commented Mar 7, 2019

It seems my tests.zip is not very helpful since I get also Unable to discover any TV's (UE46F6400) when trying samsungctl --host 192.168.0.25

@kdschlosser
Copy link
Owner Author

you need to run the RUN_ME.py file.

@kdschlosser
Copy link
Owner Author

@mlebrun

That error is a printout. it is a caught exception. I added some debugging to see what local IP addresses come up..

If you can do me a favor tho. and use the RUN_ME.py file. this is going to run a slew of tests on the TV.
I still need to update the command line portion of the library. but first thing is first. i need to get the core functioning properly then i will update the command line portion of the program.

.

@Kryzek
Copy link

Kryzek commented Mar 7, 2019

I did run the RUN_ME.py with python version 2.7.13 on linux, tests -folder zip is found on #106 (comment)
Running RUN_ME.py did not pop up authorization on tv screen, should I have seen it? On the ssdp_output.log there are some traces of the television (192.168.0.25).

Thank for your hard work from Finland.

@kdschlosser
Copy link
Owner Author

@Kryzek

sorry about that. I missed your post.

I need you to turn your TV on.
Then open your browser and go to this website.

http://192.168.0.25:7676/smp_14_

THIS PART IS IMPORTANT
after the page loads right click in the middle of the browser. there should be a menu option to view the page as source (or something to that effect). one that loads. copy all of the information you see in there.
paste the data into a text file and attach the file. please DO NOT paste it into a post here. it is going to be a lot of XML data. and it is gong to be easier to handle as a file.

@Kryzek
Copy link

Kryzek commented Mar 7, 2019

Hi, I checked and smp_14_ did not return anything, it is totally blank page.

I browsed through the ssdp_output.log and opened all the URIs with LOCATION": "http://192.168.0.25:7676/smp_xx -entries I found there.
Others smp_xx_:s returned XML-code which I copy-pasted to this file:
smp_sources.txt

@mlebrun
Copy link

mlebrun commented Mar 7, 2019

tests.zip
Here you go! You're doing great work! Let me know if there's any other way I can try and help!

@mlebrun
Copy link

mlebrun commented Mar 7, 2019

It seemed to get stuck on an HBO app?

@Kryzek
Copy link

Kryzek commented Mar 7, 2019

I tested also on Windows-environment and got better results:
tests-win.zip

@kdschlosser
Copy link
Owner Author

OK i just updated the develop branch

@Kryzek you need to accept the pairing on the TV when it asks.

@mlebrun I am hoping this change fixes the issue for the applications.

@mlebrun
Copy link

mlebrun commented Mar 7, 2019

○ → sudo python samsungctl/RUN_ME.py 
This is going to test the functionality of the TV.
It will log all tests to the screen as well as to a series of files.
The files will be located in /tests on your HDD. If you can please Zip
the contents of that folder and attach it to a post here

https://github.com/kdschlosser/samsungctl/issues/106

it would be appreciated

press any key to continue...



Traceback (most recent call last):
  File "samsungctl/RUN_ME.py", line 65, in <module>
    version=' '.join(version),
TypeError: sequence item 1: expected string, tuple found

It didn't make it that far this time? Let me know how to proceed, I'll try whatever you need!

@kdschlosser
Copy link
Owner Author

ahh yes a nested tuple..

I updated the develop branch. it has been fixed

@mlebrun
Copy link

mlebrun commented Mar 8, 2019

I think it might've failed around the same spot?

app.name: HBO GO
app.id: None
Traceback (most recent call last):
  File "samsungctl/RUN_ME.py", line 755, in <module>
    run_test(tests_to_run.pop(0))
  File "samsungctl/RUN_ME.py", line 699, in run_test
    print('app.is_runnning:', app.is_runnning)
  File "/Library/Python/2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/application.py", line 181, in __getattr__
    raise AttributeError(item)
AttributeError: is_runnning
Power Test Callback
name = Samsung TV Connector [be-dev40]
description = be-dev40
host = 192.168.1.222
port = 8001
id = 3bc39b1-b0ef-46c2-a647-4c77b1f2b4a
method = websocket
timeout = 0
token = None
upnp_locations = http://192.168.1.222:7676/rcr/, http://192.168.1.222:9197/dmr, http://192.168.1.222:7678/nservice/
paired = False
mac = e4:7d:bd:e4:b2:ef
model = UN40KU6300
app_id = None
uuid = 822f9294-0d1f-41ff-871b-05c623f9ece3
display_name = None
cec:
  None

state = True

tests.zip

@kdschlosser
Copy link
Owner Author

ha!

is_runnning

to many n's

@Kryzek
Copy link

Kryzek commented Mar 8, 2019

@Kryzek you need to accept the pairing on the TV when it asks.

I just do not get the authorization popup to accept on the television screen when running from the Linux (raspberry pi). I have tried with 2.7 and 3.5 -branch Pythons too. On Windows machine it showed popup right away.

Here is logs yet again from the Linux
tests.zip

@mlebrun
Copy link

mlebrun commented Mar 8, 2019

    Popular Now
'[DEBUG][4673746368] samsungctl.utils.wrapper
AppData.__init__(application=<samsungctl.application.Application object at 0x10c64b110>, title=u'2 Dope Queens', id=178955, appId=u'sE95AS5GGv.HboGoTizen', isPlayable=0, subtitle=None, appType=u'pxdb_app', liveLauncherType=u'', action_play_url=u'eyJjb21ldElkIjoidXJuOmhibzpzZXJpZXM6R1dpOEVDdzJGVW82VlBBRUFBQUZZIiwiZ29WMklkIjoidXJuOmhibzpzZXJpZXM6R1dpOEVDdzJGVW82VlBBRUFBQUZZIiwiZ29WMUlkIjoiR09ST1NUR1A3MTUzMiJ9', serviceId=u'', action_type=u'APP_LAUNCH', display_from=1517632200, display_until=1609498740, subtitle2=u'', subtitle3=u'', icon=u'/opt/usr/apps/DownloadManager/data/sE95AS5GGv/178955')

Traceback (most recent call last):
  File "samsungctl/RUN_ME.py", line 759, in <module>
    run_test(tests_to_run.pop(0))
  File "samsungctl/RUN_ME.py", line 718, in run_test
    print('       content.title:', content.name)
  File "/Library/Python/2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/application.py", line 496, in __getattr__
    raise AttributeError(item)
AttributeError: name
Power Test Callback
name = Samsung TV Connector [be-dev40]
description = be-dev40
host = 192.168.1.222
port = 8001
id = 42b4b62-d8ed-4c25-a60c-f31c7b8c73d
method = websocket
timeout = 0
token = None
upnp_locations = http://192.168.1.222:7676/rcr/, http://192.168.1.222:9197/dmr, http://192.168.1.222:7678/nservice/
paired = False
mac = e4:7d:bd:e4:b2:ef
model = UN40KU6300
app_id = None
uuid = 822f9294-0d1f-41ff-871b-05c623f9ece3
display_name = None
cec:
  None

state = True

tests.zip

@kdschlosser
Copy link
Owner Author

@mlebrun

fixed and pushed

@pavelbinar
Copy link

Error message after the pairing:

SETTING UP REMOTE CONNECTION
STARTING TV PAIRING PROCESS
Please enter pin from tv: 9938
192.168.1.224 -- (pin) 9938

Exception in thread Thread-5:
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/websocket_base.py", line 155, in loop
    if self.open():
  File "/usr/local/lib/python2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/utils.py", line 289, in wrapper
    result = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/remote_encrypted/__init__.py", line 184, in open
    output, last_request_id = self.hello_exchange(tv_pin)
  File "/usr/local/lib/python2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/utils.py", line 289, in wrapper
    result = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/samsungctl-0.8.65b0-py2.7.egg/samsungctl/remote_encrypted/__init__.py", line 363, in hello_exchange
    response = requests.post(self.url.step2, json=content)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'json'

I am also unable to kill the running process by ctrl+c


  • TV UE40JU6400
  • System: Mac OS X 10.14.6 (18G87) (I can test on Linux if needed)
  • Python version 2.7.16
  • tested code branch develop commit cdd3f239881e60a9c26043f3c7ff8cba42fb4aac
  • tests.zip

@ChrisKader
Copy link

I have made a lot of progress using https://smartthings.developer.samsung.com/docs/devices/smartthings-schema/schema-basics.html

I realized last week that the "SmartThings" app controls my TV with no issue. So I began to proxy traffic and use SSL Pinning to get an idea of whats going on.

Between that and the info on the "SmartThings" API site, I have reversed about 80% of the API and can successfully connect to my TV through a one time (persistent) PIN auth and control just about anything I want.

@caphm
Copy link

caphm commented Oct 3, 2019

I have made a lot of progress using https://smartthings.developer.samsung.com/docs/devices/smartthings-schema/schema-basics.html

I realized last week that the "SmartThings" app controls my TV with no issue. So I began to proxy traffic and use SSL Pinning to get an idea of whats going on.

Between that and the info on the "SmartThings" API site, I have reversed about 80% of the API and can successfully connect to my TV through a one time (persistent) PIN auth and control just about anything I want.

Do you have any code to work on? I'd love to contribute. Been trying to hunt down some documentation on how to interact with the 2018 TVs via the SmartThings protocol for ages, but never found anything.

@marius1968
Copy link

Hello,

it is possible to intercept the channel and volume change event callback ?
I am also interested in the Smart Thing functionality.

I have made a lot of progress using https://smartthings.developer.samsung.com/docs/devices/smartthings-schema/schema-basics.html

I realized last week that the "SmartThings" app controls my TV with no issue. So I began to proxy traffic and use SSL Pinning to get an idea of whats going on.

Between that and the info on the "SmartThings" API site, I have reversed about 80% of the API and can successfully connect to my TV through a one time (persistent) PIN auth and control just about anything I want.

Hello,

it is possible to intercept the channel and volume change event callback ?
I am also interested in the Smart Thing functionality

@tachang
Copy link

tachang commented May 10, 2020

@ChrisKader Did you have to decompile the apk and recompile with your own certificate to bypass the SSL pinning? I'm taking a look at the APK right now and it looks like there are a few certificates that need to be replaced.

Screen Shot 2020-05-09 at 8 08 49 PM

Wondering if you went down this route or another?

@kdschlosser
Copy link
Owner Author

kdschlosser commented May 10, 2020

OK guys. I can put some time into this bloody thing. However.. I do not want to hear anything about HASS. I will be more then happy to get this thing working properly I will not get it running in HASS that is going to be the job of someone else. I ill not modify code so that it works with HASS This can be done via monkey patching. I will get this running as a stand alone library and will be able to be used by any and all projects.

Now that this has been said. It is by far easier for me and faster if I have a TV to use so that I can test against. I can make changes as the problems appear. I personally do not have a need for another TV but for the sake of being able to develop for the thing it is going to be far easier if I have one. At the bottom of this post is a donate link you can use to help pay for this thing. If you do donate PLEASE type a message including your GitHub name This way I will add your name to the library as a contributor and you will forever be recorded as one of the people that made the library possible.

I really have no need to another TV and I would be more then happy to pass the thing off to whoever helps with development of the library once it is finished. If for some reason I am not able to finish the library I will send the TV to whomever is going to pick up where I left off. In this bat shit crazy world we live in right now if something was to happen to me I will leave instruction to my wife or family members to give you back your money. any moneys in excess of what is needed I will return each person that donated will get their "cut" of the excess up to the amount they donated.

I can get a 43" 8 series for 210.00USD which is not a horribly high priced TV. But if you all are feeling generous I can get a 55" Q900 8K for 1400.00USD. bear in mind that higher end TV's have more functionality the more functionality a TV has the more I will be able to add to the library. I can get just about any model for about 1/2 of what retail price is.

Because there is no API that has been publicly released for these TV's I am going to be doing quite a bit of data logging. I had written a really intensive debugging script that is able to handle multiple threads while keeping the logging output grouped together. It logs where a call is made from and where the call is made to providing me with the file names and line numbers for where the call originated from and where the call has been made to. It works on methods, functions, nested methods, nested functions, class level attributes, instance attributes, property gets, property sets and property deletes. It shows me the data being pass as arguments (if any) and also the data that is being returned (if any).

Most newer TV's have a debugging feature built into them that can be turned on. I will have to go back and lookup how to do this. This is something that is going to need to be done so that I am able to see what a TV is going. There seem to be some issues with the websocket-client library I do not know if these issues have been fixed or not. If they have not I will either write my own websocket connector or I may see if there is sone available that works. There are several websocket client libraries that are available so hopefully one of them should work properly.

If there is someone that has Python knowledge and is will to help out with this it would be greatly appreciated. The more brains working on this the the faster we will be able to get it working properly.

The largest issue that this library currently has is with the websocket TV's and properly detecting the power state. This is due to how Samsung TV's power down their LAN port. I have written a program that is able to leverage Windows to send out ARP requests without the need to be logged in as an administrator and also does not require starting a new process to do this. I have to take a look and see if there is a way to go about doing the same kind of a thing from posix systems. If there is then the use of a static IP on the TV and bouncing arp packets off the TV is going to be a way we can detect the power state of the TV, I did want to avoid using static IP's but because of the inconsistent nature of UPNP on Samsung TV's we may not be able to use a UPNP SSDP packet to do the discovery.

Most of the issues stem from Samsung's inconsistent API between the various models and years. I wanted to be able to provide a user with as much control as possibly but this may have to be put on the back burner or may not even be able to get done. I think the only way to properly go about adding the "extras" is going to be by making a table with TV model numbers letting us know what can and cannot be done. This is going to take a long while to compile and is going to only be able to be achieves through testing. so for the time being lets get the basics working properly.

I was also making my very best attempt to keep the API the same as with samsungctl. I am not going to do this anymore. This is due to the complexities for having 4 different connection types. We may not be able to go the auto detect method This is something I would really like to have available but it may not be possible. I am going to start over and create a new repository and work from the ground up. I have the ability to test against my TV which is a Legacy TV. I do have another Samsung TV that is an H model I believe. It is not a "smart" TV but it does have a LAN port on it. I am not sure if I will be able to do anything with it.

here is the donate link. make sure you tell me your Github username and also make sure you say this is for the Samsung TV. If I manage to get the library built fast enough I will be able to return the TV and give the money back.

https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MXZ2RLZRS8P9J&source=url

@MikeFleetwood
Copy link

Hi, I'm a complete Python noobie, so getting a bit lost trying to run your development code.
Just for background, I'm working on embedded firmware written in C to emulate the remote controls for Samsung TVs (other manufacturers to follow!). I have a working interface for H/J series TVs, skipped the next series as I don't have a TV to work with, and now working on M series (firmware 1280). I have working WSS connection, authorised by TV, but getting no response to commands. So, speed up the process, I though I'd try your interface to see if/how it works.

Anyway, I've downloaded the developer branch and open/run RUN_ME.py. In the console window I get a number of errors and it doesn't succeed in doing anything. Errors look like this:

Traceback (most recent call last):
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\RUN_ME.py", line 321, in
import samsungctl # NOQA
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl_init_.py", line 15, in
from .remote import Remote # NOQA
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\remote.py", line 7, in
from .remote_websocket import RemoteWebsocket
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\remote_websocket.py", line 12, in
from . import art_mode
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\art_mode.py", line 8, in
from .websocket_base import AuxWebsocketBase
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\websocket_base.py", line 28, in
from websocket import _abnf
ImportError: cannot import name 'abnf' from 'websocket' (C:\Users\Mike\AppData\Local\Programs\Python\Python37\lib\site-packages\websocket_init.py)

It would appear to be unable to import various modules - I'm sure I'm doing something very basic wrong - but what is it?

Many thanks,
Mike.

@kdschlosser
Copy link
Owner Author

the easiest way to get running is to run the setup.py file first. this will install all external libraries that are needed to get you up and running.

@MikeFleetwood
Copy link

Thanks - I'll give that a try!
As I say I'm not too familiar with Python. FYI, I'm using "Idle" on W10 - just in case that makes any difference :-)

@MikeFleetwood
Copy link

OK, looking better:

do you want to continue? (y/n)y

get_logger_name: samsungctl
get_logger_name: samsungctl.UPNP
TESTING DISCOVER
REGISTERING DISCOVER CALLBACK
DISCOVERING TV's
.Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Users\Mike\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\upnp\discover.py", line 266, in run
json.dumps(packet, indent=4)
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\utils.py", line 112, in call
msg = time.strftime(msg.format('%%x %%X'), time.localtime(time.time()))
KeyError: '\n "CACHE-CONTROL"'

.........
tests ran on the following TV's:
tests skipped on the following TV's:
STOPPING DISCOVER
CLOSING LOG FILES
FINISHED

Does this make any sense? It didn't seem to find the TV.
system.log
ssdp_output.3.7.log

@IDemixI
Copy link

IDemixI commented May 18, 2020

Hi @MikeFleetwood - Regarding your latest error: #116 (comment)
Making that change seems to fix it. It did for me! That should allow you to spit out some proper log files.

@kdschlosser - My apologies. I made a new issue without reading about attaching log files, etc. I've closed the issue (#135) and have attached my log files here. Progress was made using the dev branch. I've ran the RUN_ME script and have attached them. I'm still unable to send commands as I was able to on the original Ape version of samsungctl, unfortunately.

UE40KU6020 - Tests.zip

Edit: While running a simple python script (below) as a test I get the following:

Script:

#!/usr/bin/env python3

import samsungctl

config = samsungctl.Config(
    name='samsungctl',
    method='websocket',
    host='192.168.0.179',
    port='8001'
)

remote = samsungctl.Remote(config)
remote.KEY_MENU()
config.save('/home/pi/samsungtv.config')

Output:

get_logger_name: samsungctl.upnp.UPNP_Device
get_logger_name: samsungctl.upnp.UPNP_Device.adapter_addresses
get_logger_name: samsungctl.upnp.UPNP_Device.discover
get_logger_name: samsungctl.upnp.UPNP_Device.action
get_logger_name: samsungctl.upnp.UPNP_Device.icon
get_logger_name: samsungctl.upnp.UPNP_Device.service
get_logger_name: samsungctl.upnp.UPNP_Device.embedded_device
get_logger_name: samsungctl.upnp.UPNP_Device.upnp_class
get_logger_name: samsungctl.upnp.discover
get_logger_name: samsungctl.upnp
get_logger_name: samsungctl.wake_on_lan
get_logger_name: samsungctl.remote_legacy
get_logger_name: samsungctl.websocket_base
get_logger_name: samsungctl.art_mode
get_logger_name: samsungctl.application
get_logger_name: samsungctl.remote_websocket
get_logger_name: samsungctl.remote_encrypted.crypto
get_logger_name: samsungctl.remote_encrypted
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/dist-packages/samsungctl-0.8.65b0-py3.7.egg/samsungctl/websocket_base.py", line 155, in loop
    if self.open():
  File "/usr/local/lib/python3.7/dist-packages/samsungctl-0.8.65b0-py3.7.egg/samsungctl/utils.py", line 250, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/samsungctl-0.8.65b0-py3.7.egg/samsungctl/remote_websocket.py", line 221, in open
    return do()
  File "/usr/local/lib/python3.7/dist-packages/samsungctl-0.8.65b0-py3.7.egg/samsungctl/remote_websocket.py", line 215, in do
    raise RuntimeError('Unknown Auth Failure: \n' + str(self.config))
RuntimeError: Unknown Auth Failure:
name = samsungctl
description = Pi-hole
host = 192.168.0.179
port = 8001
id = 70654e4-13c9-4c5c-8c3f-1e583bb1cc9
method = websocket
timeout = 0
token = None
upnp_locations = None
paired = False
mac = None
model = None
app_id = None
uuid = None
display_name = None
// ****** CEC MUST REMAIN AT THE END OF THE FILE ******
cec:
//  name = SamsungTVCEC
//  port = RPI
//  types = 4,
//  power_off = 0
//  power_standby = 0
//  wake_avr = 0
//  keypress_combo = 113
//  keypress_combo_timeout = 50
//  keypress_repeat = 200
//  keypress_release_delay = 0
//  keypress_double_tap = 100
//  hdmi_port = 1
//  avr_audio = False

It hangs here indefinitely.

Also, regarding this "pairing" thing; I've never seen any pop-up on my TV and didn't on the last version either. Also using the Samsung SmartThings app I don't get any popups either, it simply finds my TV. I'm not sure my TV requires/has this.

Also, I'm got some experience in Python and coding in general. If there's anything you would like me to assist with I'm happy to give it a go. I'm sure I speak for a lot of people here when I say we really appreciate the work you've put in and continue to put into this library.

Many thanks!
Ryan

@kdschlosser
Copy link
Owner Author

It has been a while since I messed around with this library. it is going to take me a while to get myself back up to snuff on what I was doing with it. I am really thinking about scrapping it and starting from scratch.

@IDemixI
Copy link

IDemixI commented May 18, 2020

It has been a while since I messed around with this library. it is going to take me a while to get myself back up to snuff on what I was doing with it. I am really thinking about scrapping it and starting from scratch.

I totally understand that. As you've mentioned, you want to do things differently and as Ape appears to be completely gone, this will allow you full control over your own library and also put it on Pypi so people can install it without cloning etc. If you need a hand. please let me know. Even if it's just some debugging/testing you want me to do, I'm happy to do so!

My simple use-case for this entire thing is the fact that in the EU, all soundbars have an auto 15-minute shut-off which can't be disabled. I often pause TV or Netflix for longer than this then have to mess around switching the soundbar back on (HDMI CEC connected) and putting the volume back up which is a massive pain. I simply wanted to run a small python script every 10 minutes to send a key to the tv which hopefully would keep the soundbar alive. I can't really do this with the old version of the script as my TV decided to pop up a volume change icon which would be annoying every 10 minutes so I was looking at your library and the CEC related commands which may do the job for a silent kick in the butt to keep it alive. Sorry! Went of on a bit of a tangent there!

Cheers
Ryan

@MikeFleetwood
Copy link

Hi Ryan

My simple use-case for this entire thing is the fact that in the EU, all soundbars have an auto 15-minute shut-off which can't be disabled. I often pause TV or Netflix for longer than this then have to mess around switching the soundbar back on (HDMI CEC connected) and putting the volume back up which is a massive pain. I simply wanted to run a small python script every 10 minutes to send a key to the tv which hopefully would keep the soundbar alive. I can't really do this with the old version of the script as my TV decided to pop up a volume change icon which would be annoying every 10 minutes so I was looking at your library and the CEC related commands which may do the job for a silent kick in the butt to keep it alive. Sorry! Went of on a bit of a tangent there!
Cheers
Ryan

I suspect the soundbar shutdown is triggered by a period of silent audio, so you probably won't see anything useful on CEC. If it gets around to sending a "standby" to the TV, it will be too late to do anything about it. You might try sending it a periodic "power on" via CEC, but I doubt if that will make any difference. The only other possibility that I can think of is that it's responding to a "pause" control, in which case you could write something to capture that pause and every few minutes send "play" followed by "pause" until you detect either "play" or "stop", or some other user command that would mean you were watching again.
Sorry, there's not much else,
Mike.

@MikeFleetwood
Copy link

MikeFleetwood commented May 18, 2020

Hi @MikeFleetwood - Regarding your latest error: #116 (comment)
Making that change seems to fix it. It did for me! That should allow you to spit out some proper log files.

Hi Ryan, thanks for this. I did see that post, but assumed it had been superseded as it was a while ago - I'll give it a try.

Also, regarding this "pairing" thing; I've never seen any pop-up on my TV and didn't on the last version either. Also using the Samsung SmartThings app I don't get any popups either, it simply finds my TV. I'm not sure my TV requires/has this.
Also, I'm got some experience in Python and coding in general. If there's anything you would like me to assist with I'm happy to give it a go. I'm sure I speak for a lot of people here when I say we really appreciate the work you've put in and continue to put into this library.
Many thanks!
Ryan

I think that ever since models H/J there is no longer any "pairing". All there is is a pop-up "Allow/Deny" on the TV screen. Provided you continue to use the "token" provided by the TV on first connection you will never see that pop-up again. There's a setting on the TV "setup" that controls when, if ever, you see that message - it maybe you've got it set to "never", in which case connection will always be allowed with out user confirmation.
Many thanks,
Mike.

@MikeFleetwood
Copy link

Thanks to @IDemixI for the pointer to editing utils.py. RUN_ME ran perfectly this time. Pages of information to read through!
Basically, I'm trying to determine if my TV is accepting commands - if it is, then I've got something wrong in the code I'm developing. However if it doesn't respond to "Sansungctl" either, then it's a problem with the TV!

@MikeFleetwood
Copy link

I'm able to run RUN_ME.py to conclusion, but still get some messages that probably indicate errors.

There's still a few errors reported in the console output:445c9af7-e281-4300-a61d-ff506bac74d5.3.7.log, then it fails the KEY_VOLUP and KEY_VOLDOWN tests. Monitoring CEC output shows the remote mute operations (which pass, but use a different interface), but nothing on the volume controls.

Everything else seemed OK, although it didn't close the browser and power-off didn't work (I didn't expect it to ).

Here is the internal log file:samsungctl.445c9af7-e281-4300-a61d-ff506bac74d5.3.7.log I'm afraid I can't tell which are actual error conditions and which might just be handlers for errors that didn't occur (I see "ms.connect.unauthorized" there a couple of times).

When I first ran this, earlier today it passed the KEY_VOLUP/DOWN tests, so don't know why it should be different now - I'll try again shortly.

Any help would be appreciated - thanks!

@IDemixI
Copy link

IDemixI commented May 19, 2020

I suspect the soundbar shutdown is triggered by a period of silent audio, so you probably won't see anything useful on CEC. If it gets around to sending a "standby" to the TV, it will be too late to do anything about it. You might try sending it a periodic "power on" via CEC, but I doubt if that will make any difference. The only other possibility that I can think of is that it's responding to a "pause" control, in which case you could write something to capture that pause and every few minutes send "play" followed by "pause" until you detect either "play" or "stop", or some other user command that would mean you were watching again.
Sorry, there's not much else,
Mike.

Hi @MikeFleetwood,

Thank you for the suggestion. In the end I've gone with a slightly different approach. I had a spare Pi sat around so I've hooked it up directly to the USB port on my soundbar. From here I'm keeping an eye on the status of the device - I'm still working on it but I'm hoping I can set up some udev rules or use python select to detect when the device is switched on. From here the Pi will use LIRC to blast IR signals to the soundbar such as changing the mode to the same mode it's set to (soundbar still picks this up which is good). While writing this I've realised I can probably skip the USB bit altogether and just keep an eye on the status of the TV... checking if it's on or not. Haha, right, anyway that's the idea. IR it is!

Good luck with your project!

@kdschlosser
Copy link
Owner Author

@IDemixI

There are a few ways you can monkey around with your problem. One of the ways you are attempting to detect the power is partially correct.

You may want to plug your pi into one of the HDMI ports on the TV and install the libCEC library. Alot of Raspberry Pi's have a CEC chip built into them. You may be surprised that yours does. You can use cec and poll the soundbar to see if it is powered on.

The other way you can go about it is you would need to take a UBB cable and cut one of the ends off. you need to cut the end off that is not the end you would plug into the soundbar. You need locate the power and ground wires in the USB cable. these are typically going to be red and black if memory serves. You can look this up on the internet.

Connect the red wire to a GPIO pin and the black to a GND pin on the pie. You will then need a 10K ohm resistor and tie that from the red wire to GND as well. This resistor is going to act as a pull down resistor. So when the soundbar powers off and the USB power on the soundbar disappears the state of the USB is going to get pulled down to ground. This way on the PI you can check the GPIO and reliably tell if the soundbar is off or on.

@MikeFleetwood
Copy link

Hi.
Still struggling to get it to work. I embedded a lot of "print" statements to try to see what was going on (then stripped them out again in case I broke anything!). Here are the logging files
tests 22-05-2020 1038.zip
As far as I can see, despite clicking "Allow" on the TV, the connection doesn't not get authorised. This is a snippet from the console output (complete version in zipfile):

Exception in thread Thread-6:
Traceback (most recent call last):
File "C:\Users\Mike\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\Mike\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\websocket_base.py", line 155, in loop
if self.open():
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\utils.py", line 253, in wrapper
return func(*args, **kwargs)
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\remote_websocket.py", line 221, in open
return do()
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\remote_websocket.py", line 186, in do
res = do()
File "C:\Users\Mike\Documents\Projects\0761 aoip\kdschlosser samsungctl-develop\samsungctl-develop\samsungctl\remote_websocket.py", line 215, in do
raise RuntimeError('Unknown Auth Failure: \n' + str(self.config))

I've seen others report the same list of errors. Is it possible that one of the underlying library files is a non-compatible version? I guess I could just empty my "Python37\lib" folder then re-run setup.py. Or is there something else going on here?

The strange thing is, when I first ran RUN_ME, a couple of days ago, I'm pretty sure it all worked, despite the errors listed above still appearing. (in particular, the KEY_VOLUP/DOWN tests and the browser display did work, but no longer do) It's not worked since.

Any suggestions?

@FirasBayazed
Copy link

does anyone can tell me from where I can get complete service manual for samsung smart tv ue55nu8009?
thank you in advance

@kdschlosser
Copy link
Owner Author

kdschlosser commented Jun 10, 2020

while your TV is a Europe variant It should be the same as the US model except for the tuner and the model number. The US models have an operating input voltage of 100V - 260V or something along those lines. But all in all it should be damned close to being the same.

you can buy the manual (digital copy) for 12.00 USD

Even tho your TV ends in 8009 it is an 8000 series. the 8009 if because there is a "special" model number that is associated to the big box store where you bought it.
http://www.samsungparts.com/Products/Parts_and_Accessories/PID-SM-UN55NU8000F.aspx?model=UN55NU8000FXZA

@FirasBayazed
Copy link

thank you very much kdschlosser

@FirasBayazed
Copy link

@kdschlosser , so I have one question please if you could answer me , can I rest my samsung smart tv service menu to the original settings with this service manual pdf guide?

@kdschlosser
Copy link
Owner Author

If all you want to do is get into the service menu one of these procedures below will get you into it. it's kind of a pain to do sometimes. so you may have to try some of them more then once. Start at the bottom of the list because your TV is not horribly old. I have a C generation from 2011 I believe and it is method 2. yours being an N means it is newer and the list has the newist at the bottom.

  • Method 1: Put the TV into standby mode, turn off the TV with the remote control, then press the buttons on the remote control: “Info, Menu, Mute, Power”, then the TV turns on and displays the service menu.

  • Method 2: Turn off the power. On the remote control, press MUTE and then 1, 8, 2 and POWER

  • Method 3: When the TV is in standby mode, press DISPLAY, P.STD, MUTE, POWER on the remote control.

  • Method 4: When the TV is in standby mode, press SLEEP, P.STD, MUTE, POWER on the remote control.

  • Method 5: When the TV is in standby mode, press DISPLAY, MENU, MUTE, POWER on the remote control.

  • Method 6: On the remote control, press MUTE, then press 1, 1, 9 sequentially.

@FirasBayazed
Copy link

thank you @kdschlosser , I already know how to enter the service menu, but I need to check all the settings and options in the service menu, because I want to set them back to default status, because when I installed an app from the usb flash drive it has manubiulated with the service menu settings, so I want to check wich options or control settings has been changed to set them back to default values

@kdschlosser
Copy link
Owner Author

OoOo There should be a reset in the service menu I would think. I do not know if the service manual is going to tell you what all of the default options are.

@doff-1
Copy link

doff-1 commented Nov 21, 2021

theres been 38 participants in this thread, so I take it at some point in time there's been almost 40 people interested in getting this to work. If only 10 of us donate 20$ it should be possible for @kdschlosser to buy a new tv, and continue development if he's interested.
I definetly would be willing to donate again to get this project back up and running! Is there more people out there willing to donate?

This is the only tool I've found which states it can change brightness, and it would be awesome to have MadVR run samsungctl on some profiles to change settings on the tv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests