kennedyshead / aioasuswrt

MIT License
24 stars 24 forks source link

Use /tmp/clientlist.json in async_get_connected_devices #36

Open rkkoszewski opened 4 years ago

rkkoszewski commented 4 years ago

Hi,

I just noticed that the function async_get_connected_devices shows disconnected devices as present, even if they're not. This is probably due to using the dnsmasq.leases file, which keeps the device record till the dns lease is expired.

I noticed there is a file /tmp/clientlist.json that basically shows the same information, but shows disconnected devices much quicker. In that file it also shows the clients separated by wifi "2G", "5G" and "wired_mac", which could also be used in async_get_wl to avoid the loops and multiple calls.

Is there any reason why that file has not been used for this cases?

From my tests, that file was kept updated even when no client was connected to the web admin of the router (Unless I missed out something).

kennedyshead commented 4 years ago

Looks like a very interesting thing to explore! I'll setup some experimental tests

rkkoszewski commented 4 years ago

I actually have it already running at home and it seems to work much faster, at least to identify devices that left. You can test if it works for you from my branches here

Using Native Python JSON (Preferred by me): https://github.com/rkkoszewski/aioasuswrt/tree/feat/clientlistjson/json

Or using ORJSON (Requires ORJSON dependency installed, is slightly faster than the native version): https://github.com/rkkoszewski/aioasuswrt/tree/feat/clientlistjson/orjson

I can open a PR if you want, or just take what you need from the changes.

kennedyshead commented 4 years ago

Yes, I think it should be added as an alternative though, there are like 1mil different versions of asuswrt and I'm not 100 that the file exists in all of these systems ;) Let's try to open that file and if it does not exists fall back to the old listing.

dejablue79 commented 4 years ago

Hi, I have also found the same file while look a better way for looking up devices. Is there anything i can do to help?

kennedyshead commented 4 years ago

I' working on this, will probably be added in next version

PeteRager commented 3 years ago

I’m having the same issue, RT-AC86U, current firmware 3.0.0.4.386_40451. Turning off wireless on iPhone that has a manual DHCP IP assigned, causes the device to continue to be reported back active for >12 hours (I didn’t wait longer so I do not know if it is ever removed)

However the /tmp/clients.json does get updated within a few seconds on disconnect and almost immediately on connect. For my router this looks like a better solution.

It’d be good to get this library updated, so that it can get pulled into Home Assistant, and all those users get the benefit of this working better.

niklerus commented 3 years ago

Hi, Is there any activity around this? I opened an issue relating to this some time ago but it got closed https://github.com/home-assistant/core/issues/41538 due to inactivity.

imdunne8 commented 3 years ago

I've been using the clientlistjson/json branch from @rkkoszewski for over a month now through Home Assistant and it has been completely stable, runs faster, and picks up devices on my AiMesh extender by default. It certainly seems that this solution holds some nice benefits for many users, even if it isn't set as the default device polling method.

kennedyshead commented 3 years ago

I have tested it to and it is as you say more stable and faster. I'd be open to a PR if anyone have the time to put in some effort? I have to much daytime work and no time to play :(

rkkoszewski commented 3 years ago

I could give it a shot. I might have some spare time today after work and could create the PR.

fcastilloec commented 3 years ago

I've been using the clientlistjson/json branch from @rkkoszewski for over a month now through Home Assistant and it has been completely stable, runs faster, and picks up devices on my AiMesh extender by default. It certainly seems that this solution holds some nice benefits for many users, even if it isn't set as the default device polling method.

@imdunne8 how did you manage to use that branch with the Home Assistant integration? I'm having some problems where none of my wireless devices get reported, only wired ones, probably because my RT-AC68U is running in AP mode, so the dnsmasq.leases file is empty. I have no idea where the info is being pulled from to get the wired device's data. Nonetheless, I would love to use the mentioned branch to fix my issues.

imdunne8 commented 3 years ago

@fcastilloec The easy way to test it (which will likely have to be done again if you update HA) is to:

pip uninstall aioasuswrt pip install git+https://github.com/rkkoszewski/aioasuswrt.git@f29071c5b532436f000e5151ae0a5b2a68040541

If you run HA through Docker you will have to run these commands from inside the container.

niklerus commented 3 years ago

thanks @imdunne8 ! Tried it as well and worked great. Good job @rkkoszewski ! @imdunne8 , short question, how did you get that https adress? Howcome it's not the adress stated by rkkoszewski (https://github.com/rkkoszewski/aioasuswrt/tree/feat/clientlistjson/json) Obviously your adress works, just curious how it works, couldn't find your your adress anywhere on rkkoszewski's github page

imdunne8 commented 3 years ago

@niklerus That's just the git commit ID for the latest commit on that branch. Doing a pip install pointing at a github repository with the ID will mean it will always install that particular commit. You can find the ID if you look at the git history.

dpembo commented 3 years ago

thanks @imdunne8 ! Tried it as well and worked great. Good job @rkkoszewski ! @imdunne8 , short question, how did you get that https adress? Howcome it's not the adress stated by rkkoszewski (https://github.com/rkkoszewski/aioasuswrt/tree/feat/clientlistjson/json) Obviously your adress works, just curious how it works, couldn't find your your adress anywhere on rkkoszewski's github page

Just to say thanks to all involved! This has solved my issues also.
Much more stable and consistent! Hopefully this can be merged 👍

__

fsecko1 commented 3 years ago

Hi, I´m newbie, so sorry for my questions, but could someone help me with step by step how to install this to home assistant? I´m using native integration asuswrt in HA, but in Aimesh is not working correctly (devices stays still "home"). Thank you.

TwoD commented 3 years ago

Is this file new? I don't seem to have it in MerlinWRT 384.13_2 on my RT-AC87U.

pannal commented 2 years ago

I see the clientlist.json fork/feature branch is quite old. Will this ever get incorporated into this repository?