Working Iphone wifi presence locator


(Oliver K.) #62

Hi,

not in the rule…but in the script :wink:. Here is mine

#!/bin/bash
declare -a DEVICES
sudo ip neigh flush 192.168.x.x
sudo /usr/sbin/hping3 -2 -c 10 -p 5353 -i u1 192.168.x.x -q >/dev/null 2>&1
DEVICES=/usr/sbin/arp -an | awk '{print $4}'
CHECK="78:xx:xx:xx:xx:xx"
if [[ ${DEVICES[*]} =~ $CHECK ]]
then
echo "Anwesend"
else
echo "Abwesend"
fi

Its the “sudo ip neigh flush 192.168.x.x”, you can also use “sudo ip neigh flush all” or "sudo ip neigh flush eth0"
I prefer the first one, because it flushes only the entry with the defined IP Address.


(Stefan) #63

Of course…my fault…thanks!


(Oliver K.) #64

no Problem :wink: Does it work?


(Stefan) #65

Nope! :wink:

It seems that it’s working from ON -> OFF but messes up the other direction OFF -> ON (results not reliable). But I haven’t had much time to dig deeper into this…


(Michael) #66

Thanks for your script Björn.
Works fine for my.

Sometimes it take more then one 60 seconds cycle but thats no problem.
I made the other rules to wait 5 minutes before changing something when no ones home.

Cheers
Michael


(Michael) #67

OK, it only worked yesterday.

Today i did some tests and randomly checked my UI.
When my girlfriend went to work her phone stillt showed as online.
Even when looking into the ip neigh show IP_ADRESS her phone was still there.

So i tried to play around with the ip neigh flush IP_ADRESS.
The first tries went pretty well but soon after the phone didn´t get back.
It´s connected to the wifi but it still says “FAILED” when using ip neigh show IP_ADRESS

It takes up to 5 minutes to get visible for ip neigh again.

Cheers
Michael


(ksiezykmirek) #68

please check this solution:

https://community.openhab.org/t/best-presence-detection/11966/38


(Randy Elias) #69

Hi Jonathan,

I know this is an old thread but I’ve been trying to implement your home presence logic in openhab 2 using the exec binding and a bash script. I have it working for the most part except for the hping3 part.
For testing the hping3 command, I do the following:

To monitor my iphone connectivity, I use the ping output. Then I run the hping3 command as per your instructions:

hping3 -2 -c 10 -p 5353 -i u1 xxx.xxx.xxx.xxx

I get the following output:

HPING xxx.xxx.xxx.xxx (en0 xxx.xxx.xxx.xxx): udp mode set, 28 headers + 0 data bytes

--- xxx.xxx.xxx.xxx hping statistic ---
10 packets tramitted, 0 packets received, 100% packet loss
round-trip min/avg/max = 0.0/0.0/0.0 ms

And ping output shows no connection with the iphone after the command is run.
The hping3 output also looks like 0 packets were received … so did it fail?

What am I doing wrong?

Thanks,
Randy


(lipp_markus) #70

Made the same experience. In fact none of my devices on my network respond to this request. It is somewhat better if I allow for more time (parameters are set for 1millsec) and responses from some other devices trickle is but response time is very slow (500ms or so) but nothing with an iphone7 …
Hope someone knows more


(Norman Sand) #71

hping just wakes the phone. Afterwards you need to check for the mac with arp.


(lipp_markus) #72

Thanks @normaniac
I only looked into the details of hping3 because the script [edit see above with arp and everything] reliably and consistently misses the presence of the iphone in our house. MAC capitalized or not (and of course it is a fixed ip-address), it reports “absent”, wether the iphone is sleeping or actually not sleeping. Not sure what I am doing wrong here.

[Second edit, the script way above had some typos (oh, solutions are often simpler than it seems), here the script that works for me:

#!/bin/bash
declare -a DEVICES
sudo hping3 -2 -c 10 -p 5353 -i u1 192.168.XXX.XXX -q >/dev/null 2>&1
DEVICES=`arp -an | awk '{print $4}'`
CHECK="XX:XX:XX:XX:XX:XX"
if [[ ${DEVICES[*]} =~ $CHECK ]];then
        echo "Present"
else
        echo "Absent"
fi

(Jeff James) #73

I am having trouble with this script to reliably detect presence, not because the script doesn’t seem to be working, but that arp does not seem a good indicated of an iphone being on the network. For instance, after my phone is off the network, it remains in the arp cache for a long time (hours). Then, when it come back on the network, it doesn’t reliable get updated in the arp table on my computer. Is this normal?

Thanks
Jeff


(lipp_markus) #74

Did you try this modification?

Edit: see thread above for where to put in the script


(Jeff James) #75

Operator error here. The hping3 command wasn’t installed, but the script was directly output to /dev/null so I never saw this.

Thanks for help.


(Dominic Bonneau) #76

Hi, I was wondering if instead of using a hping3 script to wake the iPhone if we could use the tcp/udp binding ? I’m not on linux and hping3 is hard to install on Mac… also I prefer to have all my thing running in openhab with no external script


( ) #77

The discussion surrounding iPhone Presence Detection has been continued over here:


(David Graeff) #78

Hey all,
I have extended the network binding to be able to use arping. Additionally I send an empty packet to udp port 5353, as suggested here in this thread. I do not own an iPhone though, so cannot test if it actually works. The device presence detection for my android 6 phone works now, thanks to arping.

The pull request:


( ) #79

Jar available at: https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/binding/org.openhab.binding.network/2.2.0-SNAPSHOT


(David Graeff) #80

The binding update is merged. Can people with iPhones tests the presence detection and report success / failures please :slight_smile:.

The new version is only available in a 2.3 release and snapshots.

Cheers David


(Daniel A) #81

Hi!

I’m a total noob. I’m trying to get presence working with my iPhone via wifi instead of geofencing.

I can’t get it to initiliaze.

I ran the below commands

bundle:install https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/binding/org.openhab.binding.network/2.2.0-SNAPSHOT
bundle:start 237