Ape / samsungctl

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

Some TV models request authorization again after every reboot #16

Open thefrenchmatt opened 8 years ago

thefrenchmatt commented 8 years ago

Dear @Ape ,

based on this library, home-assistant.io requests a new connection each time but it seems some models should be able to remember the host based on MAC address.

Could you be so kind as to add an optional conf variable for it?

I found a practical example that may help here : http://deneb.homedns.org/things/?p=232

Ape commented 8 years ago

It's currently possible to keep the connection open and send multiple control messages. I don't see how the MAC address helps here. What is your use case here?

thefrenchmatt commented 8 years ago

Yes but as soon as the tv or server is turned off, access is requested again. This does not happen for DNLA servers or a mobile devices (incl. Apps started from those). So I'm looking for a way to pass the MAC Adress and home-automation.io uses your work, so I guessed best to ask you (:

Ape commented 8 years ago

Hmm. It doesn't request for the access again after rebooting on the models I have tested. But different models may behave differently.

Should sending the MAC address fix this? I would be happy to fix the behavior, but I cannot test it myself. Feel free to play with the source code and please send me a pull request if you get it working better.

thefrenchmatt commented 8 years ago

My skills are not that advanced but I will surely try comparing your code with the link I initially attached.

jviyer commented 8 years ago

I get this error: when I run the program. I called samsungct as follows:

samsungctl --host 192.168.1.6 --name samsungctl KEY_MUTE Traceback (most recent call last): File "/usr/local/bin/samsungctl", line 9, in <module> load_entry_point('samsungctl==0.5.1', 'console_scripts', 'samsungctl')() File "/usr/local/lib/python2.7/dist-packages/samsungctl/__main__.py", line 99, in main with Remote(config) as remote: File "/usr/local/lib/python2.7/dist-packages/samsungctl/remote.py", line 38, in __init__ self._read_response(True) File "/usr/local/lib/python2.7/dist-packages/samsungctl/remote.py", line 70, in _read_response tv_name_len = int.from_bytes(header[1:3], My conf is as follows: { "name": "samsungctl", "description": "PC", "id": "", "port": 55000, "timeout": 0

}

Ape commented 8 years ago

@jviyer You need to use Python 3. E.g. pip3 install samsungctl

jviyer commented 8 years ago

Thanks a lot ! That was the issue.

On Monday, August 8, 2016 2:11 AM, Lauri Niskanen <notifications@github.com> wrote:

@jviyer You need to use Python 3. E.g. pip3 install samsungctl— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Upas commented 7 years ago

@Ape Thanks for an amazing lib. I have faced the re-authorization issue as well. Having the MAC address in the request seems to solve the issue. I have modified the remote_legacy.py code to include mac address, like so

` payload = b"\x64\x00" \

PS: very new to github. I tried a few times but wasn't sure how to use the pull request i have created a pull request with the changes now Cheers!

Ape commented 7 years ago

@Upas Thanks for the pull request #24. Does it matter what is inserted as the MAC address? Should it be the PC or TV address?

Upas commented 7 years ago

I apologize. I might have gotten too excited to have found a fix. But in retrospect no additions are needed, the additional "mac" item can be left out. This can still be made to work with just the 3 parameters in the string serialize.

Some findings i have made from testing on my TV are listed below. Based on your existing payload string: `payload = b"\x64\x00" \

  1. "description" - should ideally be the IP address of the device (can be any thing, no enforcement here). This is not affected by change across sessions.
  2. "id" - should ideally be the MAC. Again no enforcement. This value can be anything, BUT should remain constant across sessions. If it is changed TV will ask for re-auth.
  3. "name" - Is the name of the remote. This remains as is and is also not affected by change across sessions.

So i guess the short is - a little clean up of naming of the payload components and the example should clear this up for all the folks having re-auth issues.

I have modified payload in remote_legacy.py as follows: `payload = b"\x64\x00" \

and config like so: { "ip": "192.168.0.2013", # ideally should be the IP of the device, but you can use anything "mac": "mac:address:1", "name": "Python Remote1",

    "host": "192.168.0.101",
    "port": 55000,
    "method": "legacy",
    "timeout": 0

}

pedrinho commented 7 years ago

Setting "mac" and "ip" solved my problem with re-authentication on every restart on my UN40F5500 TV.

BTW @Ape thanks so much on lib, I'm using it on https://github.com/pedrinho/samsung_remote

adeeltahir98 commented 4 years ago

How to solve this re-authentication problem using websockets method instead of legacy ?