home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.07k stars 31.09k forks source link

Using TP Link router as tracking device not possible from version 0.5x #9120

Closed dimitripb closed 5 years ago

dimitripb commented 7 years ago

Home Assistant release (hass --version): 0.51.2

Python release (python3 --version): 3.4.2

Component/platform: TP Link router as Device Tracker

Description of problem: The TP Link Router TL-WR1043ND v1 cannot be configured as a tracking device. After adding the right entries to configuration.yaml I get error messages which end with the message: "Connection reset by peer". I am sure I am not logged in already and I am sure the credentials are correct Another HA user experienced this problem after upgrading to version 0.5x

Expected: An error free addition of my TP Link router as a tracking device

Problem-relevant configuration.yaml entries and steps to reproduce:


device_tracker:
  - platform: tplink
    host: 192.168.0.1
    username: admin
    password: xxxxxxx
  1. Add entry to configuration.yaml
  2. Logout from TP Link router from all your browser sessions
  3. Restart HA
  4. Check HA log file

Traceback (if applicable):

2017-08-24 20:29:58 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform tplink
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/requests/packages/urllib3/response.py", line 302, in _error_catcher
    yield
  File "/srv/homeassistant/lib/python3.4/site-packages/requests/packages/urllib3/response.py", line 384, in read
    data = self._fp.read(amt)
  File "/usr/lib/python3.4/http/client.py", line 500, in read
    return super(HTTPResponse, self).read(amt)
  File "/usr/lib/python3.4/http/client.py", line 539, in readinto
    n = self.fp.readinto(b)
  File "/usr/lib/python3.4/socket.py", line 371, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
antosiekd commented 7 years ago

I've had constant issues with the tp link device tracker for months. Has never been fixed for me.

jpitters3 commented 7 years ago

@itchaboy Any update on this issue? Have you been able to get it working?

I'm having the same problem.

antosiekd commented 7 years ago

Nope, as far as I can tell the TP Link device tracker platform is completely broken.

0BuRner commented 6 years ago

I also have a TP-Link device but doesn't work neither with the tp link device tracker. So I dove into the code and found 2 things :

I'm going to create a pull request with a fix next week. I'll also try to implement a way to authenticate on WA850 devices.

tinmice commented 6 years ago

@0BuRner Any luck with this? Happy to help out testing if that is of any use, I have an Archer C7 unit.

0BuRner commented 6 years ago

Woops I totally forgot about this issue. I created a new device tracker module for my TL-WA850. I also fixed this issue. But I don't know if they will accept the pull request since they want HA only uses external components. I'll do it Wednesday. Don't hesitate to remind me here ;-)

tinmice commented 6 years ago

@0BuRner Reminding you here :)

0BuRner commented 6 years ago

Hi, See pull request #11962 Sadly I can't certify this little change will make the module work for everyone. I cannot test it since I don't have one of the supported device. If some of you can take these changes, try and give a feedback, it would be awesome. I also have some more modifications to be able to track devices with other tplink devices but didn't find the time to finalize the code yet. I'll let you know here.

dimitripb commented 6 years ago

As the OP of this issue I would like to help but in the meanwhile I flashed my TP Link router to OpenWRT so I cannot attribute to this issue anymore.

balloobbot commented 6 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

dimitripb commented 6 years ago

As stated before I do not have a router with original TP-Link firmware anymore so I cannot test this. I asked some other users to check it. I hope I will have an answer soon.

sajjas100 commented 6 years ago

I have an Archer C8 and have had the same issues described. I am happy to test, but am somewhat of a novice. If you can provide instructions on what I need to do to test it on hassio, I can try and test it.

dimitripb commented 6 years ago

Here you can find the instruction how to configure a TP-Link router as a tracking device: https://www.home-assistant.io/components/device_tracker.tplink/

Then restart HA and check the log. There used to be an error message about the TP-Link device tracker, but maybe this has been solved.

sajjas100 commented 6 years ago

Yes, below is the error I get in the log. I usually have to restart several times before the device tracker with TPLink starts working. @0BuRner appears to have a fix that needs to be tested. I can test it, but just need some instruction on how to load and check using hassio.

Sat Apr 07 2018 11:19:28 GMT-0500 (Central Daylight Time)

Error setting up platform tplink
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/urllib3/response.py", line 302, in _error_catcher
    yield
  File "/usr/lib/python3.6/site-packages/urllib3/response.py", line 384, in read
    data = self._fp.read(amt)
  File "/usr/lib/python3.6/http/client.py", line 449, in read
    n = self.readinto(b)
  File "/usr/lib/python3.6/http/client.py", line 493, in readinto
    n = self.fp.readinto(b)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/models.py", line 745, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/lib/python3.6/site-packages/urllib3/response.py", line 436, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/lib/python3.6/site-packages/urllib3/response.py", line 401, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python3.6/site-packages/urllib3/response.py", line 320, in _error_catcher
    raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 181, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/tplink.py", line 41, in get_scanner
    scanner = cls(config[DOMAIN])
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/tplink.py", line 64, in __init__
    self.success_init = self._update_info()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/tplink.py", line 389, in _update_info
    session.post(base_url, login_data, headers=header)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 658, in send
    r.content
  File "/usr/lib/python3.6/site-packages/requests/models.py", line 823, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "/usr/lib/python3.6/site-packages/requests/models.py", line 748, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))
dimitripb commented 6 years ago

This is still the same error so this issue has to be kept open.

JPM-git commented 6 years ago

Well, I too have problems with my tp-link RE450 which has the new firmware and I too have been digging on the tkplink.py and so far, and on my case I notice two things that don't allow the repeater to replay correctly:

First I can't login, I have made a new instant Tplink6DeviceScanner that is based n the 5 but has a new url for the client list.

Passing this big problem of not being able to login I get an erro on this line: or device in list_of_devices['data']

My fw has a particular way of working since I can acess the client page (data/device.all.json) even without login and it return 4 (I assume dummy) replays which have the correct struture but now thre is no field "deviceName" it's only "name", also "MAC" is now "mac" but i'm not sure if it's caseSensitive.

So if someone can help me update the login steap i might be able to continue with the development and help anyway i can.

Also if necessary i can provide logs and all the test needed since i have a OEM fw on the repeater and have a dev environment where i can mess everything .

sajjas100 commented 6 years ago

I have updated my tplink.py file with the changes detailed in #11962 about 2 weeks ago. I have performed numerous restarts and reboots and presence detection has worked every time.

0BuRner commented 6 years ago

I also implemented device tracking for most recent firmware (json as mentioned by JPM). Need to find some free time to create pull request and complete their PR description -_-

jtitley commented 6 years ago

I have RE450 and applied #11962 and now get No RPM for this combination of URL and method error. Is that what is being discussed here about not being able to log in?

JPM-git commented 6 years ago

I have applied the update and yes now i get "all" the error from "device Scanners (Tplink5DeviceScanner, Tplink4DeviceScanner, Tplink3DeviceScanner, Tplink2DeviceScanner, TplinkDeviceScanner) but none will work on the latest firmware on my repeater.

0BuRner commented 6 years ago

Hi, here is a gist containing a piece of code extracted from my "in-progress" but probably "never released" project that can extract clients connected to latest TPLink devices : https://gist.github.com/0BuRner/08c691f482d5edb2938a9f26db00654c Some modifications are needed in order to make it work in home-assistant. Feel free to use it and modify as you wish. Hope it will help. Regards

JPM-git commented 6 years ago

I'll give it a try later today.

codypet commented 6 years ago

Has anyone figured this out yet? I recently got a TP C1200 and it would be nice to put presence detection in. Looking at my log somethings going on, but I can't seem to figure it out and it seems like a long standing problem here.

jtitley commented 6 years ago

Someone needs to take @0BuRner code and see if it can be integrated. TPLink use a strange login encryption method where a straight post won't work. I guess to prevent brute force attacks or something like that.

On the surface it looks like @0BuRner code will work so it's a question of someone picking it up.

bvansambeek commented 6 years ago

I am on a TP Link Router TL-WR1043ND v1 and get the error as described above. I double checked the credentials and they are correct. I am logged out of the router on all devices. I am on hass 0.76.2

HolyNoodle commented 6 years ago

I got Archer C9 version : 1.2.2 Build 20180423 rel.85787(4555)

HA 0.79.2 Python 3.6.6 Rpi 3B+

I get the same error as @sajjas100 and can test if someone lead me through the steps. Got background in computing, basics in term of HA.

HolyNoodle commented 6 years ago

For those interested in having something working with the Archer C9 v5 (since you can't install openwrt(v1) or dd-wrt(v4) on it), I came up with a custom platform for this particular device. It's working. Got no problem, at least for the moment : https://github.com/HolyNoodle/HA-TPLink-ArcherC9

balloobbot commented 5 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

balloobbot commented 5 years ago

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem 👍