Page 18 of 55

Re: Python plugin: Presence detection from wireless router

Posted: Thursday 06 September 2018 22:19
by sapnho
@escApe: I discovered a strange problem. When I reboot Domoticz I get these error messages:
2018-09-06 22:12:17.943 Error: (iDetect iPhones) SSH subprocess failed with error (255):b''
2018-09-06 22:12:17.944 Error: (iDetect iPhones) Could not retreive router capabilities from 192.168.178.55
2018-09-06 22:12:17.984 Error: (iDetect iPhones) SSH subprocess failed with error (255):b''
2018-09-06 22:12:17.984 Error: (iDetect iPhones) Could not retreive router capabilities from 192.168.178.56
2018-09-06 22:12:18.022 Error: (iDetect iPhones) SSH subprocess failed with error (255):b''
2018-09-06 22:12:18.022 Error: (iDetect iPhones) Could not retreive router capabilities from 192.168.178.57
2018-09-06 22:12:18.125 Error: (iDetect RPi Fnatenrahmen) SSH subprocess failed with error (255):b''
2018-09-06 22:12:18.125 Error: (iDetect RPi Fnatenrahmen) Could not retreive router capabilities from 192.168.178.55
2018-09-06 22:12:18.165 Error: (iDetect RPi Fnatenrahmen) SSH subprocess failed with error (255):b''
2018-09-06 22:12:18.165 Error: (iDetect RPi Fnatenrahmen) Could not retreive router capabilities from 192.168.178.56
2018-09-06 22:12:18.212 Error: (iDetect RPi Fnatenrahmen) SSH subprocess failed with error (255):b''
2018-09-06 22:12:18.213 Error: (iDetect RPi Fnatenrahmen) Could not retreive router capabilities from 192.168.178.57
2018-09-06 22:12:27.729 Error: (iDetect RPi Fnatenrahmen) No usable commandlines or routers to check presence. Check configuration and routers.
2018-09-06 22:12:27.730 Error: (iDetect iPhones) No usable commandlines or routers to check presence. Check configuration and routers.
2018-09-06 22:13:35.349 Error: (iDetect iPhones) No usable commandlines or routers to check presence. Check configuration and routers.
2018-09-06 22:14:35.347 Error: (iDetect iPhones) No usable commandlines or routers to check presence. Check configuration and routers.
The only way to stop them is to deactivate iDetect in Hardware, update, enable it and update again. After that no more problems.

Any idea how to fix this?

Re: Python plugin: Presence detection from wireless router

Posted: Thursday 06 September 2018 22:34
by EscApe
Not strange at all, but an oversight on my part :oops:

Your Domoticz is starting before the network interface of the raspberry is completely initialized. When introducing multi router support i removed the retry, so it no longer copes with this situation. Just pressing update on the settings page will fix it (no need to disable/enable). You can also configure Domoticz to start after the network is fully operational (which i prefer anyway), but that takes some tinkering with the startup script or systemd (depending on which u use).

The plugin should recover from the network not being up when starting.... will fix this in the next couple of days. For now, just press update or never reboot the raspberry ;-)

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 3:30
by sapnho
Ah, great, an easy fix in 0.63 then. ;) Thanks!

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 10:30
by poudenes
Seem a nice and great plugin. Only Apple Time Capsule users cannot use this. There is no ssh access option.

Keep up the good work!


Verzonden vanaf mijn iPhone met Tapatalk Pro

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 11:24
by mvzut
EscApe wrote: Thursday 06 September 2018 22:34 You can also configure Domoticz to start after the network is fully operational (which i prefer anyway), but that takes some tinkering with the startup script or systemd (depending on which u use).
If you use a Raspberry Pi this is very easy to do: just start "sudo raspi-config" from the command line, go to "Boot Options" and select "B2 Wait for Network at Boot".

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 16:42
by sapnho
@mvzut: Good workaround, thanks!

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 16:54
by wizzard72
Hi EscApe,

I found a little bug. It's in the qcsapi_sockrpc part:

Code: Select all

"export PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH;wl -i eth1 assoclist | cut -d' ' -f2;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;exit"]
The command "do qcsapi_sockrpc get_station_mac_addr wifi0 $i" must start from 0 instead of 1 (i=1). The While loop loops too far, so I get this errorcode: "QCS API ERROR 34: PARAMETER VALUE OUT OF RANGE".


So ik there are 2 devices on the 5G Wifi, then:
  • qcsapi_sockrpc get_station_mac_addr wifi0 0
  • qcsapi_sockrpc get_station_mac_addr wifi0 1
must be queried.

I don't know why I didn't see it earlier :-(

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 16:58
by wizzard72
Also I'm not able to switch On the Override switch manually.

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 17:11
by EscApe
@wizzard72

I will fix the qcsapi loop (next version is coming soon). Starting at 1 is based on the information i got when we implemented this, so i do hope it is not router specific.

The override button could be disabled in the plugin settings. What is your current 'override mode'?

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 20:21
by EscApe
Just uploaded version 0.6.3

Fixed: Error handling that was insufficient after introducing multi router support.
Fixed: Query for Quantenna chipset (Asus AC87 and others) was starting at wifi0 1 but should start at wifi0 0.

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 21:15
by sapnho
Ah, now I get plenty of errors with 0.63
2018-09-07 21:12:48.766 Error: (iDetect iPhones) 'onStart' failed 'NameError'.
2018-09-07 21:12:48.766 Error: (iDetect iPhones) ----> Line 616 in '/home/pi/domoticz/plugins/iDetect/plugin.py', function onStart
2018-09-07 21:12:48.766 Error: (iDetect iPhones) ----> Line 430 in '/home/pi/domoticz/plugins/iDetect/plugin.py', function onStart
2018-09-07 21:12:48.819 Error: (iDetect RPi Fnatenrahmen) 'onStart' failed 'NameError'.
2018-09-07 21:12:48.819 Error: (iDetect RPi Fnatenrahmen) ----> Line 616 in '/home/pi/domoticz/plugins/iDetect/plugin.py', function onStart
2018-09-07 21:12:48.819 Error: (iDetect RPi Fnatenrahmen) ----> Line 430 in '/home/pi/domoticz/plugins/iDetect/plugin.py', function onStart
2018-09-07 21:13:05.864 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:05.864 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:15.881 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:15.881 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:25.847 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:25.897 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:35.863 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:35.863 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:45.879 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:45.880 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:55.895 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:13:55.896 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:14:05.862 Error: (iDetect RPi Fnatenrahmen) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
2018-09-07 21:14:05.862 Error: (iDetect iPhones) Plugin initialization did not complete successfully. Check the (debug) log for startup errors.
Rebooted twice.

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 22:26
by EscApe
My bad! :oops:
Left a test in there that broke the plugin for multiple routers. Should be fixed now... however... I had to edit directly on github (am not at my computer) and could not test, so I hope that didn’t introduce indentation errors in python (probably not).
0.6.4 is available

Re: Python plugin: Presence detection from wireless router

Posted: Friday 07 September 2018 22:45
by sapnho
Seems to work again, thanks!

Re: Python plugin: Presence detection from wireless router

Posted: Saturday 08 September 2018 13:37
by sapnho
When rebooting, I get this round of errors but without doing anything, it works fine after that.
2018-09-08 11:22:50.632 Error: (iDetect iPhones) SSH subprocess failed with error (255):b''
2018-09-08 11:22:50.632 Error: (iDetect iPhones) Could not retreive router capabilities from 192.168.178.55
2018-09-08 11:22:50.685 Error: (iDetect iPhones) SSH subprocess failed with error (255):b''
2018-09-08 11:22:50.686 Error: (iDetect iPhones) Could not retreive router capabilities from 192.168.178.56
2018-09-08 11:22:50.739 Error: (iDetect iPhones) SSH subprocess failed with error (255):b''
2018-09-08 11:22:50.739 Error: (iDetect iPhones) Could not retreive router capabilities from 192.168.178.57
2018-09-08 11:22:50.858 Error: (iDetect RPi Fnatenrahmen) SSH subprocess failed with error (255):b''
2018-09-08 11:22:50.858 Error: (iDetect RPi Fnatenrahmen) Could not retreive router capabilities from 192.168.178.55
2018-09-08 11:22:50.892 Error: (iDetect RPi Fnatenrahmen) SSH subprocess failed with error (255):b''
2018-09-08 11:22:50.892 Error: (iDetect RPi Fnatenrahmen) Could not retreive router capabilities from 192.168.178.56
2018-09-08 11:22:50.929 Error: (iDetect RPi Fnatenrahmen) SSH subprocess failed with error (255):b''
2018-09-08 11:22:50.929 Error: (iDetect RPi Fnatenrahmen) Could not retreive router capabilities from 192.168.178.57
2018-09-08 11:23:00.448 Error: (iDetect RPi Fnatenrahmen) 192.168.178.56 was not properly initialized. Retrying to get router capabilities (and skipping this poll round).
Maybe a minute of wait time before it starts?

Re: Python plugin: Presence detection from wireless router

Posted: Saturday 08 September 2018 14:37
by EscApe
So it does recover from these errors? Glad to hear that :D

Using multiple servers increases the amount of error logging, which is unnecessary in this situation. I will see what I can do about that in the next version.

A wait time is not an option, because the plugin system is single threaded and it would block everything else. To prevent these errors at startup you will have to make sure that the network is up before Domoticz starts. Did you follow the instructions given by mvzut?

Re: Python plugin: Presence detection from wireless router

Posted: Saturday 08 September 2018 18:27
by sapnho
EscApe wrote: Saturday 08 September 2018 14:37Did you follow the instructions given by mvzut?
Yes, I did.

Re: Python plugin: Presence detection from wireless router

Posted: Saturday 08 September 2018 21:32
by EscApe
This might help... new and improved on GitHub. Please keep an eye on the log and check if absence/presence is properly detected. I had to make some major changes to better accommodate multiple routers. It works well on my single router setup, but i cannot test in a multi router environment.

The plugin will now only log an error after 3 failures in a row on the same router. It will also throttle the poll frequency after a ssh failure. 30 seconds of minimum wait time for every failure, with a maximum of 2 minutes. That should reduce error message drastically. You will still get 3 messages for your three routers if the network is not operational, but chances are that the network is up before the 3 errors have occurred. Especially since after the first error the polling will start throttling the frequency.

I am considering to start throttling a little later (after 2-3 failures), but let's first see how this works in real life.

**version 0.6.5**
- Improved: Lowering poll frequency on errors on a per router basis (one failed router will no longer affect the rest).
- Improved: Less logging of non critical errors (one or two ssh failures is no reason to worry .. or log .. since the connection can recover on the next poll.)

Re: Python plugin: Presence detection from wireless router

Posted: Saturday 08 September 2018 22:05
by sapnho
So far, so good!

(Meaning no error messages after a reboot) ;)

Re: Python plugin: Presence detection from wireless router

Posted: Saturday 08 September 2018 22:12
by sapnho
BTW, the password is still in the log files. :ugeek:

Re: Python plugin: Presence detection from wireless router

Posted: Sunday 09 September 2018 16:36
by EscApe
Now new features or fixes, but i have tweaked the logging a bit

**version 0.6.6**
- Improved: Debug logging for the ssh session now hides the ssh password.
- Improved: Presence changes are now logged (without needing debug mode), so you can see something is going on.
- Improved: Some more log tweaking (removed some redundancies and changed log levels for some messages)