kdschlosser / samsungctl

Remote control Samsung televisions via a TCP/IP connection
MIT License
155 stars 33 forks source link

Testing the timeout fix #2

Closed aseabridge closed 5 years ago

aseabridge commented 6 years ago

Thanks for putting in a fix for the timeout @kdschlosser. I can see you’ve added the LG logging to the file. To test this with my 2017/2018 tv I’m guessing I’ll need to checkout this timeout branch and call the method. What command should I issue? When I tried using this library earlier today diectlty it was giving me errors about bytes so I’m guessing I was missing some parameters.

eclair4151 commented 6 years ago

so yea you will need to checkout this branch git checkout --track origin/timeout_fix

then try to run this python command

import samsungctl

config =  {
        "name": "samsungctl",
        "description": "PC",
        "id": "11",
        "host": "YOUR IP",
        "port": 8002,
        "method": "websocket"
    }

with samsungctl.Remote(config) as remote:
    remote.control("KEY_PLAY")
kdschlosser commented 6 years ago

tanks @eclair4151

fluxdigital commented 6 years ago

Thanks. I'm not sure if I'm doing something wrong but I checked out that branch. Then saved the phython above as test.py and then ran it in Thonny. I got the following:

Python 3.5.3 (/usr/bin/python3)
>>> %Run test.py
Traceback (most recent call last):
  File "/home/pi/Documents/Samsungcti-test/test.py", line 12, in <module>
    with samsungctl.Remote(config) as remote:
  File "/home/pi/.local/lib/python3.5/site-packages/samsungctl/remote.py", line 10, in __init__
    self.remote = RemoteWebsocket(config)
  File "/home/pi/.local/lib/python3.5/site-packages/samsungctl/remote_websocket.py", line 22, in __init__
    self._serialize_string(config["name"])), config["timeout"])
KeyError: 'timeout'
>>> 
kdschlosser commented 6 years ago

use this instead.

import samsungctl

config =  {
    "name": "samsungctl",
    "description": "PC",
    "id": "11",
    "host": "YOUR IP",
    "port": 8002,
    "method": "websocket",
    "timeout": 5
}

with samsungctl.Remote(config) as remote:
    remote.control("KEY_PLAY")
fluxdigital commented 6 years ago

Hmm so I checked my tv is on and on the network and ran a scan to check the ip is correct. Then I ran the script above and get this:

>>> %Run test.py
Traceback (most recent call last):
  File "/home/pi/Documents/Samsungcti-test/test.py", line 13, in <module>
    with samsungctl.Remote(config) as remote:
  File "/home/pi/.local/lib/python3.5/site-packages/samsungctl/remote.py", line 10, in __init__
    self.remote = RemoteWebsocket(config)
  File "/home/pi/.local/lib/python3.5/site-packages/samsungctl/remote_websocket.py", line 22, in __init__
    self._serialize_string(config["name"])), config["timeout"])
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_core.py", line 487, in create_connection
    websock.connect(url, **options)
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_core.py", line 214, in connect
    self.handshake_response = handshake(self.sock, *addrs, **options)
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_handshake.py", line 69, in handshake
    status, resp = _get_resp_headers(sock)
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_handshake.py", line 127, in _get_resp_headers
    status, resp_headers = read_headers(sock)
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_http.py", line 226, in read_headers
    line = recv_line(sock)
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_socket.py", line 101, in recv_line
    c = recv(sock, 1)
  File "/home/pi/.local/lib/python3.5/site-packages/websocket/_socket.py", line 93, in recv
    "Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
>>> 
DJPsycho82 commented 6 years ago

I'm struggling a while with samsungctl. I'm pretty new with python and not a programmer for work. But I can read most of the code without problems. I want to help fixing this issue. I own a Samsung TV Q7F 2017 model. I run the 'program' samsungctl on a Raspberry pi. When i run the program i get the following output :

{ "data": { "id": "5c786543-cfc2-4820-8a4f-d323113c78dc", "token": "17223081", "clients": [ { "attributes": { "name": "c2Ftc3VuZ2N0bA==" }, "connectTime": 1543258140926, "deviceName": "c2Ftc3VuZ2N0bA==", "id": "5c786543-cfc2-4820-8a4f-d323113c78dc", "isHost": false } ] }, "event": "ms.channel.connect" } Error: Permission denied

Looks like there is something going wrong with the Token but i'm not sure how to solve it. What am i doing wrong or could i test some code to fix this?

DJPsycho82 commented 5 years ago

Also nice to know, samsung isn't using smart view for their new tv's. They use smart things now to control the equipment they sell. I only own a TV. But i can check tonight if the smart things app sends some usefull information to the tv. I am not a star with wireshark, but i can try :)

sebdbr commented 5 years ago

Hello ! Before the upgrade to the 1250 firmware, I was able to control my Samsung TV with samsungctl through Domoticz. Since I've download the new remote_websocket.py file, there isn't error messages anymore when I try a samsungctl command, but I obtain a "permission denied" even if I select "authorise" on my TV. I guess I have to create a token.txt file somewhere, but I don't know exactly where, and I can't find how to obtain this token... I tried to access to the "wss://@tvip:8002/..." as mentioned sooner with several browser, but I have no response from the TV... I need some help... Thanks for reading !

kdschlosser commented 5 years ago

I am working on the issue. I do not own a TV to be able to test with. I am going to set up a slack account for this repo. maybe someone would be willing to forward a few ports so I can have access to the TV. it would greatly speed up the development process not having to do the whole back and forth thing.

adding would be so the IP can be sent to me. if there is anyone willing to do this for me let me know. At the same time I will also check remote button press responses and see if i can possibly leverage the TV to give me some other information/control as well. I am pretty sure I can get volume change notifications from the TV. and possibly channel change and input change. But i need to have access to the TV. after initial access I will request a few more ports be forwarded. but the ports I will not know until i connect with the TV

eclair4151 commented 5 years ago

I’m going to do some testing on my M series In about 40 min when I get home from work :)

kdschlosser commented 5 years ago

here is an invite link for the slack chat. the link is only good for a single day.

https://join.slack.com/t/samsungtvcontrol/shared_invite/enQtNDg5NTgzMDIxMjgyLTg0Y2MzZmY1OGU2NzQ1NjdiNGI5YTkxMjczOTRjMTcyM2MyMTM3YWI5ZTNlNjc5NTcwYTlmNDBhZmM4ZjA4MTY

kdschlosser commented 5 years ago

@eclair4151 if you will be home in 40 minutes. join that slack chat. we can hash this thing out collectively.

I know that the TV is capable of doing more over that web scoket we simply need to find out what exactly.

I am going to write a version of the code that handles the socket connection differently. I want to keep the connection open in a manner that will allow for all messages to come in from the TV at any time, the websocket library has the ability to do this via the WebSocketApp class.

kdschlosser commented 5 years ago

ok so I wanted to let you all know where I am at.

I still have not gotten a full test result as far as the websocket thing goes.

I have however managed to extend the functionality of the package to include.

getting:
    brightness
    contrast
    color temp
    color
    sharpness
    mute
    volume
    channel
    source
    channel info
    channel list
    source list
    media playback position
    media info
    dtv info
    channel list
    current program information
    detail channel information
    detail program information
    extended information about what options the TV has

all of the below are direct input meaning you will be able to set the volume to 20 or 30 or 50 or whatever you want directly

setting
    brightness
    contrast
    color temp
    color
    sharpness
    mute
    volume
    channel
    source
    media position

My TV is an older one. But I am sure these will all work with a newer TV a guy I know tested a few of them with success.

It is going to be a very large amount of code that has to be added to support all of the above, I can do it in a dynamic nature which on the back end of it I am. But I am going to hard code most of the interface. this way it is IDE compatible and not a complete mystery how to use.

But I bet you will all like to see volume the current volume or channel data in your favorite HA program eh??

Once I am done with it will be up to you to get the authors of those programs to add that functionality. I am keeping the current API in tact so the package will function as it did before. I am just extending onto it.

I have sorted the issues with the discovery process which is a +

sebdbr commented 5 years ago

Breaking news : In fact it seems to work properly if I run it as a sudoer ("sudo samsungctl -i --host xxx.xxx.xxx.xxx --port 8002 --method websocket --timeout 10")... Now it remains to make it work through Domoticz... to be continued.

sebdbr commented 5 years ago

Good news. I'm able again to control the volume through domoticz ... It remains to adapt the keys. For now, I can't turn the tv off. I have a post 2016 ue49mu6105k model ... Do you think I need to edit the interactive.py file?

DJPsycho82 commented 5 years ago

Yesterday my router died, so had something else to do ;) But i'm online again. Can i test the lastest code? Not sure which one to clone though...

DJPsycho82 commented 5 years ago

I can confirm though that executing the samsungctl with sudo works! I tried it with the old version, but not yet with the version couple of days ago. After 1 button press it stops working though, have to CTRL+C the program and start it again for the next command. Just figured out that also without the Sudo it works now. Not sure why ....

kdschlosser commented 5 years ago

well it is good to know that it is in fact working to some extent. so we know the solution is viable. just have to work out some of the bugs.

I have the back end for the added controls finished up. I am adding the methods at this point. from what I am gathering you should be able to do things like change the playing content that is on a USB getting playing content meta data. all kinds of things. there are over 100 different things that can be changed/manipulated.

I am looking for that one single things that will tell me what the firmware version is or something to that effect. it will make the selection of using ssl or not much easier. instead of a try and if it fails then do something else routine.

eclair4151 commented 5 years ago

Did you see my comment on slack? I think I have found a good way to detect to use ssl or not

kdschlosser commented 5 years ago

I did want to post my progress. I now have a plethora of output from the TV. all kinds of goodies.

track_count: 0
media_duration: 0:00:00
media_uri: None
media_metadata: None
playback_device: NETWORK,NONE
record_device: NOT_IMPLEMENTED
write_status: NOT_IMPLEMENTED
state: NO_MEDIA_PRESENT
status: OK
speed: 1
position_info: {
    'absolute_time': '0:00:00',
    'absolute_count': 2147483647,
    'relative_count': 2147483647,
    'relative_time': '0:00:00',
    'track_uri': None,
    'track_metadata': None,
    'track_duration': '0:00:00',
    'track_number': 0
}
device_capabilities: [
    'NETWORK,NONE',
    'NOT_IMPLEMENTED',
    'NOT_IMPLEMENTED'
]
brightness: 100
contrast: 100
sharpness: 55
color_temperature: 3
protocol_info: {
    'source': None,
    'sink': [
        'http-get:*:image/jpeg:*',
        'http-get:*:audio/mpeg:*',
        'http-get:*:video/x-msvideo:*',
        'http-get:*:video/x-ms-asf:*',
        'http-get:*:video/x-divx:*',
        'http-get:*:video/x-ms-wmv:*',
        'http-get:*:video/x-mkv:*',
        'http-get:*:video/mp4:*',
        'http-get:*:video/x-avi:*',
        'http-get:*:video/avi:*',
        'http-get:*:video/x-flv:*',
        'http-get:*:video/mpeg:*',
        'http-get:*:video/3gpp:*',
        plus 158 more
    ]
}
x_audio_selection: None
x_video_selection: None
banner_information: None
channel_list: {
    'sort': None,
    'satellite_id': None,
    'channel_list_type': '0x02',
    'version': 19,
    'channel_list_url': 'http://192.168.1.64:9090/BinaryBlob/3/ChannelList.dat',
    'supported_channels': []
}
source_list: [
    {
        'is_label_editable': False,
        'is_connected': True,
        'id': 0,
        'viewable': True,
        'name': 'TV'
    },
    {
        'viewable': False,
        'name': 'PC',
        'is_label_editable': True,
        'label': 'PC',
        'is_connected': True,
        'id': 67
    },
    {
        'viewable': False,
        'name': 'DLNA',
        'is_label_editable': False,
        'device_name': 'HDHomeRun DMS 131F777B',
        'is_connected': True,
        'id': 23
    },
    {
        'viewable': True,
        'name': 'HDMI1/DVI',
        'is_label_editable': True,
        'label': 'HDMI1/DVI',
        'is_connected': False,
        'id': 71
    },
    {
        'viewable': True,
        'name': 'HDMI2',
        'is_label_editable': True,
        'label': 'HDMI2',
        'is_connected': False,
        'id': 72
    },
    {
        'viewable': True,
        'name': 'HDMI3',
        'is_label_editable': True,
        'label': 'HDMI3',
        'is_connected': False,
        'id': 73
    },
    {
        'viewable': True,
        'name': 'HDMI4',
        'is_label_editable': True,
        'label': 'HDMI4',
        'is_connected': False,
        'id': 74
    },
    {
        'viewable': False,
        'name': 'AV1',
        'is_label_editable': True,
        'label': 'AV1',
        'is_connected': False,
        'id': 55
    },
    {
        'viewable': False,
        'name': 'AV2',
        'is_label_editable': True,
        'label': 'AV2',
        'is_connected': False,
        'id': 56
    },
    {
        'viewable': True,
        'name': 'COMPONENT',
        'is_label_editable': True,
        'label': 'COMPONENT',
        'is_connected': False,
        'id': 63
    },
    {
        'is_label_editable': False,
        'is_connected': False,
        'id': -1,
        'viewable': False,
        'name': 'USB'
    }
]
source: {
    'is_label_editable': False,
    'is_connected': True,
    'id': 0,
    'viewable': True,
    'name': 'TV'
}
channel: {
    'channel_type': 'CATV',
    'program_number': 0,
    'ptc': 6,
    'major': 6,
    'minor': 0
}
program_information_url: http://192.168.1.64:9090/BinaryBlob/4/CurrentProgInfo.dat
current_time: None
schedule_list_url: http://192.168.1.64:9090/BinaryBlob/0/ScheduleList.dat
watching_information: {
    'information': None,
    'tv_mode': 'Tuner'
}
mute: False
volume: 50
year: 2011
region: USA
tuner_count: 1
dtv_support: True
pvr_support: False

so now we can get notification if anything on the TV changes. woo yah! I am able to set the channel and volume all the things I stated.

kdschlosser commented 5 years ago

ok here is the version I have been working on. if you run the example.py file it will run a series of tests and print out a whole mess of data. if you would be willing to copy and paste that data to me I will be able to make sure that everything is working properly. This is still very experimental. it is going to have some hiccups.

https://github.com/kdschlosser/samsungctl/tree/upnp_features

sebdbr commented 5 years ago

When I try to "git clone" the repositories, I have no UPNP directory, nor example.py file...

eclair4151 commented 5 years ago

Make sure you checkout the correct branch

fluxdigital commented 5 years ago

Thanks @kdschlosser. I've tried git clone but get an error for some reason. I can git clone the main branch fine but just not this one. not sure why? I uninstalled git and reinstalled it but still no joy. This is the error I get:

pi@raspberrypi:~ $ cd /home/pi/Documents/Samsung-check
pi@raspberrypi:~/Documents/Samsung-check $ git clone https://github.com/kdschlosser/samsungctl/tree/upnp_features
Cloning into 'upnp_features'...
fatal: repository 'https://github.com/kdschlosser/samsungctl/tree/upnp_features/' not found
fluxdigital commented 5 years ago

Yeah just tried on my laptop too, the above was on my pi. And I get the same issue.

eclair4151 commented 5 years ago

try git clone https://github.com/kdschlosser/samsungctl.git git checkout upnp_features

eclair4151 commented 5 years ago

when i run it i get

Traceback (most recent call last):
  File "/Users/tomershemesh/PycharmProjects/samsungctl_branch/samsungctl/example.py", line 41, in <module>
    for tv in remote.discover(5):
  File "/Users/tomershemesh/PycharmProjects/samsungctl_branch/samsungctl/upnp/discover.py", line 146, in discover
    for item in socket.getaddrinfo('', None, socket.AF_INET):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 743, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
fluxdigital commented 5 years ago

Still no luck I'm afraid, it can't find the branch:

pi@raspberrypi:~/Documents/Samsung-check $ git clone https://github.com/kdschlosser/samsungctl.git
Cloning into 'samsungctl'...
remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 483 (delta 21), reused 27 (delta 3), pack-reused 426
Receiving objects: 100% (483/483), 114.06 KiB | 97.00 KiB/s, done.
Resolving deltas: 100% (267/267), done.
pi@raspberrypi:~/Documents/Samsung-check $ git checkout upnp_features
fatal: Not a git repository (or any of the parent directories): .git
pi@raspberrypi:~/Documents/Samsung-check $ sudo git checkout upnp_features
fatal: Not a git repository (or any of the parent directories): .git
pi@raspberrypi:~/Documents/Samsung-check $ 
fluxdigital commented 5 years ago

Actually looks like I just needed to cd up to the SamsungCtl folder and then switch branch. Ran the discover.py file and get this:

>>> %Run discover.py
Traceback (most recent call last):
  File "/home/pi/Documents/Samsung-check/samsungctl/samsungctl/upnp/discover.py", line 196, in <module>
    for f_device in discover(10):
  File "/home/pi/Documents/Samsung-check/samsungctl/samsungctl/upnp/discover.py", line 146, in discover
    for item in socket.getaddrinfo('', None, socket.AF_INET):
  File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
kdschlosser commented 5 years ago

ok the error socket.gaierror: [Errno -2] Name or service not known

is a dns resolver issue.. This can be caused by one of 2 things. and I will see if i can correct on my end. when i enumerate all of the available IP's in the network stack i pass '', None and the protocol. in this case IPV4

socket.getaddrinfo('', None, socket.AF_INET)

the doct state to pass None and None. but when I do this on Windows the program crashes. I wonder if changing it to None and None on linux will cause it to function properly. If it does then this is actually a bug in Python. it is one that I can band-aide.

so if you change line 146 in upnp/discover.py from

for item in socket.getaddrinfo('', None, socket.AF_INET):

to this

for item in socket.getaddrinfo(None, None, socket.AF_INET):

see if that corrects that issue. If it does not then there is something wrong with the network stack on your Linux installation. specifically the DNS resolver portion of the stack. something wrong with the hosts file possibly.

this error

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

seems to be a MAC specific problem and is a bug in python. It looks as tho I am going to have to find a different mechanism to enumerate the network adapters. This I do not know how to do.

The reason for this is that by design python sockets will always bind to the first network stack in the binding order. when sending out an SSDP packet since it is a broadcast it has to be sent out on that specific adapter. so if you have 2 network interfaces in your coumputer with 2 different network subnets and the TV is located on the network of the address listed second in the binding order the package would never locate it. since I have obtained the IP address of the TV the computers OS will handle binding to the proper address to be able to connect to that IP. but with broadcasts i have to manually bind the address. which is what the getaddrinfo is there for. it is supposed to return all of the IPV4 addressed on the local machine.

Now on the mac it could be the same issue as with linux. so if you want to give it shot follow the instruction above for the linux and see if it works, if it does then it is a simple thing to band-aide.

kdschlosser commented 5 years ago

please be sure to have requests installed if you are not running setup.py as well. there is that single additional requirement that i did add.

kdschlosser commented 5 years ago

this weekend I will spend some time and do a reinstall on my workstation. I need to change out my HDD. I have no more space. Once i do that I will install a VM with Linux on it for testing. I will also dust off my old macbook and hack the latest OSX onto it this way I will be able to test better. at the moment I am limited to testiing in Windows.

fluxdigital commented 5 years ago

I changed the line on 146 to: for item in socket.getaddrinfo(None, None, socket.AF_INET):

However I still get the same error on my pi.

I may be missing something though, I'm not sure what you meant by 'please be sure to have requests installed if you are not running setup.py as well. there is that single additional requirement that i did add.'

kdschlosser commented 5 years ago

requests is a python package, the issue you are running into has nothing to do with requests so do not worry about it for the time being. chances are you probably already have the requests python package installed. we can cross that bridge if we get there

I have updated that branch hopefully with the fix. I do not create any kind of a subprocess and parse the output to get the addresses. I think that is a hack way of going about it but it seems to be the accepted way to do it. so I decided to grab the bull by the cojones and going directly to the OSX, Linux and Windows API with ctypes to enumerate the local addresses. I am hoping it works.

fluxdigital commented 5 years ago

Thanks Kevin, I checked out the branch again and pulled it but I get this error now. Am I missing some dependencies?:

Python 3.5.3 (/usr/bin/python3)
>>> %cd /home/pi/Documents/Samsung-new/samsungctl/samsungctl/upnp
>>> %Run discover.py
Traceback (most recent call last):
  File "/home/pi/Documents/Samsung-new/samsungctl/samsungctl/upnp/discover.py", line 437, in <module>
    for f_device in discover(10):
  File "/home/pi/Documents/Samsung-new/samsungctl/samsungctl/upnp/discover.py", line 279, in discover
    from . import UPNPTV
SystemError: Parent module '' not loaded, cannot perform relative import
>>> 
kdschlosser commented 5 years ago

easiest thing to do would be to install it.

python setup.py install

then use this script to run it

from samsungct import example

and that should be all there is to it. I may have to update a few other things in it first tho. i will take a look at it in a few minutes

fluxdigital commented 5 years ago

Thanks. I've tried that but get the following issue. I'm probably missing something here:

pi@raspberrypi:~/Documents/Samsung-new/samsungctl $ sudo python3 setup.py install
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    import samsungctl
  File "/home/pi/Documents/Samsung-new/samsungctl/samsungctl/__init__.py", line 11, in <module>
    from .remote import Remote
  File "/home/pi/Documents/Samsung-new/samsungctl/samsungctl/remote.py", line 2, in <module>
    from .upnp.discover import discover
  File "/home/pi/Documents/Samsung-new/samsungctl/samsungctl/upnp/__init__.py", line 545, in <module>
    from samsungctl.remote_websocket import RemoteWebsocket
  File "/home/pi/Documents/Samsung-new/samsungctl/samsungctl/remote_websocket.py", line 54, in <module>
    class RemoteWebsocket(WebSocketApp):
NameError: name 'WebSocketApp' is not defined
pi@raspberrypi:~/Documents/Samsung-new/samsungctl $
kdschlosser commented 5 years ago

I wonder why it is not installing the requirements. i will take a look at that bit of it. that is original and I have not changed it at all.

Murph24 commented 5 years ago

@kdschlosser @fluxdigital

Not sure on this but check the "extras_require" in setup.py. The websocket-client library is optional as it not needed for "legacy". Not sure on the exact syntax, but its something like: pip install samsungctl[websocket]

This will cause the websocket-client library to be installed

kdschlosser commented 5 years ago

yeah I am going to move that to the requirements. more people have the newer style TV's

One other thing. The library is not going to work at the moment. I got a person that has a newer TV to give me a UPNP discover on their network. and the newer TV's use a whole different set of classes. I am currently in the process of changing the package. I also should be able to expand the functionality because of this. The way that I wrote the UPNP portions of the package were done in a specific way. So that I would be able to add any additional classes very easily. the whole thing is dynamic in nature. I should have a working version by tomorrow.

kdschlosser commented 5 years ago

ok so I made a new library specifically for scanning the network for UPNP devices. which is the mechanism that is going to open the dorrs to controlling the TV and getting notifications from it as well.

I still need to get the data from a newer TV. I have not gotten that yet. This library will make it easier

https://github.com/kdschlosser/UPNP_Device

it requires requests and also six

pip install requests pip install six

and place the above package into you site-packages folder.

change the FILEPATH to where ever you can save to. and attach the file to a post. zip it up first tho.

FILEPATH = r'C:\Users\Administrator\Desktop\UPNP.log'

import logging
from UPNP_Device import discover

with open(FILEPATH, 'w') as f:
    f.write('')

for device in discover(3, logging.DEBUG):
    data = str(device)
    with open(FILEPATH, 'a') as f:
        f.write(data)
        f.flush()

    print(data)
mike9011 commented 5 years ago

I still need to get the data from a newer TV. I have not gotten that yet. This library will make it easier

Can i help you with something? I have a 2018 model (Q8FN).

kdschlosser commented 5 years ago

you know how to work your way around python??

mike9011 commented 5 years ago

Hmm i'm not an advanced user, but if it's not too difficult it must succeed.

gooman-uk commented 5 years ago

I have a UE50MU6120. If you need data from that, I can do it at the weekend - let me know if it's needed. D> On Wednesday, 5 December 2018, 00:13:59 GMT, Kevin Schlosser notifications@github.com wrote:

ok so I made a new library specifically for scanning the network for UPNP devices. which is the mechanism that is going to open the dorrs to controlling the TV and getting notifications from it as well.

I still need to get the data from a newer TV. I have not gotten that yet. This library will make it easier

https://github.com/kdschlosser/UPNP_Device

it requires requests and also six

pip install requests pip install six

and place the above package into you site-packages folder.

change the FILEPATH to where ever you can save to. and attach the file to a post. zip it up first tho. FILEPATH = r'C:\Users\Administrator\Desktop\UPNP.log'

import logging from UPNP_Devices import discover

with open(FILEPATH, 'w') as f: f.write('')

for device in discover(3, logging.DEBUG): data = str(device) with open(FILEPATH, 'a') as f: f.write(data) f.flush()

print(data)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

mike9011 commented 5 years ago

I've tried the UPNP discovery tool, but it doesn't find my Samsung TV (on the same lan). Is there any way to force the script to a specifik IP address?

msvinth commented 5 years ago

I also tried the UPNP tool and also it did not find my Samsung TVs (2017 & 2018 models). Found all my Sonos devices but no TVs.

kdschlosser commented 5 years ago

It could be that the newer TV's do not respond to discovery packets. I am going to add a means to enter the IP of the TV. we can see if this will force a response from it if they are sent directly to the TV. (my router functions in this exact same manner) . Maybe that will instigate a response from the TV.

kdschlosser commented 5 years ago

OK I added the ability to use an IP address to search for in the UPNP_Device library I made. The FILEPATH is set to create a file on the desktop for a Windows user the filename is UPNP_DEVICE_OUTPUT.log

You can change the FILEPATH to whatever it is you like. change the TV_IP_ADDRESS to the IP of your TV. and this way we can see if it responds.

from __future__ import print_function
import os
import UPNP_Device
import logging

TV_IP_ADDRESS = '0.0.0.0'
FILEPATH = r'%USERPROFILE%\Desktop\UPNP_DEVICE_OUTPUT.log'
FILEPATH = os.path.expandvars(FILEPATH)

with open(FILEPATH, 'w') as f:
    for device in UPNP_Device.discover(10, logging.DEBUG, TV_IP_ADDRESS):
        data = str(device)
        print(data)
        f.write(data)
kdschlosser commented 5 years ago

I do have some pretty cool news tho.. I will be able to tie in Samsung Soundbars into this library as well.