Re: Python plugin: Presence detection from wireless router
Posted: Sunday 03 March 2019 11:19
I it's in 2 places, a global variable in the top of the script would been nice or a field in the settings
Open source Home Automation System
https://forum.domoticz.com/
I it's in 2 places, a global variable in the top of the script would been nice or a field in the settings
It should already work if you specify the host as host:portI guess this has been asked before but please let us change the port to use.
Code: Select all
[email protected]:2022=brctlFirst thing to check if things work fine on the command line but not in the plugin is if they are using the same key-based authentication. You might have configured authentication from the pi (normal) userprofile, while Domoticz is running as root be defaultRan it manually and I got a list of MAC addresses.
EscApe wrote: Sunday 03 March 2019 13:48 @Varzir
It should already work if you specify the host as host:portI guess this has been asked before but please let us change the port to use.
A complex server configuration could for example beWhich would mean: connect to my router with IP address 192.168.0.1 on port 2022 with username 'admin' and force 'brctl' detection method.Code: Select all
[email protected]:2022=brctl
It was what I did, I connected with ssh key from my raspberry pi(domoticz) to my router software using the RPi root account and ran the command I found in the plugin but I'm not that good at coding/scripting I couldn't find any more command or understand how it tries to use list of MAC addresses.First thing to check if things work fine on the command line but not in the plugin is if they are using the same key-based authentication. You might have configured authentication from the pi (normal) userprofile, while Domoticz is running as root be defaultRan it manually and I got a list of MAC addresses.
YesShould I add this to the WiFi router Ip address field?
Indeed I had the idea to try this after posting!mikeoo wrote: Sunday 03 March 2019 9:52I also use 3 Unify AP and have only one Anyhome button.Number8 wrote: Sunday 03 March 2019 7:06 @EscApe I have 3 Unifi AP's and likely more to come, so I ended up up with 3 Anyone buttons. Would be great I guess to have one master Anyone button. Is this something that could considered?
In Hardware page of Domoticz i use al 3 ip-adresses for Wifi Router Ip-adres like: 192.168.0.201,192.168.0.202,192.168.0.203
Now it scans al 3 AP without any problems.
Setup: https://www.domoticz.com/forum/viewtopi ... 20#p197905
You maybe missed my editing, It's working now with using arp.EscApe wrote: Sunday 03 March 2019 14:15YesShould I add this to the WiFi router Ip address field?
Before getting into the code that runs on the router let’s first get the connection working. From the piece of logging you sent before it seems like it is not even connecting (yet). If you get it working with the correct port please run it in debug mode and share the complete log of the plugin. Make sure you use the unaltered plugin (before your own changes) by copying a fresh version.
Edit: you don’t need to use all the parameters in my example. If you only want to specify ip and port you can just enter something like 192.168.0.1:2022
I did use option 1. I doubt that one AP can report all connected MAC addresses of all AP's, if it exists it would be most probably the role of the controller.EscApe wrote: Sunday 03 March 2019 8:38 @Number8,
4. If you happen to find a (proprietary Unifi) command on the AP's that returns all connected Mac addresses on all AP's in a network/mesh from one command on one AP then I can add it to the plugin (has to be something quicker and more reliable than ARP).
I would go with option 1![]()
I doubt it's a Synology package issue but I will do some debugging later this evening. If I found something I will report back.EscApe wrote: Thursday 18 April 2019 20:25 @schumi2004
Could this be caused by the Synology packaging? Not finding the ssh binary seems like an OS related issue. Maybe the search path has changed(?) I just tried the latest Domoticz beta on my raspberry and the plugin is still working without any issues.

Code: Select all
2019-06-13 14:56:10.984 Status: (AsusWRT) Entering work loop.
2019-06-13 14:56:10.985 Status: (AsusWRT) Initialized version 0.7.7, author 'ESCape'
2019-06-13 14:56:14.236 (AsusWRT) Debug logging mask set to: PYTHON
2019-06-13 14:56:14.236 (AsusWRT) Not running on Windows
2019-06-13 14:56:14.256 (AsusWRT) The OS user profile running domoticz is: root
2019-06-13 14:56:14.289 (AsusWRT) Checking if [ssh -V] will run: OK
2019-06-13 14:56:14.289 (AsusWRT) Parsing user and optional keyfile from:admin
2019-06-13 14:56:14.310 (AsusWRT) Checking if [sshpass -V] will run: OK
2019-06-13 14:56:14.311 (AsusWRT) Monitoring {'Miriam': {'lastseen': None, 'mac': '6C:xx:xx:xx:xx:9D', 'ignore': False}, 'Laurens': {'lastseen': None, 'mac': '4C:xx:xx:xx:xx:00', 'ignore': False}} for presence.
2019-06-13 14:56:14.311 (AsusWRT) 2 of them will control the Anyone home switch
2019-06-13 14:56:14.311 (AsusWRT) Router configuration:192.168.0.1
2019-06-13 14:56:14.311 (AsusWRT) Using password instead of ssh public key authentication for 192.168.0.1 (less secure!)
2019-06-13 14:56:14.312 (AsusWRT) Fetching data from 192.168.0.1 using: sshpass -p **secret** ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -p22 [email protected]
2019-06-13 14:56:14.312 #!/bin/sh
2019-06-13 14:56:14.312 export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH
2019-06-13 14:56:14.312 type wl > /dev/null 2>&1 && printf "~wl"
2019-06-13 14:56:14.312 type iwinfo > /dev/null 2>&1 && printf "~iwinfo"
2019-06-13 14:56:14.312 type wlanconfig > /dev/null 2>&1 && printf "~wlanconfig"
2019-06-13 14:56:14.312 type qcsapi_sockrpc > /dev/null 2>&1 && printf "~qcsapi_sockrpc"
2019-06-13 14:56:14.312 type brctl > /dev/null 2>&1 && printf "~brctl"
2019-06-13 14:56:14.312 type arp > /dev/null 2>&1 && printf "~arp"
2019-06-13 14:56:14.312 [ -f /proc/net/arp ] && printf "~procarp"
2019-06-13 14:56:14.312 exit
2019-06-13 14:56:14.312
2019-06-13 14:56:14.612 (AsusWRT) SSH subprocess for 192.168.0.1 failed with error (255):b''
2019-06-13 14:56:14.612 (AsusWRT) SSH command on 192.168.0.1 took 300 milliseconds.
2019-06-13 14:56:14.612 (AsusWRT) Could not retreive available commands on 192.168.0.1
2019-06-13 14:56:14.613 (AsusWRT) Router initialized as:{'192.168.0.1': {'port': 22, 'errorcount': 1, 'initialized': False, 'prospone': datetime.datetime(2019, 6, 13, 14, 56, 26, 612846), 'cmd': '', 'user': 'admin'}}
2019-06-13 14:56:14.613 (AsusWRT) AsusWRT - Laurens is stil in use
2019-06-13 14:56:14.613 (AsusWRT) AsusWRT - Miriam is stil in use
2019-06-13 14:56:14.613 (AsusWRT) Devicenames and their Domoticz (subdevice) index: {'Miriam': 3, 'Laurens': 2}
2019-06-13 14:56:14.613 (AsusWRT) MAC addresses to monitor: {'Miriam': {'lastseen': None, 'mac': '6C:xx:xx:xx:xx:9D', 'ignore': False}, 'Laurens': {'lastseen': None, 'mac': '4C:xx:xx:xx:xx:00', 'ignore': False}}
2019-06-13 14:56:14.613 (AsusWRT) Plugin initialization done.
2019-06-13 14:56:25.401 (AsusWRT) Prosponed connection to 192.168.0.1 for 0:00:01.211365
2019-06-13 14:56:25.401 (AsusWRT) Did not retreive WLAN information from any router
2019-06-13 14:56:25.402 (AsusWRT) Entire poll took 0% of the poll interval time (0 milliseconds)
2019-06-13 14:56:40.559 (AsusWRT) 192.168.0.1 was not properly initialized. Retrying to get router capabilities (and skipping this poll round).
2019-06-13 14:56:40.562 (AsusWRT) Using password instead of ssh public key authentication for 192.168.0.1 (less secure!)
2019-06-13 14:56:40.562 (AsusWRT) Fetching data from 192.168.0.1 using: sshpass -p **secret** ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -p22 [email protected]
2019-06-13 14:56:40.562 #!/bin/sh
2019-06-13 14:56:40.562 export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH
2019-06-13 14:56:40.562 type wl > /dev/null 2>&1 && printf "~wl"
2019-06-13 14:56:40.562 type iwinfo > /dev/null 2>&1 && printf "~iwinfo"
2019-06-13 14:56:40.562 type wlanconfig > /dev/null 2>&1 && printf "~wlanconfig"
2019-06-13 14:56:40.562 type qcsapi_sockrpc > /dev/null 2>&1 && printf "~qcsapi_sockrpc"
2019-06-13 14:56:40.562 type brctl > /dev/null 2>&1 && printf "~brctl"
2019-06-13 14:56:40.562 type arp > /dev/null 2>&1 && printf "~arp"
2019-06-13 14:56:40.562 [ -f /proc/net/arp ] && printf "~procarp"
2019-06-13 14:56:40.562 exit
2019-06-13 14:56:40.562
2019-06-13 14:56:40.882 (AsusWRT) SSH subprocess for 192.168.0.1 failed with error (255):b''
2019-06-13 14:56:40.883 (AsusWRT) SSH command on 192.168.0.1 took 320 milliseconds.
2019-06-13 14:56:40.883 (AsusWRT) Could not retreive available commands on 192.168.0.1
2019-06-13 14:56:40.883 (AsusWRT) Routerinfo:{'port': 22, 'errorcount': 2, 'initialized': False, 'prospone': datetime.datetime(2019, 6, 13, 14, 57, 40, 883379), 'cmd': '', 'user': 'admin'}
2019-06-13 14:56:40.883 (AsusWRT) Did not retreive WLAN information from any router
2019-06-13 14:56:40.883 (AsusWRT) Entire poll took 2% of the poll interval time (325 milliseconds) Code: Select all
admin@RT-AC66U_B1-DB30:/tmp/home/root# ifconfig | cut -d ' ' -f1| tr ':' '\n' | grep -E '^eth|^wlan'
eth0
eth1
eth2
I'm running on a raspberry pi and have sshpass installed. I also read out an OpenWRT router with your plugin and that works perfect.EscApe wrote: Thursday 13 June 2019 19:17 Could you try the command including the sshpass wrapper (full syntax is in the log on the 13th line) to make sure sshpass is installed and working? Otherwise my second guess would be a typo in the password(?) Unfortunately I could not get more informative logging from the subprocess routine.
Code: Select all
pi@PiHome:~ $ sshpass -p mypassword ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -p22 [email protected]
ASUSWRT-Merlin RT-AC68U 384.11-2 Sat May 18 03:32:01 UTC 2019
admin@RT-AC66U_B1-DB30:/tmp/home/root# wl assoclist
assoclist 4C:66:41:6E:2E:00
assoclist 18:01:F1:35:D6:6F
assoclist 6C:71:D9:CD:22:63
assoclist 80:7D:3A:47:69:DA
assoclist EC:FA:BC:18:D0:5A
assoclist 40:A5:EF:0B:32:4E
assoclist DC:4F:22:26:7B:55
assoclist B0:D5:9D:22:57:C7
assoclist 00:04:20:EF:72:EA
assoclist F0:FE:6B:72:B3:3C
admin@RT-AC66U_B1-DB30:/tmp/home/root#
Found the problem. Thanks for thinking along with meEscApe wrote: Thursday 13 June 2019 20:26 The 255 error is to generic to really troubleshoot, but the python subproces doesn't provide much more![]()
I'm running Merlin on my AC86u (primary router/ap) and have no such issues. Most of the time problems like this are caused by authentication issues or in rarer cases timeouts. Since the process only took 300ms timeouts are unlikely. I'm just guessing here: did you previously configure ssh key based authentication for the user profile that is running Domoticz? Maybe a now invalid user key messes things up or maybe the host key has changed so the connection is no longer trusted(?) Did you try the command under the root user profile (which is running Domotica according to your log)? That might be more informative.
Code: Select all
2019-07-26 09:49:48.175 (Présence) Fetching data from 192.168.21.30 using: ssh -i -o ConnectTimeout=3 -p22 [email protected]
#!/bin/sh
export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH
type wl > /dev/null 2>&1 && printf "~wl"
type iwinfo > /dev/null 2>&1 && printf "~iwinfo"
type wlanconfig > /dev/null 2>&1 && printf "~wlanconfig"
type qcsapi_sockrpc > /dev/null 2>&1 && printf "~qcsapi_sockrpc"
type brctl > /dev/null 2>&1 && printf "~brctl"
type arp > /dev/null 2>&1 && printf "~arp"
[ -f /proc/net/arp ] && printf "~procarp"
exit
2019-07-26 09:49:49.446 (Présence) SSH subprocess for 192.168.21.30 failed with error (1):b''
2019-07-26 09:49:49.447 (Présence) SSH command on 192.168.21.30 took 643 milliseconds.
2019-07-26 09:49:49.447 (Présence) Could not retreive interfaces belonging to iwinfo command on 192.168.21.30
2019-07-26 09:49:49.447 (Présence) Found suitable command (and interfaces) for router 192.168.21.30:{'brctl': []}
2019-07-26 09:49:49.447 (Présence) Using generic brctl command on router 192.168.21.30. Will respond slower and on some routers a little less reliable to absence
Any comments?