Page 2 of 3
Re: script for presence detection of a phone
Posted: Wednesday 04 January 2017 14:27
by zedd
The solution to this is to use something that
does request a reply from your phone (or another device) and will get a response whether the device active or not. Arp-requests are generally answered by all phones, so why not use this? Indeed, checking with 'arp', only performs a lookup in an existing table in the OS.
But, there is a tool called 'arping' which will send an arp-whois and report the response. Use it like this:
Code: Select all
$ sudo apt-get update
$ sudo apt-get install arping
$ sudo arping 192.168.1.1
I've altered the script from
https://www.domoticz.com/wiki/Presence_detection to use arping as it is much more reliable AND will detect when a device is disconnected / leaves the network.
Note: I've installed Domoticz on a Raspberry Pi, so above mentioned method may or may not work for you. Arping is available on most OS's though.
Caveat: arping uses a system call that requires root-access, so you need to prepend 'sudo' to the command.
Re: script for presence detection of a phone
Posted: Wednesday 04 January 2017 15:46
by jannl
I think also arping will give problems with Android's doze function (Android 6)
Re: script for presence detection of a phone
Posted: Wednesday 04 January 2017 21:32
by zedd
To be honest: I haven't got a clue if that's the case or not.
Experience (meaning, the past few days) arping has worked flawlessly for me. Which doesn't mean that other versions than our Android 7 phones may provide different results.
Re: script for presence detection of a phone
Posted: Thursday 05 January 2017 7:48
by jannl
Place your android 7 phone on a flat surface, no charger attached and wait a few hours. See what happens.
Re: script for presence detection of a phone
Posted: Tuesday 10 January 2017 9:19
by Koensk
Anyway,
What's the working solution? I tried both ip-presence detection and this arp methode but both off them don't work.
With arp I get the following error
pi@raspberrypi ~/domoticz/scripts $ ./arpdetect.sh 192.168.0.110 635 10
PING 192.168.0.110 (192.168.0.110) 56(84) bytes of data.
--- 192.168.0.110 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 215.874/215.874/215.874/0.000 ms
./arpdetect.sh: line 60: unexpected EOF while looking for matching `"'
Anyone an idea or an other solution to detect if my phone is in the house or not?
Thx
Re: script for presence detection of a phone
Posted: Monday 20 March 2017 22:10
by ArnieO
I get exactly the same error as what Koensk is describing.
What are we doing wrong?
Re: script for presence detection of a phone
Posted: Monday 20 March 2017 22:45
by ArnieO
SOLVED: There was an error with one or the <">-signs in line 50. Copy/paste issue, I assume.
Re: script for presence detection of a phone
Posted: Tuesday 21 March 2017 20:53
by Nerre
Strange thing for me is that arping to the IP address of the phone (Android) works, but not using the MAC address (I wanted to use the MAC to avoid having to give the phone static IP).
And I am sure I use the right MAC address since arpinging the IP address gives med the MAC as response, so I can copy it and paste.
This is probably something with my phone, but it shows that is may be hard to find a foolproof method.
Re: script for presence detection of a phone
Posted: Wednesday 22 March 2017 1:04
by kubrik
Perhaps i'm going a little ot...but..
i've found that using nmap (i've tried arp-scan too..totally unreliable) is the more "reliable" method for network presence detection.
Code: Select all
sudo /usr/bin/nmap -sP -PR 192.168.1.50-100 | grep MAC | awk '{ print $3 }'
gives a list of mac addresses alive into the network range 192.168.50-100 (dhcp scope in this case...you can put all subnet but slower).
You can search for your phones mac addresses into this list.
Android issue can be "solved" considering a time range detection for the "absence".
Infact i've also found that with 1 minute check you can consider offline the phone if the script doesn't find it for 12 minutes (with 10 minutes i get some false positives).
If you use the absence for alarm activation, it could be a reasonable activation time.
Re: script for presence detection of a phone
Posted: Wednesday 22 March 2017 19:41
by Nerre
The version of nmap I have installed (6.47) does not seem to have options -sP or -PR...
Oh, it did... but I didn't see them in the manpage.... strange.
Re: script for presence detection of a phone
Posted: Thursday 23 March 2017 0:02
by kubrik
You are right...
-sP is the actual -sn (no port scan), both are the same.
-PR (Arp ping) is the default with local network.
So "nmap -sP -PR 192.168.1.50-100" is equivalent to "nmap -sn 192.168.1.50-100"
rif.
https://nmap.org/book/man-host-discovery.html
Re: script for presence detection of a phone
Posted: Sunday 23 April 2017 16:52
by Jazzle
Koensk wrote:Anyway,
What's the working solution? I tried both ip-presence detection and this arp methode but both off them don't work.
With arp I get the following error
pi@raspberrypi ~/domoticz/scripts $ ./arpdetect.sh 192.168.0.110 635 10
PING 192.168.0.110 (192.168.0.110) 56(84) bytes of data.
--- 192.168.0.110 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 215.874/215.874/215.874/0.000 ms
./arpdetect.sh: line 60: unexpected EOF while looking for matching `"'
Anyone an idea or an other solution to detect if my phone is in the house or not?
Thx
Koesnk, dit you find the reason for the EOF error and did you get the Arp script working?
I get the following 2 errors:
./arpdetect.sh: line 60: unexpected EOF while looking for matching `"'
./arpdetect.sh: line 62: syntax error: unexpected end of file
Anyone an idea?
Thanks
Jasper
Re: script for presence detection of a phone
Posted: Tuesday 23 May 2017 14:48
by micksel
Zedd, Can you share your modified script?
Re: script for presence detection of a phone
Posted: Tuesday 23 May 2017 16:14
by zedd
micksel wrote:Zedd, Can you share your modified script?
I actually altered the script in the
Wiki page...
Re: script for presence detection of a phone
Posted: Tuesday 23 May 2017 16:29
by micksel
zedd wrote:micksel wrote:Zedd, Can you share your modified script?
I actually altered the script in the
Wiki page...
Feeling stupid, thanks
Re: script for presence detection of a phone
Posted: Tuesday 23 May 2017 23:28
by EdwinK
When trying this
Code: Select all
python check_device_online.py 192.168.0.117 168 10 30
results in
Code: Select all
python check_device_online.py 192.168.0.117 168 10 30
23:25:12- script started.
23:25:12- according to domoticz, 192.168.0.117 is offline
Usage: arping [-fqbDUAV] [-c count] [-w timeout] [-I device] [-s source] destination
-f : quit on first reply
-q : be quiet
-b : keep broadcasting, don't go unicast
-D : duplicate address detection mode
-U : Unsolicited ARP mode, update your neighbours
-A : ARP answer mode, update your neighbours
-V : print version and exit
-c count : how many packets to send
-w timeout : how long to wait for a reply
-I device : which ethernet device to use
-s source : source ip address
destination : ask for what ip address
This goes on until I stop the script.
It seems my phone (Android 7) goes to doze after some time. Can't find a place to turn that off. Trying to add a ping in the script I'm not sure off doing.
Manually setting the switch to 'on' results the script in answering that the phone is online, of course. But I'm sure that isn't the right way of working with it.
Re: script for presence detection of a phone
Posted: Sunday 28 May 2017 8:42
by micksel
Seems that the used a big W in the script and not a small w, so start by changing that, I hade that problem, but I also changed by removing the timeout so that will use the default value and set a -c of at least 15 because my android is something very slow on responding.
Re: script for presence detection of a phone
Posted: Friday 02 June 2017 12:23
by Jordyboytjuh
EdKo66 wrote:When trying this
Code: Select all
python check_device_online.py 192.168.0.117 168 10 30
results in
Code: Select all
python check_device_online.py 192.168.0.117 168 10 30
23:25:12- script started.
23:25:12- according to domoticz, 192.168.0.117 is offline
Usage: arping [-fqbDUAV] [-c count] [-w timeout] [-I device] [-s source] destination
-f : quit on first reply
-q : be quiet
-b : keep broadcasting, don't go unicast
-D : duplicate address detection mode
-U : Unsolicited ARP mode, update your neighbours
-A : ARP answer mode, update your neighbours
-V : print version and exit
-c count : how many packets to send
-w timeout : how long to wait for a reply
-I device : which ethernet device to use
-s source : source ip address
destination : ask for what ip address
This goes on until I stop the script.
It seems my phone (Android 7) goes to doze after some time. Can't find a place to turn that off. Trying to add a ping in the script I'm not sure off doing.
Manually setting the switch to 'on' results the script in answering that the phone is online, of course. But I'm sure that isn't the right way of working with it.
I think I've the same issue. Since the update to Android 7 my online device checker won't work as good as it did. When I put my phone in just stand-by mode. After a little while, it says it's not "on" anymore in domoticz. When I put the mobile on again, the pushnotification that "someone's home" immediately appears. When I try to ping it directly on the pc, it says request timed out (when it's a little while in standby mode). I think in Android 7 something has changed the pinging?
Re: script for presence detection of a phone
Posted: Friday 02 June 2017 13:34
by jvdz
Correct, Android 7 does put the WiFi much more in sleep mode than older releases, meaning any MAC or IP checking will be flawed. I am using both Ping and Bluetooth Check to determine the presence of the phones and that works like a charm.
Jos
Re: script for presence detection of a phone
Posted: Saturday 03 June 2017 21:53
by thijsdebets
I created a script to detect all devices on the network.
Installation instructions are here:
https://github.com/thijsdebets/networkdetectz/wiki
It uses a combination of arpscan, ping and even supports bluetooth detection.
I use it very succesfull to detect who is at home and to set the lights to TV-Mode when the tv switches on, etc.
It requires one arp-scan every minute via cron making it low on resources.