script for presence detection of a phone

Must be cleaned all topics go to the right subforum
zedd
Posts: 5
Joined: Monday 02 January 2017 23:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: script for presence detection of a phone

Postby zedd » Wednesday 04 January 2017 15:27

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.

User avatar
jannl
Posts: 680
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Geleen
Contact:

Re: script for presence detection of a phone

Postby jannl » Wednesday 04 January 2017 16:46

I think also arping will give problems with Android's doze function (Android 6)

zedd
Posts: 5
Joined: Monday 02 January 2017 23:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: script for presence detection of a phone

Postby zedd » Wednesday 04 January 2017 22:32

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.

User avatar
jannl
Posts: 680
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Geleen
Contact:

Re: script for presence detection of a phone

Postby jannl » Thursday 05 January 2017 8:48

Place your android 7 phone on a flat surface, no charger attached and wait a few hours. See what happens.

Koensk
Posts: 25
Joined: Friday 25 September 2015 9:23
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: script for presence detection of a phone

Postby Koensk » Tuesday 10 January 2017 10:19

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

[email protected] ~/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


Return to “Scripts [cleaning in progress]”

Who is online

Users browsing this forum: No registered users and 3 guests