iPhone Presence Detection with hping3 and ARP

The Network binding now will do arping so you can just use that. Look at the readme for the binding for details.

There is also an iCloud binding people have been successful using.

Hi,
Has anybody measured the impact of waking the iPhone’s WiFi to answer the pings in battery life?
Regards.

Excellent question @jjmeseguer, I was thinking about the same issue. Yesterday I spent some time googling for that with no success.

So if someone has more information, that would be great!!

Thank you

Thanks Rich!
The network binding works now after some configuration. I extended the time to 90000ms before the device is stated as offline. Seems to be working since then. Before the iPhone presence went offline/online around every minute.

1 Like

Sorry for my ignorance… How set IP and MAC on script file?

(Sorry for my ignorance) :sweat_smile:

How set IP and MAC on script file?

I am receiving the following error on the presence…Anyone have any ideas?

2018-10-08 17:01:01.774 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Determine presence Iphone’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: IphonePresence.rules#|::0.2.1.2.0.0.0.0.2.0.1::0::/1)

Blockquote

How does one update to 2.19?

iOS 12.0.1 iPhone Xs.
It doesn’t work. It takes about 30 seconds after the screen is black then the script says “not present” anyone seen the same?

iPhone 7 here. Same results. it just doesn’t work. i tried so many settings and so many versions. I just can;t get a decent detection. I don’t like cloud stuff, but i think im going to switch to the icloud binding and use the geofencing rule.

It doesn’t seem to work for newer android phones. I have a Samsung Galaxy S8 and a Galaxy S9. Both are not responding to the hping3 call (100% loss) and are not in the arp table afterwards.

I can do a simple ping when they are not in sleep and then the script detects the phone, but hpin3 doesn’t seem to do the trick at all.

hi

I’ve got an iphone 6s and the suggested procedure doesnt work. i have iphone 6s with ios 12.1.12. if i understand the script corretcly you flush the arp table and then send udp packets using hping3. how can the hping3 know the iphone mac ?

i tried using a static arp entry for the iphone, and i sniff the udp packets arriving but it stil doesnt answer arp. is there another way to wake the iphone up?

Regards

Hi

My solution is to assign fixed IP addresses to the iPhone from my WLAN router. Then I use pingable network device as an item and the channel with lastseen:

DateTime iPhone_Lastseen "Last seen" {channel="network:pingdevice:00xy0000:lastseen"}

Cheers

doing it same, but not really satisfied with results as iphones while sleeping are not responding to pings. But I’m not sure if I want to have something waking up my phone during the night or so, as it seems quite not needed.

what’s your refreshinterval and retry?

its a litle work and money but i am now using BT binding

it works flawlessly, but you will need to walk around with something like this on your keys

but its worth it… i have zero false reading i use it to unlock my alram system, and shut down my small falt you will need more then one reciver for a bigger place

I am using: Refresh Interval 60000 (ms) and Retry 1. Not sure but I think these are the default values.
Whether it works during the night I didn’t check though.

I had quite bad experiences with default settings and latest iOS
this went better with these:

refreshInterval=20000, retry=10

but not yet 100% accurate

Hello,
I did as you say and the detection works. To the script in the “grep” function I added a -i parameter so it considers the MAC correctly even if written in capital letters. But I have a problem that I don’t understand … in case of “not detected” the echo “OFF” is not executed, how come? I checked the log file, but that line is never executed.
Can you help me?
Thank you

#!/bin/bash

# v1.1 2017-04-11: VARIATION WITH LOGGING INCLUDED

# detect iphone by IP and MAC address.
# use MAC address too, to prevent false positives if IP might change
# return ON or OFF so output can be directly bound to a switch item

# number of retries, less is faster, but less accurate
MAXRETRIES=20

# path to log file - to use logging, uncomment all lines containing 'echo >> logfile'
LOGFILE=/etc/openhab2/scripts/iphone.log

# exit immediately if no parameters supplied
if [ $# -lt 2 ]
  then
    echo `date '+%F %T'` - Required parameters not specified >> ${LOGFILE}
    echo "UNDEF"
    exit 1
fi

# Set variables
IP=$1
MAC=$2

echo `date '+%F %T'` - Script started for ${IP} and ${MAC} >> ${LOGFILE}

COUNT=0
while [ ${COUNT} -lt ${MAXRETRIES} ];
do
  echo `date '+%F %T'` - Try ${COUNT} >> ${LOGFILE}

  # Change dev and eth0 if needed
  sudo ip neigh flush dev eth0 ${IP}

  sudo hping3 -q -2 -c 10 -p 5353 -i u1 ${IP} >/dev/null 2>&1
  sleep .1

  # Only arp specific device, grep for a mac-address
  STATUS=`arp -an ${IP} | awk '{print $4}' | grep -i "${MAC}"`

  echo `date '+%F %T'` - Valore per status ${#STATUS} >> ${LOGFILE} 
  
  if [ ${#STATUS} -eq 17 ]; then
      # exit when phone is detected

      echo `date '+%F %T'` - Phone detected >> ${LOGFILE}

      echo "ON"
      exit 0
  fi
  let COUNT=COUNT+1
  sleep .1
done
# consider away if reached max retries 

echo `date '+%F %T'` - Phone not detected >> ${LOGFILE}
echo "OFF"


Hello everyone,
I am implementing presence at home, with iphone and android cell phone on my OH2.
Seeing all the methods posted, I would like a help to use the following way.

1 - Doors are opened and inform OH2
2 - Fires a package to “wake up” cell phones for a few minutes.
3 - If there is no answer, turn off all lights

That way, whenever a door is activated, I will check if people (cell phones) are at home.

And if you open the door just to get pizza or mail, there is no problem in turning everything off, because the cell phone was at home.

It can also be implemented with motion sensors when present in automation.

I believe that this way I don’t run into the issue of checking the cell phone all the time, draining its battery.

I am grateful for examples and suggestions!

am using motion sensors, cell phones are super unreliable source
more here