Python plugin: Presence detection from wireless router

Python and python framework
EscApe
Posts: 142
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Friday 29 June 2018 21:29

Did you update to the latest version and try the new #forcegeneric option (as described on github and in the previous posts)?
That should force the plugin to use brctl or arp and ignore the wl command even if the command is available on the router.

In your case the command seems to be available, but unless we/you can figure out what interfaces to query we can’t use it. It could be as simple as the router using other interfaces names than eth*, wlan*, ath* and the script simply filtering them out.

User avatar
Innovator
Posts: 15
Joined: Tuesday 20 February 2018 13:33
Target OS: NAS (Synology & others)
Domoticz version: 8924
Location: Amsterdam
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Innovator » Saturday 30 June 2018 9:20

@Escape Thanks for the advice; executed and working! :D
Synology DS918+ /DS412+
ASUS BRT-AC828, RT-AC86U, RT-AC68U

drwurn
Posts: 33
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Saturday 30 June 2018 15:58

My phone (android) has multiple unwanted absence while being at home.
My wife's phone (Iphone) is working properly.

Already looked in my phone but wifi power saver is turned off.
It looks like it's happening after an hour or so when I didn't was active on my phone, and after that hour it's happening multiple times per hour.
The period that my phone is offline are a few minuts and it's going online without touching my phone.

Already changed the poll and grace period a few times but so far it didn't work out.

What should be a good poll/grace time in my case?
Don't really care if it takes a few minutes to confirm absence, if presence confirmation is fast.

EscApe
Posts: 142
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 04 July 2018 14:00

@drwurn

Hard to say. The detection depends on a stable wifi connection or a grace period that will bridge the temporary connection drops. If your wife's phone sometimes drops the connection for more than 10 minutes, you will need a grace period longer than that. The grace period does not influence how quickly a new presence is detected. Only absence.

In this case do NOT choose a longer poll time. Long poll times will affect how quickly presence is detected AND if your wif'e's phone drops the connection often, then the chance will increase that you are checking for presence during such a connection drop. Polling often will ensure the grace period will be reset every time the phone is (briefly) connected.

I'm afraid you'll just have to experiment to find the ideal combination of settings.

Prutsium
Posts: 24
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Prutsium » Friday 06 July 2018 22:01

Wierd .....

I have it running on my own Asus RT68 and works great.
Trying to setup the same on the RT87 and no luck .... SSH is enabled and no certificate.

Code: Select all

Result:
2018-07-06 22:58:49.975 (Presence detection Phones) Output from router: b''
2018-07-06 22:58:56.410 MQTT: Topic: domoticz/in, Message: {"idx":23,"nvalue":0,"svalue":"0;13662.7","Battery":57,"RSSI":6}
2018-07-06 22:58:56.520 MQTT: Topic: domoticz/in, Message: {"idx":20,"nvalue":0,"svalue":"230","Battery":57,"RSSI":6}
2018-07-06 22:58:56.628 MQTT: Topic: domoticz/in, Message: {"idx":22,"nvalue":0,"svalue":"0.000","Battery":57,"RSSI":6}
2018-07-06 22:59:04.837 (Presence detection Phones) Pushing 'onHeartbeatCallback' on to queue
2018-07-06 22:59:04.854 (Presence detection Phones) Processing 'onHeartbeatCallback' message
2018-07-06 22:59:04.854 (Presence detection Phones) Calling message handler 'onHeartbeat'.
2018-07-06 22:59:04.854 (Presence detection Phones) devid2domid: {'Jerome': 2}
2018-07-06 22:59:04.854 (Presence detection Phones) Checking router capabilities and wireless interfaces
2018-07-06 22:59:04.854 (Presence detection Phones) Pushing 'PollIntervalDirective' on to queue
2018-07-06 22:59:04.854 (Presence detection Phones) Using ssh public key authentication (~/.ssh/id_rsa.pub) for OS user running domoticz.
2018-07-06 22:59:04.870 (Presence detection Phones) The OS user profile running domoticz is:	root
2018-07-06 22:59:04.870 (Presence detection Phones) Fetching data from router using ssh
2018-07-06 22:59:04.870 (Presence detection Phones) command: ['ssh', '-o', 'ConnectTimeout=2', 'oxy@192.168.199.1', '#!/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\t\t\t\t\t\t\t\t\t\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-07-06 22:59:04.985 (Presence detection Phones) Returncode ssh command: 255

EscApe
Posts: 142
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Friday 06 July 2018 22:39

Hi Prutsium,

My frist guess would be a authentication failure. You say no certificate, but the plugin up is trying to use key based authentication according to the log segment. Seems like you are getting no info from the router at all.

Prutsium
Posts: 24
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Prutsium » Saturday 07 July 2018 6:26

EscApe wrote:
Friday 06 July 2018 22:39
Hi Prutsium,

My frist guess would be a authentication failure. You say no certificate, but the plugin up is trying to use key based authentication according to the log segment. Seems like you are getting no info from the router at all.
<t>When i try to log into the router directly from the Pi running domoticz with SSH ***@192.168.199.1 i get no errors so seems SSH from the Pi works.<br/>
<br/>
No clue whats happening here as i installed it before without issues on a different system.</t>

Prutsium
Posts: 24
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Prutsium » Saturday 07 July 2018 6:26

EscApe wrote:
Friday 06 July 2018 22:39
Hi Prutsium,

My frist guess would be a authentication failure. You say no certificate, but the plugin up is trying to use key based authentication according to the log segment. Seems like you are getting no info from the router at all.
<t>When i try to log into the router directly from the Pi running domoticz with SSH ***@192.168.199.1 i get no errors so seems SSH from the Pi works.<br/>
<br/>
No clue whats happening here as i installed it before without issues on a different system.</t>

Prutsium
Posts: 24
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Prutsium » Saturday 07 July 2018 6:36

Prutsium wrote:
Saturday 07 July 2018 6:26
EscApe wrote:
Friday 06 July 2018 22:39
Hi Prutsium,

My frist guess would be a authentication failure. You say no certificate, but the plugin up is trying to use key based authentication according to the log segment. Seems like you are getting no info from the router at all.
<t>When i try to log into the router directly from the Pi running domoticz with SSH ***@192.168.199.1 i get no errors so seems SSH from the Pi works.<br/>
<br/>
No clue whats happening here as i installed it before without issues on a different system.</t>
Ok got it working have generated a key and then it worked. Seems the option without key and using user & pass doesnt work somehow.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest