Python plugin: Presence detection from wireless router

Python and python framework

Moderator: leecollings

User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EdwinK »

After reading the posts, I hoped this would work with my router (Asus RT-AC51U), so I tried the steps on this, and I think I've everything working on both router and domoticz site (choose option 1 for SSH).

But after restarting and enabling the hardware i got this:

Code: Select all

2018-08-17 11:52:28.327 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:52:38.293 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:52:38.293 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:52:38.294 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:52:48.311 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:52:48.311 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:52:48.311 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:52:58.329 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:52:58.329 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:52:58.329 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:08.297 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:53:08.297 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:08.297 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:18.315 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:53:18.315 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:18.315 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:28.332 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:53:28.333 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:28.333 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:38.300 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:53:38.301 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:38.301 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:48.318 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:53:48.318 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:48.318 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:58.336 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:53:58.336 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:53:58.336 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:08.308 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:54:08.309 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:08.309 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:18.326 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:54:18.326 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:18.327 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:28.344 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:54:28.344 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:28.344 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:38.313 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:54:38.313 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:38.313 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:48.331 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:54:48.331 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:48.331 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:58.350 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:54:58.350 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:54:58.350 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:08.324 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:55:08.324 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:08.324 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:18.341 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:55:18.341 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:18.341 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:28.361 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:55:28.361 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:28.361 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:38.328 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:55:38.329 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:38.329 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:48.345 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:55:48.345 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:48.345 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:58.363 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:55:58.363 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:55:58.363 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:08.330 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:56:08.330 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:08.330 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:18.348 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:56:18.348 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:18.348 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:28.367 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:56:28.367 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:28.368 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:38.335 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:56:38.335 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:38.335 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:48.353 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
2018-08-17 11:56:48.353 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:48.353 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py, function onHeartbeat
2018-08-17 11:56:58.373 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
Already read through some of the posts on the onHeartbeat message, but don't understand any of it. Hope someone can help me with this, as I would really like to have this plugin working.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by wizzard72 »

EscApe wrote: Friday 17 August 2018 9:58 @wizzard72:
If I understand correctly the number (4 in your example) is the number of connected devices. If so, then this number would change on every connect/disconnect and can not be determined only at startup.
Is this correct?
Yes this is correct.
I just found out how to get the interface name of the 5G: qcsapi_sockrpc get_primary_interface. The outcome is "wifi0".

So in the part "routercommand" it can be added the same way as the other methods:

Code: Select all

test=$(which qcsapi_sockrpc > /dev/null 2>&1)
                    if [ $? == 0 ]; then
                            printf "qcsapi_sockrpc@"
							for iface in $(qcsapi_sockrpc get_primary_interface)
							do
									test=$(qcsapi_sockrpc get_primary_interface > /dev/null 2>&1)
                                    if [ $? == 0 ]; then
                                            printf "$iface "
                                    fi
                    fi
I also found a way to output all MAC addresses: qcsapi_sockrpc get_assoc_records wifi0

A little down in the "routercommand" part somewhere where all the methods are called, we can add:

Code: Select all

elif method=="qcsapi_sockrpc":
				Domoticz.Status("Using chipset specific (qcsapi_sockrpc) command on router for interfaces " + str(interfaces))
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH"
				Domoticz.Status("Using chipset specific (qcsapi_sockrpc) command on router for interfaces ")
				for knownif in interfaces:
					pollscript=pollscript + ";qcsapi_sockrpc get_assoc_records " + knownif + " | cut -d' ' -f1 | cut -d':' -f1-6" 
				pollscript=pollscript + ";exit"
This part of the plugin:

Code: Select all

if method=="wl":
				Domoticz.Status("Using chipset specific (wl) command on router for interfaces " + str(interfaces))
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH"
				for knownif in interfaces:
					pollscript=pollscript + ";wl -i " + knownif + " assoclist | cut -d' ' -f2"
				pollscript=pollscript + ";exit"
			elif method=="iwinfo":
				Domoticz.Status("Using chipset specific (iwinfo) command on router for interfaces " + str(interfaces))
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH"
				for knownif in interfaces:
					pollscript=pollscript + ";iwinfo " + knownif + " assoclist | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1"
				pollscript=pollscript + ";exit"
			elif method=="wlanconfig":
				Domoticz.Status("Using chipset specific (wlanconfig) command on router for interfaces " + str(interfaces))
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH"
				for knownif in interfaces:
					pollscript=pollscript + ";wlanconfig " + knownif + " list | grep '^..:..:..:..:..:.. ' | cut -d' ' -f1"
				pollscript=pollscript + ";exit"
			elif method=="brctl":
				Domoticz.Status("Using generic (brctl) instead of chipset specific command on router (slower response to absence)")
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;brctl showmacs br0 | grep '..:..:..:..:..:..' | awk '{print $ 2}';exit"		
			elif method=="arp":
				Domoticz.Status("Using generic (arp) instead of chipset specific command on router (slower and on some routers less reliable response to absence)")
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;arp -a | grep '..:..:..:..:..:..' | awk '{print $ 4}';exit"
			elif method=="procarp":
				Domoticz.Status("Using last resort method (read info from /proc/net/arp file). This method has a slower and less reliable response to absence)")
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;cat /proc/net/arp | grep '..:..:..:..:..:..' | awk '{print $ 4}';exit"
			elif method=="qcsapi_sockrpc":
				Domoticz.Status("Using chipset specific (qcsapi_sockrpc) command on router for interfaces " + str(interfaces))
				pollscript="export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH"
				Domoticz.Status("Using chipset specific (qcsapi_sockrpc) command on router for interfaces ")
				for knownif in interfaces:
					pollscript=pollscript + ";qcsapi_sockrpc get_assoc_records " + knownif + " | cut -d' ' -f1 | cut -d':' -f1-6" 
				pollscript=pollscript + ";exit"
			else:
				Domoticz.Error("Unable to construct router commandline for presence")
				pollscript = "none"
				
might need to be run a few times (1 or 2, depending of the amount of chipsets). The output of the routerscript (for the RT-AC87U) = qcsapi_sockrpc@wifi0 wl@eth1
For another router it might be wl@eth0,eth2 (i dont know exactly)

Somehow we have to count the amount of routercommands and use this as a loop counter. But I dont know how to do this.
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Melotron »

My wifes phone got some problems on connecting to the router yesterday. She started to get wrong password when shes connecting to the wifi.
So I updated the firmware to the latest Asuswrt-Merlin 384.6, and its working good for her phone now.
But after that the script stopped working.

Its givng me the following error :

Code: Select all

Error: (Presence detection WIFI) No usable commandline to check presence. Trying again to detect router capabilities.
Error: (Presence detection WIFI) Temporarily limiting the polling frequency after encountering 5 (ssh) errors in a row.
Error: (Presence detection WIFI) SSH subprocess failed with error (255):b''
Error: (Presence detection WIFI) Could not determine router capabilities
Here are the ssh configuration on the router.
What do I need to change ??

//Magnus Svensson
Attachments
asus.jpg
asus.jpg (45.26 KiB) Viewed 1344 times
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Melotron »

Solved it.

Figured out at work that I needed to delete the old ssh key and get a new one.

Code: Select all

sudo ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.1.1
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 »

@wizzard72 (and for other testers, especially AC87 owners)

Thank you for supplying the command lines needed! I had to change your code and the script logic to truly support multiple commands in one router, but the basic command lines are till int there an should work. Please test them in debug mode.

wizzard73, Could you share the raw output of qcsapi_sockrpc get_assoc_records wifi0?
Can you also test the errorlevel if the command is run with a non existing interface name? (echo $? right after the command is run from cli)

All AC87 owners: the wl and qcsapi_sockrpc should show up in the plugin's debug log. Both should also mention the interfaces on which they are used. There should be no other commands/methods mentioned in the log and mac addresses of mobile devices should only show up once in the raw data from the router. A few examples of the debug log (from plugin start until the first poll) would be appreciated.

Other users: On single chipset routers it should still only detect and use 1 command. Please check and let me know if it does use more than 1 command (which would probably be redundant)

This version is very experimental and i will publish it to GitHub after i received enough feedback to confirm it is working and not breaking things for other routers. For now i will post it here... (not very gitfull, i know ;-))
Remove the .txt extension (had to add that to be able to upload) and replace the original plugin.py
Attachments
plugin.py.txt
(22.98 KiB) Downloaded 31 times
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 »

@EdwinK

Can you share the debug log from the start of the plugin. The heartbeat is probable failing because the initialization went wrong.
Most common cause is ssh key based access not setup correctly (for the userprofile running domoticz, which is root by default)
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 »

@Melotron:

Glad you got it working again and thanks for the tip to others! If the ssh key on either side changes it will indeed also break ssh key based login.

I don't recall asuswrt-merlin generating a new key after my last update, but that will likely differ between versions and upgrade methods. Hopefully it won't be necessary every time. Maybe you can backup and restore the keys when updating(?)
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EdwinK »

EscApe wrote: Monday 27 August 2018 15:04 @EdwinK

Can you share the debug log from the start of the plugin. The heartbeat is probable failing because the initialization went wrong.
Most common cause is ssh key based access not setup correctly (for the userprofile running domoticz, which is root by default)
This is from my log, I think I've got it all. The router is a RT-AC51U
Spoiler: show

Code: Select all

2018-08-27 15:15:53.904 (iDetect) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE ALL
2018-08-27 15:15:53.905 (iDetect) Not running on Windows
2018-08-27 15:15:53.950 (iDetect) Checking if [ssh -V] will run: OK
2018-08-27 15:15:53.967 (iDetect) Checking if [sshpass -V] will run: OK
2018-08-27 15:15:53.967 (iDetect) Monitoring {'edwin': 'EC89142FD7B2'} for presence.
2018-08-27 15:15:53.967 (iDetect) Checking router capabilities and wireless interfaces
2018-08-27 15:15:53.967 (iDetect) Using password instead of ssh public key authentication (less secure!)
2018-08-27 15:15:53.967 (iDetect) Fetching data from router using: ['sshpass', '-p', '***', 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=2', '[email protected]', '#!/bin/sh\n\t\t\t\t\texport PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH\n\t\t\t\t\ttest=$(which wl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "wl@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wl -i $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which iwinfo > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "iwinfo@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(iwinfo $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which wlanconfig > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "wlanconfig@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wlanconfig $iface list > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which brctl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "brctl"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which arp > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "arp"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tif [ -f /proc/net/arp ]; then\n\t\t\t\t\t\tprintf "procarp"\n\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tprintf none']
2018-08-27 15:15:53.637 Status: (iDetect) Started.
2018-08-27 15:15:53.901 Status: (iDetect) Entering work loop.
2018-08-27 15:15:53.902 Status: (iDetect) Initialized version 0.4.3, author 'ESCape'
2018-08-27 15:15:54.951 (iDetect) ssh command (router) returned:b'brctl'
2018-08-27 15:15:54.951 (iDetect) Parsed data from router: ['brctl']
2018-08-27 15:15:54.951 (iDetect) Constructed this cmd for the router to poll for present phones: export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;brctl showmacs br0 | grep '..:..:..:..:..:..' | awk '{print $ 2}';exit
2018-08-27 15:15:54.952 (iDetect) Creating device 'Anyone'.
2018-08-27 15:15:54.952 (iDetect) Device created for general/Anyone presence
2018-08-27 15:15:54.952 (iDetect) Creating device 'Override'.
Also:

Code: Select all

2018-08-27 15:19:34.511 Error: (iDetect) ----> Line 479 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py', function onHeartbeat
2018-08-27 15:19:34.511 Error: (iDetect) ----> Line 400 in '/home/pi/domoticz/plugins/Domoticz_iDetect/plugin.py', function onHeartbeat
2018-08-27 15:19:44.527 Error: (iDetect) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''.
Last edited by EdwinK on Monday 27 August 2018 15:27, edited 1 time in total.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
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 »

Hi EdwinK,
Creating device 'Override'
should have happened on the first run. I think you will have to enable the creation of new devices in the domoticz settings. At least when setting up the plugin and when adding new devices to monitor. After that you can disable it.

The plugin does not (yet) handle this situation nicely, so there is no meaningful error message. Will have to look into that.
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EdwinK »

Still nothing.Going to remove the plugin and try again.

edit: And now it seems to work.

edit2: At least the devices are created, and I see some data about absent phone and so, but at the moment no switching's occur
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
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 »

@EdwinK

Hmm.. Just had a look at some info about the AC51U. Seems to be a realtek chipset based router. The plugin should support it by falling back on the brctl command, but that will be a bit slower to respond to people (devices) leaving the house.

If you can experiment/find the right commands to query the realtek chipset, then i will gladly add hardware support to the plugin.

Brctl should also be okay for most uses though. Hope that's is working now. Switching after a mac address leaving can take several minutes with brctl, new connections should appear instantly (depending on poll frequency).
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EdwinK »

@EscApe I will try and keep an eye on it. Noticed it was using 'bctl' in the log. Let's see how it works. Polling is at 10 seconds
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by wizzard72 »

Hi @EscApe,

Good work! I going to test your very experimental plugin.
EscApe wrote: Monday 27 August 2018 15:01 wizzard73, Could you share the raw output of qcsapi_sockrpc get_assoc_records wifi0?
Can you also test the errorlevel if the command is run with a non existing interface name? (echo $? right after the command is run from cli)
The qcsapi_sockrpc get_assoc_records wifi0 shows:

Code: Select all

12:12:12:12:12:12: 1535387597
13:13:13:13:13:13: 1531696052
The qcsapi_sockrpc get_assoc_records wifi1 (non existing) shows:

Code: Select all

qcsapi_sockrpc get_assoc_records wifi1
QCS API error 1023: Operation only available on the primary WiFi interface

echo $?
1
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by wizzard72 »

Hi @EscApe,

Hereby my log:

Code: Select all

2018-08-27 16:52:48.389 (TESTWIFI) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE ALL 
2018-08-27 16:52:48.389 (TESTWIFI) Not running on Windows 
2018-08-27 16:52:48.417 (TESTWIFI) Checking if [ssh -V] will run: OK 
2018-08-27 16:52:48.445 (TESTWIFI) Checking if [sshpass -V] will run: OK 
2018-08-27 16:52:48.446 (TESTWIFI) Monitoring {'Wizzard72': '12:12:12:12:12:12'} for presence. 
2018-08-27 16:52:48.446 (TESTWIFI) Checking router capabilities and wireless interfaces 
2018-08-27 16:52:48.446 (TESTWIFI) Using password instead of ssh public key authentication (less secure!) 
2018-08-27 16:52:48.446 (TESTWIFI) Fetching data from router using: ['sshpass', '-p', '$NIKS!', 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=2', '[email protected]', '#!/bin/sh\n\t\t\t\t\texport PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH\n\t\t\t\t\thwmethod=false\n\t\t\t\t\ttest=$(which wl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "wl@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wl -i $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\thwmethod=true\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which iwinfo > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tif [ "$hwmethod" == true ]; then\n\t\t\t\t\t\t\t\tprintf "#"\n\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tprintf "iwinfo@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(iwinfo $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\thwmethod=true\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which wlanconfig > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tif [ "$hwmethod" == true ]; then\n\t\t\t\t\t\t\t\tprintf "#"\n\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tprintf "wlanconfig@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wlanconfig $iface list > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\thwmethod=true\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which qcsapi_sockrpc > /dev/null 2>&1)\n if [ $? == 0 ]; then\n\t\t\t\t\t\t\tif [ "$hwmethod" == true ]; then\n\t\t\t\t\t\t\t\tprintf "#"\n\t\t\t\t\t\t\tfi \n \t\t\tprintf "qcsapi_sockrpc@"\n\t\t\t\t\t\t\tfor iface in $(qcsapi_sockrpc get_primary_interface)\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(qcsapi_sockrpc get_assoc_records $iface > /dev/null 2>&1)\n \tif [ $? == 0 ]; then\n printf "$iface "\n fi\n done\n hwmethod=true\n fi\n\t\t\t\t\t\n\t\t\t\t\tif [ "$hwmethod" == true ] ; then\n\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which brctl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "brctl"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which arp > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "arp"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tif [ -f /proc/net/arp ]; then\n\t\t\t\t\t\tprintf "procarp"\n\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tprintf none'] 
2018-08-27 16:52:48.036 Status: (TESTWIFI) Started. 
2018-08-27 16:52:48.385 Status: (TESTWIFI) Entering work loop. 
2018-08-27 16:52:48.386 Status: (TESTWIFI) Initialized version 0.4.4b, author 'ESCape' 
2018-08-27 16:52:49.091 (TESTWIFI) ssh command (router) returned:b'wl@eth1 #qcsapi_sockrpc@wifi0 ' 
2018-08-27 16:52:49.091 (TESTWIFI) Capabilities data from router: ['wl@eth1 ', 'qcsapi_sockrpc@wifi0 '] 
2018-08-27 16:52:49.091 (TESTWIFI) Parsed data from router: ['wl', 'eth1 '] 
2018-08-27 16:52:49.092 (TESTWIFI) Parsed data from router: ['qcsapi_sockrpc', 'wifi0 '] 
2018-08-27 16:52:49.092 (TESTWIFI) Constructed this cmd for the router to poll for present phones: export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;wl -i eth1 assoclist | cut -d' ' -f2;qcsapi_sockrpc get_assoc_records wifi0 | cut -d' ' -f1 | cut -d':' -f1-6;exit 
2018-08-27 16:52:49.092 (TESTWIFI) Creating images from file '/home/pi/domoticz/plugins/iPaul/ihome.zip'. 
2018-08-27 16:52:49.092 Status: (TESTWIFI) Using chipset specific (wl) command on router for interfaces ['eth1'] 
2018-08-27 16:52:49.092 Status: (TESTWIFI) Using chipset specific (qcsapi_sockrpc) command on router for interfaces ['wifi0'] 
2018-08-27 16:52:49.105 Error: (TESTWIFI) 'onStart' failed 'KeyError'. 
2018-08-27 16:52:49.105 Error: (TESTWIFI) ----> Line 509 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onStart 
2018-08-27 16:52:49.105 Error: (TESTWIFI) ----> Line 351 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onStart 
2018-08-27 16:52:57.892 (TESTWIFI) Pushing 'onHeartbeatCallback' on to queue 
2018-08-27 16:52:57.940 (TESTWIFI) Processing 'onHeartbeatCallback' message 
2018-08-27 16:52:57.940 (TESTWIFI) Calling message handler 'onHeartbeat'. 
2018-08-27 16:52:57.941 Error: (TESTWIFI) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''. 
2018-08-27 16:52:57.941 Error: (TESTWIFI) ----> Line 513 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:52:57.941 Error: (TESTWIFI) ----> Line 434 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:53:17.901 (TESTWIFI) Pushing 'onHeartbeatCallback' on to queue 
2018-08-27 16:53:17.946 (TESTWIFI) Processing 'onHeartbeatCallback' message 
2018-08-27 16:53:17.946 (TESTWIFI) Calling message handler 'onHeartbeat'. 
2018-08-27 16:53:17.946 Error: (TESTWIFI) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''. 
2018-08-27 16:53:17.946 Error: (TESTWIFI) ----> Line 513 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:53:17.946 Error: (TESTWIFI) ----> Line 434 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:53:22.681 (TESTWIFI) Pushing 'onStopCallback' on to queue 
2018-08-27 16:53:22.709 (TESTWIFI) Processing 'onStopCallback' message 
2018-08-27 16:53:22.709 (TESTWIFI) Message handler 'onStop' not callable, ignored. 
2018-08-27 16:53:22.681 Status: (TESTWIFI) Stop directive received. 
2018-08-27 16:53:22.881 Status: (TESTWIFI) Stopping threads. 
2018-08-27 16:53:22.901 Status: (TESTWIFI) Exiting work loop. 
2018-08-27 16:53:22.902 Status: (TESTWIFI) Stopped. 
2018-08-27 16:53:27.748 Status: (TESTWIFI) Started. 
2018-08-27 16:53:28.075 (TESTWIFI) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE ALL 
2018-08-27 16:53:28.075 (TESTWIFI) Not running on Windows 
2018-08-27 16:53:28.099 (TESTWIFI) Checking if [ssh -V] will run: OK 
2018-08-27 16:53:28.117 (TESTWIFI) Checking if [sshpass -V] will run: OK 
2018-08-27 16:53:28.117 (TESTWIFI) Monitoring {'Wizzard72': '12:12:12:12:12:12'} for presence. 
2018-08-27 16:53:28.117 (TESTWIFI) Checking router capabilities and wireless interfaces 
2018-08-27 16:53:28.117 (TESTWIFI) Using password instead of ssh public key authentication (less secure!) 
2018-08-27 16:53:28.117 (TESTWIFI) Fetching data from router using: ['sshpass', '-p', '$NIKS!', 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=2', '[email protected]', '#!/bin/sh\n\t\t\t\t\texport PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH\n\t\t\t\t\thwmethod=false\n\t\t\t\t\ttest=$(which wl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "wl@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wl -i $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\thwmethod=true\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which iwinfo > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tif [ "$hwmethod" == true ]; then\n\t\t\t\t\t\t\t\tprintf "#"\n\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tprintf "iwinfo@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(iwinfo $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\thwmethod=true\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which wlanconfig > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tif [ "$hwmethod" == true ]; then\n\t\t\t\t\t\t\t\tprintf "#"\n\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tprintf "wlanconfig@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wlanconfig $iface list > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\thwmethod=true\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which qcsapi_sockrpc > /dev/null 2>&1)\n if [ $? == 0 ]; then\n\t\t\t\t\t\t\tif [ "$hwmethod" == true ]; then\n\t\t\t\t\t\t\t\tprintf "#"\n\t\t\t\t\t\t\tfi \n \t\t\tprintf "qcsapi_sockrpc@"\n\t\t\t\t\t\t\tfor iface in $(qcsapi_sockrpc get_primary_interface)\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(qcsapi_sockrpc get_assoc_records $iface > /dev/null 2>&1)\n \tif [ $? == 0 ]; then\n printf "$iface "\n fi\n done\n hwmethod=true\n fi\n\t\t\t\t\t\n\t\t\t\t\tif [ "$hwmethod" == true ] ; then\n\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which brctl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "brctl"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which arp > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "arp"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tif [ -f /proc/net/arp ]; then\n\t\t\t\t\t\tprintf "procarp"\n\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tprintf none'] 
2018-08-27 16:53:28.592 (TESTWIFI) ssh command (router) returned:b'wl@eth1 #qcsapi_sockrpc@wifi0 ' 
2018-08-27 16:53:28.592 (TESTWIFI) Capabilities data from router: ['wl@eth1 ', 'qcsapi_sockrpc@wifi0 '] 
2018-08-27 16:53:28.592 (TESTWIFI) Parsed data from router: ['wl', 'eth1 '] 
2018-08-27 16:53:28.592 (TESTWIFI) Parsed data from router: ['qcsapi_sockrpc', 'wifi0 '] 
2018-08-27 16:53:28.593 (TESTWIFI) Constructed this cmd for the router to poll for present phones: export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;wl -i eth1 assoclist | cut -d' ' -f2;qcsapi_sockrpc get_assoc_records wifi0 | cut -d' ' -f1 | cut -d':' -f1-6;exit 
2018-08-27 16:53:28.593 (TESTWIFI) Creating images from file '/home/pi/domoticz/plugins/iPaul/ihome.zip'. 
2018-08-27 16:53:28.023 Status: (TESTWIFI) Initialized version 0.4.4b, author 'ESCape' 
2018-08-27 16:53:28.022 Status: (TESTWIFI) Entering work loop. 
2018-08-27 16:53:28.592 Status: (TESTWIFI) Using chipset specific (wl) command on router for interfaces ['eth1'] 
2018-08-27 16:53:28.592 Status: (TESTWIFI) Using chipset specific (qcsapi_sockrpc) command on router for interfaces ['wifi0'] 
2018-08-27 16:53:28.599 Error: (TESTWIFI) 'onStart' failed 'KeyError'. 
2018-08-27 16:53:28.599 Error: (TESTWIFI) ----> Line 509 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onStart 
2018-08-27 16:53:28.599 Error: (TESTWIFI) ----> Line 351 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onStart 
2018-08-27 16:53:37.531 (TESTWIFI) Pushing 'onHeartbeatCallback' on to queue 
2018-08-27 16:53:37.550 (TESTWIFI) Processing 'onHeartbeatCallback' message 
2018-08-27 16:53:37.551 (TESTWIFI) Calling message handler 'onHeartbeat'. 
2018-08-27 16:53:37.551 Error: (TESTWIFI) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''. 
2018-08-27 16:53:37.551 Error: (TESTWIFI) ----> Line 513 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:53:37.551 Error: (TESTWIFI) ----> Line 434 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:53:47.539 (TESTWIFI) Pushing 'onHeartbeatCallback' on to queue 
2018-08-27 16:53:47.560 (TESTWIFI) Processing 'onHeartbeatCallback' message 
2018-08-27 16:53:47.560 (TESTWIFI) Calling message handler 'onHeartbeat'. 
2018-08-27 16:53:47.560 Error: (TESTWIFI) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute 'beats''. 
2018-08-27 16:53:47.560 Error: (TESTWIFI) ----> Line 513 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
2018-08-27 16:53:47.560 Error: (TESTWIFI) ----> Line 434 in /home/pi/domoticz/plugins/iPaul/plugin.py, function onHeartbeat 
So the detection works :-) Only a few error messages :-)
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 »

@wizzard72

The first error seems te refer to the creation of icons from the icon file. Did you copy the experimental plugin.py over an existing installation? You should, because i only supplied the new python code and it still depends on other parts.

The log looks looks very promising. Are the devices actually switching?

Unfortunately some initialization errors can still lead to unhandled errors (with meaningless messages) during polling, so the initialization part of the log is the most interesting.

EDIT:
Do you know, or can you find out, it the qcsapi_sockrpc get_primary_interface command will return all interfaces or just the primary? If it doesn't it would be even better if we (you ;-)) can find a command that does. Otherwise it will be a matter of time until a router comes along that was to be queried on multiple interfaces of that chipset.
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by wizzard72 »

EscApe wrote: Monday 27 August 2018 17:23 @wizzard72

The first error seems te refer to the creation of icons from the icon file. Did you copy the experimental plugin.py over an existing installation? You should, because i only supplied the new python code and it still depends on other parts.
I found the problem. I created a new folder and placed the files in there, but there are to many associations to do it like this. So now I have copied the plugin.py file over the existing plugin.

No more errors, but... I thought that "qcsapi_sockrpc get_assoc_records wifi0" would do the trick, but I was wrong. We have to do it the following way:
1. Count the total devices connected to wifi0 (5G)

Code: Select all

qcsapi_sockrpc get_count_assoc wifi0
2. Loop through the list of mac addresses discovered in step 1

Code: Select all

qcsapi_sockrpc get_station_mac_addr wifi0 <count step 1>
3. Match the mac address with the mac address of the phone, if this is true, then the device is present otherwise it's not.
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 »

@wizzard72

Do you know why get_assoc_records doesn't work and how the get_station_mac_addr results are different? The sample you supplied looked good. Is get_assoc_records not real time?

This change should do what you suggested. Please replace (line 232)

Code: Select all

pollscript=pollscript + ";qcsapi_sockrpc get_assoc_records " + knownif + " | cut -d' ' -f1 | cut -d':' -f1-6"
with:

Code: Select all

pollscript=pollscript + ";concount=$(qcsapi_sockrpc get_count_assoc " + knownif + ");for i in $(seq 1 $concount); do qcsapi_sockrpc get_station_mac_addr " + knownif + " $i; done"
The one line loop is pure theory. I have no way to test it, so there could be typos or other errors. Keeping my fingers crossed ;)

EDIT: I'm assuming the count starts at 1. If it starts at 0 then the sequence must be modified to $(seq 0 $concount-1) or something like that...
Last edited by EscApe on Monday 27 August 2018 20:40, edited 2 times in total.
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by wizzard72 »

EscApe wrote: Monday 27 August 2018 20:37 @wizzard72

Do you know why get_assoc_records doesn't work and how the get_station_mac_addr results are different? The sample you supplied looked good. Is get_assoc_records not real time?
Correct it's not realtime.

I'm going to try the code. Let you know the results.
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by wizzard72 »

@EscApe,

The code

Code: Select all

pollscript=pollscript + ";concount=$(qcsapi_sockrpc get_count_assoc " + knownif + ");for i in $(seq 1 $concount); do qcsapi_sockrpc get_station_mac_addr " + knownif + " $i; done"
is not working
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 »

@wizzard72

My bad :oops: The router os does not have the seq command.

If that was the only problem, then this should work (at least the loop works on my asus with dummy echo commands)

Code: Select all

pollscript=pollscript + ";concount=$(qcsapi_sockrpc get_count_assoc " + knownif + ");i=1;while [[ $i -le $concount ]]; do qcsapi_sockrpc get_station_mac_addr " + knownif + " $i;i=$((i+1));done"
If it doesn't can you try the following script on the router itself and share the output?

Code: Select all

concount=$(qcsapi_sockrpc get_count_assoc wifi0)
i=1
while [[ $i -le $concount ]]; do
        qcsapi_sockrpc get_station_mac_addr wifi0 $i
        i=$((i+1))
done
If the script on the router works but the plugin doesn't then i'm very interested in the debug log. You can share it as PM if you want to keep mac addresses and such secret.

EDIT: Did you try if get_station_mac_addr is indeed faster (real-time'ish) then get_assoc_records? Otherwise getting this loop to work might be a waste of time for both of us.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest