One of the challenges in having a good home automation system is how to detect the presence of people in the house. I’ve had many tries on doing this, among them:
– Movement sensors.
These work – but for a big house you need a lot of movement sensors if you are going to have good coverage, and they do not work in practice in our house.
– iBeacons
Generally need to track a Bluetooth device, and unless you can get every household member to carry a bluetooth device, this is unworkable. The best idea would be to use a ibeacon running one a mobile phone, but these would include installing software on every household members mobile phone, not workable in practice. The option is to detect each phones bluetooth interface, but this is again not applicable for IOS devices (more about that later) – or without reducing battery life when the phone is outside the range of your house. The range is also very short, and means that you would need (potentially) a lot of receivers.
– Check for the presence of mobile phones.
You can unfortunately not ping IOS devices after that have entered deep sleep, nor use ARP to detect them.
As our household is run on iPhones the last has been a problem – until I found a reference to how to wake up a IOS device from deep sleep by sending packets to port 5353 (mDNS port) to wake it up, and the use ARP to check for the presence on the network.
This is a excellent way of doing detection, as the only downside is that it will lead to more battery usage (as deep sleep reduces the devices power consumption drastically). And of course it was very clear that a way to do this had to exist – otherwise you would not get alerts/messages/emails wen the IOS device was in deep sleep.
How to do this in practice
After installing hping3 (I did this on a Raspberry Pi by using arp-get install hping3) i made a very short shell script
#!/bin/bash
sudo hping3 -2 -c 10 -p 5353 -i u1 $1 2> /dev/null 1>/dev/null
arp -an | egrep -w $1
it works (though not perfectly) as it wakes up the IOS devices, and responds like this when it finds a device
? (192.168.1.196) at b4:f0:ab:c5:62:dc [ether] on eth0
and for a device that is asleep
? (192.168.1.19) at <incomplete> on eth0