Python plugin: Presence detection from wireless router

Python and python framework

Moderator: leecollings

gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Sunday 16 February 2020 8:23
With ARP pfSense reports after approx. 20 minutes that the device is not present in the network.
What are your poll interval and grace period settings for the plugin? As a rule of thumb use 3-4 polls within the grace period. Having just 1 poll within the grace period dramatically increases the chance to miss a connected device on a poll connection delay/error and any (short) connection drop by a phone.
If your devices go offline long enough to disappear from the arp table (which is already unusual on my asus router) then maybe you can modify the arp timeout on pfSense(?)
Frankly, I don’t know how to use nmap in detail because I have just installed it. But I noticed it has a lot of possibilities.
I find it difficult to find out which arguments to use for poll and grace, because this is a bit out of my league. However when I search on the internet for the words nmap, poll and grace it comes up in this part of the nmap manual: https://nmap.org/book/man-performance.html
Maybe you are willing to assist here?
EscApe wrote: Sunday 16 February 2020 8:23
But pfSense has the possibility to install packages.
There is a package NMAP, which scans quickly whether a device is online or not.
It might be even easier to use nmap from the domoticz host itself, but wouldn’t the already available ping approach work just as well if you already know the (fixed) ip addresses? I have been experimenting with some network discovery but it is a resource heavy and slow process for the entire network, which is not desirable if you want to poll frequently.
Last week I had to reinstall my Rpi/Domoticz (raspbian stretch) system due to a crash, so I made a fresh Raspbian Buster system. On the stretch system I used the (modified) presence detection python script example on the Domoticz wiki page, which uses arping. This actually worked quite well, but on Buster it reports an error because a used method

Code: Select all

 base64.decodestring(s)
has been deprecated in python 3. The only reason I never tried idetect is that I, until now, I didn’t know how to pass the ssh login issue on pfSense. The mini-pc that runs pfSense on is quite fast and doesn’t have any resource problems in network scanning. There is also an arping package avaialable for pfSense, which may be more suitable for presence detecting?
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

The 3 phones (2 motorla’s and 1 Samsung) I want to presence detect also seem to have wifi drops of approx 2-10 minutes when I look in the text log of the switches that idetect has created. For the Samsung I have figured out the problem, but still looking for a motorola fix. Somebody experience in this?
EscApe
Posts: 535
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 »

Frankly, I don’t know how to use nmap in detail because I have just installed it. But I noticed it has a lot of possibilities.
I find it difficult to find out which arguments to use for poll and grace, because this is a bit out of my league. However when I search on the internet for the words nmap, poll and grace it comes up in this part of the nmap manual: https://nmap.org/book/man-performance.html
Maybe you are willing to assist here?
I meant the poll interval and grace period you set for the idetect plugin when using arp on the pfSense (which was working for you except for the false absence). The right combination might just solve your problem. The nmap approach look like overkill te me.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Sunday 16 February 2020 11:34
Frankly, I don’t know how to use nmap in detail because I have just installed it. But I noticed it has a lot of possibilities.
I find it difficult to find out which arguments to use for poll and grace, because this is a bit out of my league. However when I search on the internet for the words nmap, poll and grace it comes up in this part of the nmap manual: https://nmap.org/book/man-performance.html
Maybe you are willing to assist here?
I meant the poll interval and grace period you set for the idetect plugin when using arp on the pfSense (which was working for you except for the false absence). The right combination might just solve your problem. The nmap approach look like overkill te me.
Sorry, default: 15 and 30
EscApe
Posts: 535
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 »

gschmidt wrote: Sunday 16 February 2020 11:54
EscApe wrote: Sunday 16 February 2020 11:34
Frankly, I don’t know how to use nmap in detail because I have just installed it. But I noticed it has a lot of possibilities.
I find it difficult to find out which arguments to use for poll and grace, because this is a bit out of my league. However when I search on the internet for the words nmap, poll and grace it comes up in this part of the nmap manual: https://nmap.org/book/man-performance.html
Maybe you are willing to assist here?
I meant the poll interval and grace period you set for the idetect plugin when using arp on the pfSense (which was working for you except for the false absence). The right combination might just solve your problem. The nmap approach look like overkill te me.
Sorry, default: 15 and 30
Have you tried increasing the grace period? You could start high, like 90 seconds, and if it is stable (no false absence) for a few days reduce it to 60 etc... until you find a value that works for you. If your phones drop their connections or don’t generate any traffic for a long time then no method will give you a quick and still reliable way to detect absence/presence. You would always need a even longer time to confirm a phone is really absent. (New) presence will still be detected quickly, because you are sill polling every 15 seconds.

True wireless detection (on an accesspoint) would be more reliable.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

True wireless detection (on an accesspoint) would be more reliable.
My pfSense router has no wireless, I use 2 TP-Link AP’s for wireless connections.
One AP has ddwrt, and the other (tp-link eap245) original software.

What would be the network discovery functions to use on both ap’s?
EscApe
Posts: 535
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 »

gschmidt wrote: Sunday 16 February 2020 12:39
True wireless detection (on an accesspoint) would be more reliable.
My pfSense router has no wireless, I use 2 TP-Link AP’s for wireless connections.
One AP has ddwrt, and the other (tp-link eap245) original software.

What would be the network discovery functions to use on both ap’s?
I don’t know every type of router but at least dd-wrt would probably support ssh and autodetection by the plugin. Original firmware might to. Maybe ssh needs te be enabled in the ap configuration(?)
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Sunday 16 February 2020 13:12
gschmidt wrote: Sunday 16 February 2020 12:39
True wireless detection (on an accesspoint) would be more reliable.
My pfSense router has no wireless, I use 2 TP-Link AP’s for wireless connections.
One AP has ddwrt, and the other (tp-link eap245) original software.

What would be the network discovery functions to use on both ap’s?
I don’t know every type of router but at least dd-wrt would probably support ssh and autodetection by the plugin. Original firmware might to. Maybe ssh needs te be enabled in the ap configuration(?)
Most of the time the Phones are connected to the AP1 (original TP-Link firmware).
Keep in mind that both 2.4 and 5ghz have the same SSID, the phones will switch to either the 2.4 or 5ghz band depending on the distance to the Access Point.

When I configure a tracker (default settings, no arguments) in iDetect for the AP1, I get the following domoticz log:

Code: Select all

2020-02-18 19:07:41.967 Error: (iDetect) 192.168.1.5 ====> SSH returned error:usage: wlanconfig athX create wlandev wifiX
2020-02-18 19:07:41.967 wlanmode [sta|adhoc|ap|monitor|wrap|p2pgo|p2pcli|p2pdev|specialvap|smart_monitor|lp_iot_mode]
2020-02-18 19:07:41.967 [wlanaddr <mac_addr>] [mataddr <mac_addr>] [bssid|-bssid] [vapid <0-15>] [nosbeacon]
2020-02-18 19:07:41.967 usage: wlanconfig athX destroy
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds add-addr wds_ni_macaddr wds_macaddr
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds reset-addr macaddr
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds reset-table
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds read-addr wds_ni_macaddr
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds dump-wdstable
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds read-table
2020-02-18 19:07:41.967 usage: wlanconfig athX hmwds rem-addr <mac_addr>
2020-02-18 19:07:41.967 usage: wlanconfig athX ald sta-enable <sta_mac_addr> <0/1>
2020-02-18 19:07:41.967 usage: wlanconfig athX hmmc add ip mask
2020-02-18 19:07:41.967 usage: wlanconfig athX hmmc del ip mask
2020-02-18 19:07:41.967 usage: wlanconfig athX hmmc dump
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm setbssmax <idle period in seconds> [<idle option>]
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm getbssmax
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm tfsreq <filename>
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm deltfs
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm timintvl <Interval>
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm gettimparams
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm timrate <highrateEnable> <lowRateEnable>
2020-02-18 19:07:41.967 usage: wlanconfig athX wnm bssterm <delay in TBTT> [<duration in minutes>]
2020-02-18 19:07:41.967 usage: wlanconfig athX addssid ssidname per_value(0--100)
2020-02-18 19:07:41.967 usage: wlanconfig athX addsta macaddr(example:112233445566) per_value(0--100)
2020-02-18 19:07:41.967 usage: wlanconfig athX delssid ssidname
2020-02-18 19:07:41.967 usage: wlanconfig athX delsta macaddr
2020-02-18 19:07:41.967 usage: wlanconfig athX showatftable [show_per_peer_table<1>]
2020-02-18 19:07:41.967 usage: wlanconfig athX showairtime
2020-02-18 19:07:41.967 usage: wlanconfig athX flushatftable
2020-02-18 19:07:41.967 usage: wlanconfig athX addatfgroup groupname ssid
2020-02-18 19:07:41.967 usage: wlanconfig athX configatfgroup groupname value (0 - 100))
2020-02-18 19:07:41.967 usage: wlanconfig athX delatfgroup groupname
2020-02-18 19:07:41.967 usage: wlanconfig athX showatfgroup
2020-02-18 19:07:41.967 usage: wlanconfig athX addtputsta macaddr tput airtime(opt)
2020-02-18 19:07:41.967 usage: wlanconfig athX deltputsta macaddr
2020-02-18 19:07:41.967 usage: wlanconfig athX showtputtbl
2020-02-18 19:07:41.967 usage: wlanconfig athX atfstat
2020-02-18 19:07:41.967 usage: wlanconfig athX vendorie add len <oui+pcap_data in bytes> oui <eg:xxxxxx> pcap_data <eg:xxxxxxxx> ftype_map <eg:xx>
2020-02-18 19:07:41.967 usage: wlanconfig athX vendorie update len <oui+pcap_data in bytes> oui <eg:xxxxxx> pcap_data <eg:xxxxxxxx> ftype_map <eg:xx>
2020-02-18 19:07:41.967 usage: wlanconfig athX vendorie remove len <oui+pcap_data in bytes> oui <eg:xxxxxx> pcap_data <eg:xx>
2020-02-18 19:07:41.967 usage: wlanconfig athX vendorie list
2020-02-18 19:07:41.967 usage: wlanconfig athX vendorie list len <oui in bytes> oui <eg:xxxxxx>
2020-02-18 19:07:41.967
2020-02-18 19:07:41.968 Error: (iDetect) 192.168.1.5 ====> SSH returned empty response. Transport active: True 
Looking at the log I notice iDetect finds the "wlanconfig" function, but it does not find the correct arguments (i think).
The WLAN interfaces of AP1 are called ath0 (2.4GHz) and ath10 (5 GHz).

ath0 (2.4GHz) list:

Code: Select all

/bin $ wlanconfig ath0 list
ADDR               AID CHAN TXRATE RXRATE RSSI MINRSSI MAXRSSI IDLE  TXSEQ  RXSEQ  CAPS        ACAPS     ERP    STATE MAXRATE(DOT11) HTCAPS ASSOCTIME    IEs                                MODE                   PSMODE RXNSS TXNSS
78:11:dc:23:2d:0a    2    1  65M     66M   55      67      67    0  12699   42544  EPSs         0          f              0               P 51:38:51  RSN WME                              IEEE80211_MODE_11NG_HT20   0        1     1
f4:39:15:f8:44:88    1    1 127M     52M   42      35      55    0  29472   41296  EPSs         0         1f              0              PG 48:51:47  RSN WME                              IEEE80211_MODE_11NG_HT20   1        2     2
04:b4:36:c8:a8:8d    3    1  70M     11M   42      20      58    0  51802   50112  EPSs         0          f              0              AP 00:47:21  RSN WME                              IEEE80211_MODE_11NG_HT20   0        1     1
/bin $
ath10 (5GHz) list:

Code: Select all

/bin $ wlanconfig ath10 list
ADDR               AID CHAN TXRATE RXRATE RSSI MINRSSI MAXRSSI IDLE  TXSEQ  RXSE                                                                                        Q  CAPS        ACAPS     ERP    STATE MAXRATE(DOT11) HTCAPS ASSOCTIME    IEs   M                                                                                        ODE                   PSMODE RXNSS TXNSS
14:95:ce:63:f1:c8    1   48 866M    780M   52      27      55    0      0   6553                                                                                        5    EP         0          b              0            AWPS 54:45:37  RSN WME IE                                                                                        EE80211_MODE_11AC_VHT80   1        2     2
d4:f5:47:93:46:5c    3   48 433M    390M   37      26      44    0      0   6553                                                                                        5   EPs         0          b              0            AWPS 16:53:00  RSN WME IE                                                                                        EE80211_MODE_11AC_VHT80   1        1     1
44:07:0b:46:5f:26    5   48 390M    390M   27      19      44    0      0   6553                                                                                        5   EPs         0          b              0             WPS 15:31:22  RSN WME IE                                                                                        EE80211_MODE_11AC_VHT80   0        1     1
f4:06:69:32:e7:a3    6   48 390M    263M   35      27      45    0      0   6553                                                                                        5   EPs         0          b              0            WQSM 01:43:10  RSN WME IE                                                                                        EE80211_MODE_11AC_VHT80   0        1     1
d4:63:c6:66:1e:2e    4   48 150M    150M   41      29      48    0      0   6553                                                                                        5    EP         0          b              0             WPS 00:48:45  RSN WME IE                                                                                        EE80211_MODE_11NA_HT40   1        1     1
04:b4:29:c8:b2:8a    7   48 390M    325M   29      23      40    0      0   6553                                                                                        5  EPSs         0          b              0            AWPS 00:12:30  RSN WME IE                                                                                        EE80211_MODE_11AC_VHT80   0        1     1
30:4b:07:f1:1b:d3    2   48 433M      6M   40      31      40    0      0   6553                                                                                        5    EP         0          b              0            AWPS 00:08:22  RSN WME IE                                                                                        EE80211_MODE_11AC_VHT80   1        1     1
How should configuration of the tracker in iDetect look like to list both wlan interfaces (ath0 and ath10)?
Because the phones can either be on the 2.4GHz or 5GHz band.
EscApe
Posts: 535
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 »

Can you provide some more logging? From the moment the plugin starts until the first error. What happens before the failure will probably tell us more than the failure itself.

The plugin is designed to deal with multiple wireless interfaces on one router. I also use it on my Asus router (2.4 + 5). Maybe it does not detect the interfaces correctly on you router and messes up the wlanconfig command by omitting the interface name... but now I’m just guessing, the logs will show what’s going on.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

My tracker(s) config for AP1 and AP2 is

Code: Select all

192.168.1.5#ssh=wlanconfig ath10 list, 192.168.1.5#ssh=wlanconfig ath0 list, 192.168.1.2#user=root&password=xxxxxx
both trackers for AP1 work, the tracker for AP2 (ddwrt firmware) seems to have no build in command for listing connected devices

Code: Select all

 2020-02-18 20:37:33.082 Status: (iDetect) Tracker activated:192.168.1.5 port 22, user: admin, type: prefab and options: {'ssh': 'wlanconfig ath10 list'}
2020-02-18 20:37:33.083 Status: (iDetect) Tracker activated:192.168.1.5 port 22, user: admin, type: prefab and options: {'ssh': 'wlanconfig ath0 list'}
2020-02-18 20:37:35.150 Status: (iDetect) 192.168.1.2 ====> SSH connection established
2020-02-18 20:37:35.168 Status: (iDetect) 192.168.1.2 No supported chipset found. Using generic mode: ip
2020-02-18 20:37:35.168 Status: (iDetect) Tracker activated:192.168.1.2 port 22, user: root, type: default and options: {'user': 'root', 'password': '********'}
2020-02-18 20:37:48.292 Status: (iDetect) 192.168.1.5 ====> SSH connection established
2020-02-18 20:37:48.307 Status: (iDetect) 192.168.1.5 ====> SSH connection established
2020-02-18 20:37:48.113 Error: (iDetect) 192.168.1.2 ====> SSH returned empty response. Transport active: True
2020-02-18 20:38:03.143 Error: (iDetect) 192.168.1.2 ====> SSH returned empty response. Transport active: True
2020-02-18 20:38:18.170 Error: (iDetect) 192.168.1.2 ====> SSH returned empty response. Transport active: True 
Another thing is when I change the Grace time and press the update button, the Domoticz site seems to hang. Only stopping

Code: Select all

sudo service domoticz.sh stop
which takes approx. 30 seconds and start is resolving the issue
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Tuesday 18 February 2020 20:25 Can you provide some more logging? From the moment the plugin starts until the first error. What happens before the failure will probably tell us more than the failure itself.

The plugin is designed to deal with multiple wireless interfaces on one router. I also use it on my Asus router (2.4 + 5). Maybe it does not detect the interfaces correctly on you router and messes up the wlanconfig command by omitting the interface name... but now I’m just guessing, the logs will show what’s going on.
Here the log:
https://pastebin.pl/view/a6b01786

ath0 (2.4GHz) and ath10 (5GHz) are the wlan interfaces on AP1
This is working as tracker(s) config:

Code: Select all

192.168.1.5#ssh=wlanconfig ath10 list, 192.168.1.5#ssh=wlanconfig ath0 list
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

For AP2 (ddwrt) the domoticz log returns the following error: https://pastebin.pl/view/7c634d6a

I checked manually with ssh the AP2 and the functions brctl and ip are defenitely there:

Code: Select all

root@AP2:~# brctl
Usage: brctl [commands]
commands:
        addbr           <bridge>                add bridge
        delbr           <bridge>                delete bridge
        addif           <bridge> <device>       add interface to bridge
        delif           <bridge> <device>       delete interface from bridge
        hairpin         <bridge> <port> {on|off}        turn hairpin on/off
        setageing       <bridge> <time>         set ageing time
        setbridgeprio   <bridge> <prio>         set bridge priority
        setfd           <bridge> <time>         set bridge forward delay
        sethello        <bridge> <time>         set hello time
        setmaxage       <bridge> <time>         set max message age
        setpathcost     <bridge> <port> <cost>  set path cost
        setportprio     <bridge> <port> <prio>  set port priority
        setportsnooping <bridge> <port> <addr>  set port snooping
        clearportsnooping       <bridge> <port> <addr>  clear port snooping
        showportsnooping        <bridge>        show port snooping
        enableportsnooping      <enable>                enable port snooping
        show                                    show a list of bridges
        showmacs        <bridge>                show a list of mac addrs
        showstp         <bridge>                show bridge stp info
        stp             <bridge> {on|off}       turn stp on/off
root@AP2:~# brctl showmacs
Incorrect number of arguments for command
Usage: brctl showmacs <bridge>          show a list of mac addrs

gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

Okay I figured out what the trackers field of AP1 and AP2 should look like to make it work without errors:

Code: Select all

192.168.1.5#ssh=wlanconfig ath10 list; wlanconfig ath0 list, 192.168.1.2#user=root&password=mysecret&ssh=wl_atheros assoclist

user name	: admin (192.168.1.5 username)
password	: mysecret (192.168.1.5 password)
DDWRT Firmware Routers
Now the trick with ddwrt firmware routers/access points is that the wl command only works for "broadcom" chipsets.
When the router has an "atheros" chipset the command should be wl_atheros.
"wl_atheros -i ath0 assoclist" also works in case the plugin wants to autodetect all (wireless) interfaces
So if you want ddwrt firmware integrate into the Plug-in:
  • get the chipset type (or does athX means it is a wireless interface of the atheros chipset?)
  • get the names of the interfaces
  • create the tracker: if chipset is broadcom-->use wl command, else wl_atheros
TP-Link EAP245
wlanconfig athX list is strange because list is not shown as one of the arguments when typing "wlanconfig"
EscApe
Posts: 535
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 »

Great finds! Thanks.
So if you want ddwrt firmware integrate into the Plug-in:
get the chipset type (or does athX means it is a wireless interface of the atheros chipset?)
get the names of the interfaces
create the tracker: if chipset is broadcom-->use wl command, else wl_atheros
That is exactly what the plugin does when using auto-detection. The chipset type is determined by the available commands and the commands found are then tried on the interfaces found (only trying the ones that are know to be wireless on some routers: ethX, wlanX, athX and wlX)

Edit: according to your previous log the interfaces where not correctly auto-detected on 192.168.1.5. However you where able to query using wlanconfig and a preconfigured interface name. Could you try this slightly modified auto-detection code on the router (it should be more verbose)?

Code: Select all

for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | grep -E '^eth|^wlan|^ath|^wl');do
	testif=`wlanconfig $iface list`
	[ $? == 0 ] && [ "$testif" != "Not supported" ] && printf "~$iface"
done 
When the router has an "atheros" chipset the command should be wl_atheros.
I am not sure if that is true for all atheros based routers, since wlanconfig seems to work for the ones that where already using the plugin. It might be just for dd-wrt(?)
TP-Link EAP245
wlanconfig athX list is strange because list is not shown as one of the arguments when typing "wlanconfig"
This could also be specific to the TP-Link. Does it return the connected Mac addresses anyway or do we need a special tracker for tp-link instead of the auto-detection? The command syntax was provided by another user and seems to be right according to the wlanconfig documentation.

I added wl_atheros to the auto-detection. Can you try (after updating) and share the results?

@Comunity
Because I do not own every type of router I can not test a change like this. Pleas let me know if it broke or improved anything for you.

I am also curious if some routers have both wl_atheros and wlanconfig commands. Even if the plugin still works, I would still like to know if it did request/receive the Mac list twice.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Thursday 20 February 2020 19:14
When the router has an "atheros" chipset the command should be wl_atheros.
I am not sure if that is true for all atheros based routers, since wlanconfig seems to work for the ones that where already using the plugin. It might be just for dd-wrt(?)

I am also curious if some routers have both wl_atheros and wlanconfig commands. Even if the plugin still works, I would still like to know if it did request/receive the Mac list twice.
First DD-WRT (this is installed on a TP-Link WR1043ND V2):
https://wiki.dd-wrt.com/wiki/index.php/Wl_command

Setup
No setup is required as 'wl' comes with all Broadcom DD-WRT installations.
(For Atheros Hardware, this functionality is absent/less developed, and users will need to use the 'ifconfig' and 'wl_atheros' commands instead.
See these threads: wl command "not found", Regarding "wl command not found" and others)
Are you using this code the get the chipset?

Code: Select all

cat /proc/cpuinfo | grep 'system type'
system type : Qualcomm Atheros QCA9558 ver 1 rev 1.0 (0x1130)

I have updated iDetect, and only configured the DD-WRT router.
It has an error (grep only gets eth but it should grep also ath)
Code should probably be:

Code: Select all

for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '' | grep -E '^eth|^wlan|^ath|^wl');do
This is also already suffucient to get the macs of all interfaces.

Code: Select all

wl_atheros assoclist
Here the result with error:
https://pastebin.com/0GvZUCVS
Last edited by gschmidt on Friday 21 February 2020 19:50, edited 6 times in total.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Thursday 20 February 2020 19:14
Edit: according to your previous log the interfaces where not correctly auto-detected on 192.168.1.5. However you where able to query using wlanconfig and a preconfigured interface name. Could you try this slightly modified auto-detection code on the router (it should be more verbose)?

Code: Select all

for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | grep -E '^eth|^wlan|^ath|^wl');do
	testif=`wlanconfig $iface list`
	[ $? == 0 ] && [ "$testif" != "Not supported" ] && printf "~$iface"
done 
TP-Link EAP245

Code: Select all

cat /proc/cpuinfo | grep 'system type'
system type : Qualcomm Atheros QCA956X rev 0

Now your code in ssh console get the following errors:
grep -E should be grep -e (because tr command probably want's to translate E to e...but tr is not found)

Code: Select all

/bin $ for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | grep -e '^eth|^wl
an|^ath|^wl');do
> testif=`wlanconfig $iface list`
> [ $? == 0 ] && [ "$testif" != "Not supported" ] && printf "~$iface"
> done
-sh: tr: not found
/bin $
I read in a thread and can confirm that this command also returns mac addresses:

Code: Select all

/bin $ cat /proc/ath10/clients_keys
d8:0d:17:f5:d8:4b wep1 flg:0x7 hw_keyix:1 ciph:AES-CCM key:xxxxxxxxxxxxxxxxxxxx  9bcf6dc8489e
f4:06:69:32:a7:03 ucast flg:0x3 hw_keyix:5 ciph:AES-CCM key:xxxxxxxxxxxxxxxxxxxx   080e33bd9ff91
30:4b:07:f1:7b:e0 ucast flg:0x3 hw_keyix:5 ciph:AES-CCM key:xxxxxxxxxxxxxxxxxxxx    baac32947b9ec
44:07:0b:46:bf:20 ucast flg:0x3 hw_keyix:5 ciph:AES-CCM key:xxxxxxxxxxxxxxxxxxxx   9cb5ca2dbbe0b
d4:f5:47:93:36:1c ucast flg:0x3 hw_keyix:5 ciph:AES-CCM key:xxxxxxxxxxxxxxxxxxxx    7227e459b65e9
14:95:ce:63:e1:c0 ucast flg:0x3 hw_keyix:5 ciph:AES-CCM key:xxxxxxxxxxxxxxxxxxxx    8649eeb29664d
/bin $
Since wlanconfig does not return the "list" argument although it works, this command might be an alternative?
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Thursday 20 February 2020 19:14 I am also curious if some routers have both wl_atheros and wlanconfig commands. Even if the plugin still works, I would still like to know if it did request/receive the Mac list twice.
Although I have 2 TP-Links, Router (DD-WRT configured as AP) and AP which have both Atheros Chipsets, they don't have both commands.
It is either wl_atheros or wlanconfig.

This probably also gives you the answer that wl_atheros is only a command for the dd-wrt firmware.
EscApe
Posts: 535
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 gschmidt,

Thanks for the additional info!

That's the trouble with automatic detection. There are many differences in hardware and firmware, and people are even using third party firmwares, so there is no guaranteed (and simple) way of detecting the correct chipset and interfaces for every combination. The router-side detection script could easily get overcomplicated to only slightly increase the relative number of routers it will support. Writing a specific tracker or providing your own shh command (like you did) would probably be easier in some of theses cases.

A few examples:
TP-Link EAP245
CODE: SELECT ALL
cat /proc/cpuinfo | grep 'system type'
system type : Qualcomm Atheros QCA956X rev 0
Will return nothing on my Asus router
Now your code in ssh console get the following errors:
grep -E should be grep -e (because tr command probably want's to translate E to e...but tr is not found)
grep -E and grep -e have different meaning/function on my busybox based Asus router

And then there is always the chance of me messing things up ;-) I indead forgot the ^ath part for this ATHeros based detection :oops: Will add it immediately.
I have updated iDetect, and only configured the DD-WRT router.
It has an error (grep only gets eth but it should grep also ath)
Code should probably be:
CODE: SELECT ALL
for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '' | grep -E '^eth|^wlan|^ath|^wl');do
This is also already suffucient to get the macs of all interfaces.
CODE: SELECT ALL
wl_atheros assoclist
Edit: Are you sure it is getting ALL macs? The wl command also works without the -i argument, but on my Asus it will only return macs connected to the 2.4 wireless interface.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by gschmidt »

EscApe wrote: Wednesday 26 February 2020 10:04
This is also already suffucient to get the macs of all interfaces.
CODE: SELECT ALL
wl_atheros assoclist
Edit: Are you sure it is getting ALL macs? The wl command also works without the -i argument, but on my Asus it will only return macs connected to the 2.4 wireless interface.
Not sure indeed...it is only a 2.4ghz wireless router ;-)

But I did noticed another thing...if no wireless clients are connected to (in my case the dd-wrt) the AP (the 2 AP's have the same SSID), domoticz log keeps dumping the error that no connections were found on this AP
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python plugin: Presence detection from wireless router

Post by manjh »

This plugin is just what I need, after messing around with "ping" and PIR detectors to determine if someone is home, I am more than ready for a simple solution that just works without trouble.

Plugin install went like a charm, but after configuring and starting the plugin in the HW tab, the log file tells me it cannot log on to the router.
I use an unmodified Netgear R7000.
Also tried Putty to SSH into the router, no luck.

My conclusion is that the R7000 does not support SSH. Cannot find anything in the settings menu.
Am I correct? Is there any way out of this, besides installing DD-WRT?
Hans
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest