Python plugin: Presence detection from wireless router

Python and python framework

Moderator: leecollings

EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

@sapnho:

That statement will just be repeated on every poll. Have a look at the debug log while the plugin is starting. That should provide more helpful info.
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

Ok, will check tomorrow. Thanks.
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

Following another restart of Domoticz (with iDetect deactivated) everything seems to work fine again. No error messages during the night. Thanks.

Now, I just need to find out how to install ssh public key authentication instead of the password because the password is indeed open in the logfiles. I haven't quite understood the instructions other than putting the public key on the wifi device. But since I have three of those and a separate controller (Unifi Cloud Key), I am not sure how that would work. Any pointers?
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

@EscApe: Received this error message once this morning. No worries everything works fine, but I know you are always keen to get a report of error messages...
2018-09-04 07:44:13.675 Error: (iDetect) SSH subprocess failed with error (255):b''
PatrickM
Posts: 20
Joined: Wednesday 18 June 2014 15:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by PatrickM »

The plugin works great for me, after making some modifications. I run a router with openwrt/lede based firmware with grep supplied by busybox. Patterns like

Code: Select all

grep '^eth\|^wlan\|^ath'
don't work properly, only matching lines starting with eth. Changing to

Code: Select all

grep -E '^eth|^wlan|^ath'
fixes that and should work on any version of grep. I would submit a PR but I also changed all indenting to my personal preference ;-)
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

@mvzut:
I sill hope you didn't hold your breath .... for 21 hours ;-)

@sapnho:
Nice to hear that it works... i have added a little something to monitor response times and potential timeout situations (and upped the hard timeout a little)
No longer displaying passwords in the debug log

@PatrickM:
Thanks for letting me know! Fixed in this version

Just pushed a new version

**version 0.6.2**
- Added: You can now use different passwords for routers by configuring them as username@routerip (otherwise global username on the configuration page will be used).
- Added: Displaying the time a ssh command takes when in debug mode.
- Enhanced: Password is no longer displayed in the debug log.
- Fixed: Grep command for some openwrt routers.
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

Very nice. That removed the occasional error message altogether. Thanks!
mvzut
Posts: 443
Joined: Thursday 12 November 2015 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Python plugin: Presence detection from wireless router

Post by mvzut »

Cool, great improvements!

Unfortunately it still doesn't solve my problem completely: The Linksys router with Tomato firmware still gives a 255 error, regardless of which timeouts I choose, unless I put it in #forcegeneric mode. Any idea what this could be? Seems something might be going wrong in the part which determines which methods are supported by the router. This part of the code is probably not used when you force the method? I can post (or PM) a piece of my log using debug mode if that helps.
Raspberry Pi 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

@mvzut

Without a debug log i can't tell what's going on... There should no longer be a password in the log, so it should be safe to share.
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

EscApe wrote: Wednesday 05 September 2018 14:38 There should no longer be a password in the log, so it should be safe to share.
Oh, the password is still in there.. (0.62)

2018-09-05 14:41:15.405 (iDetect) Fetching data from router using: ['sshpass', '-p', 'thisiswhereyoucanseethepassword', 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=2', '[email protected]', "export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;wlanconfig ath0 list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1;wlanconfig ath2 list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1;wlanconfig eth0 list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1;exit"]
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

Oops... that’s a different piece of logging I didn’t take into account. Will see if I can remove those passwords in a future version. Can you share or pm me the debug log from where the plug starts until the first poll?

Would like to see any responses and/or errors to the command it is sending (according to the line you shared)

Is the password the right password for that router? Passwords must be the same on both routers unless you use key based authentication. Only the usernames can be different if you use a password.
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

Thanks for the log in pm

Can you login to the failing router (xxx.56) using ssh from the command line, run the command manually and share the results? Just copy me paste to the routers command line.

Code: Select all

export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;wlanconfig ath0 list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1;wlanconfig ath2 list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1;wlanconfig eth0 list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1;exit
Haven’t seen the start part of the debug log, but since it is using a command line it probably initialized just fine. Passwords or ssh connection should not be the problem. Otherwise it would not initialize properly and forcegeneric would also fail. Maybe the router has a different syntax for wlanconfig. What is the model and firmware of the router?
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

All wifi access points are Unifi AP Pro, same firmware. Funny thing, they all work with iDetect. Will send you the login with PM.
hjzwiers
Posts: 163
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by hjzwiers »

Running a AC86u as main router and AC68u in AImesh mode.

with #forcegeneric it sees all phones, but with quite a detection delay

So I tried the newest version and added both the IP of the main and mesh router. This is the log:

2018-09-05 20:40:48.391 Status: (iDetect) Initialized version 0.6.2, author 'ESCape'
2018-09-05 20:40:48.593 Status: (iDetect) Using chipset specific (wl) command on router 192.168.1.1 for interfaces ['eth5', 'eth6']
2018-09-05 20:40:48.971 Status: (iDetect) Using chipset specific (wl) command on router 192.168.1.236 for interfaces ['eth1', 'eth2']

iDetect now only sees the phones connected to the main router, but not the ones on the mesh router.

I will revert to using #forcegeneric, just did this to do the test
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

@hjzwiers

Thanks for your feedback! To bad it's not working (yet).

So the plugin was able to retrieve the router capabilities. The ssh connection works. For some reason it is not getting the association ('presence') info from the router, but without a debug log i cannot tell whats happening. Maybe the routers behave differently in a mesh setup. I cannot try this because i only have one router.

Forcegeneric will also work if only one of the routers is queried, so that doesn't tell us anything about the multi router support.
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

@hjzwiers

Thanks for your feedback! To bad it's not working (yet).

So the plugin was able to retrieve the router capabilities. The ssh connection works. For some reason it is not getting the association ('presence') info from the router, but without a debug log i cannot tell whats happening. Maybe the routers behave differently in a mesh setup. I cannot try this because i only have one router.

Forcegeneric will also work if only one of the routers is queried, so that doesn't tell us anything about the multi router support.
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

@sapnho:

From the logs you send me i can tell all three routers are queried and responding with mac addresses. For some reason the wlanconfig command does not exit with an error code when querying a eth* interface, but only ath* interfaces seem te be right. It only displays an error but does exit with code 0 (no error). That's why eth* are still detected at startup and queries at every poll. I don't think the error message will interfere with the detection though.

In the log i see no reason for the detection to fail. It shows mac addresses from all three mesh members. Has it magically started working??
sapnho
Posts: 45
Joined: Monday 27 August 2018 17:49
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9962
Location: Frankfurt am Main
Contact:

Re: Python plugin: Presence detection from wireless router

Post by sapnho »

Yes, 0.62 works fine and detects all phones quickly. No complaints from my side. ;)

Great stuff! Thanks!
EscApe
Posts: 528
Joined: Thursday 02 April 2015 8:46
Target OS: Linux
Domoticz version: 2020+
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe »

Help wanted

Dear forum members and plugin users. There seem to be some issues with the detection on mesh/multiple routers. I can not troubleshoot these myself, since i don't own such a setup. If anyone with sufficient linux cli, networking and preferably python knowledge (who does use multiple routers) wants to help me troubleshoot this, then please let me know. Either on the forum or pm.

If anyone knows how to determine the right wireless interfaces on a router that uses the wlanconfig (atheros chipset?) command, then that info would also be appreciated. Just trying every interface is not the solution, because it will not throw an exit code when it fails. Is it safe to assume the interfaces are always called ath* ????

Thanks!
mvzut
Posts: 443
Joined: Thursday 12 November 2015 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by mvzut »

EscApe wrote:@mvzut

Without a debug log i can't tell what's going on... There should no longer be a password in the log, so it should be safe to share.
I sent you a PM with the log. Hope you find some hints in there about what might be the problem with the Linksys/Tomato router.
Thank for all your support!
Raspberry Pi 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest