Presence Detection via the iPhone and Wifi

Tom's picture
Tags: 

So, as Phil mentioned, we all got iPhones as a holiday bonus. And they're pretty great. JP and I held off until Macworld, lest we miss out on a new 3G handset (a longshot, I know). When that didn't happen I immediately scurried over to Pentagon City and bought a beautiful internet lozenge.

Since then I've been figuring out all of the amazing things it can do for me. On Thursday I had a stroke of inspiration. I've been looking longingly at Bluetooth presence detection setups for a while. I like the idea of having my hardware respond to my proximity, but I've got some reservations about wasting a Bluetooth dongle (and server, and Bluetooth-on-Linux configuration time) on the effort. The iPhone is the first mobile I've owned that does wifi. This seems like an opportunity to do presence detection on the cheap.

My approach is pretty simple: ping the iPhone. If it's there, I probably am, too. But how to ping it? The iPhone uses DHCP to get an address. At home I've got a router running the SveaSoft firmware. It's simple enough to configure DNSMasq to always dole out the same IP address to my iPhone's MAC.

Then I wrote a bash script to send three pings, check the number of successful replies, and log the result to a text file. I set it up to run on a minute cron and let it go overnight:

PING_COUNT=`ping -c 3 192.168.2.21 | grep "bytes from" | wc -l`
test $PING_COUNT -eq 3 && RESULT="here" || RESULT="not here"
RIGHT_NOW=`date`
echo "$RIGHT_NOW - $RESULT" >> status.txt

Here are the results from the first 24 hours:

creating my own orwellian self-surveillance system

I started the script at about 1:05, spent a little time playing with the iPhone, then went to sleep (leaving the phone on & charging). I woke up, unplugged the iPhone and left the apartment a little before ten (I highly recommend flextime and a having a very short commute). I was back in the apartment around 6:30, then left about an hour later to catch a bus to Philly. I didn't touch my phone at all during that pre-bus hour.

So all in all this looks pretty promising. Will detection via wifi have the granularity of Bluetooth? No, probably not. The phone doesn't seem to dial in to the network as frequently. It's also not clear why the overnight connections are more intermittent. My phone was in my bedroom overnight, which gets a weaker signal than the living room where I spent that hour in the evening. Perhaps that's why it connected less often during the nighttime. Or maybe it dials back its network activities based upon how recently it's been used. Or maybe those smart folks in Cupertino taught it to know when its owner is likely to be asleep (accelerometer FTW?). It's hard to say.

But although Bluetooth's instant detectability is needed for some purposes — turning on appliances, launching programs, changing IM status, that sort of thing — it's less necessary for what I have in mind: letting my friends know whether I'm in town at the moment. I'll probably alter the script a bit so that it doesn't log lots of data to disk, and instead hits a PHP script on my server with the result of the presence test. That way I can just run it on my router, removing the need for a server. Who knows? With all the traveling that folks here at EchoDitto do, it might be worthwhile to implement it on our office systems, too.

Incidentally, Bluetooth presence detection is, of course, well within the iPhone's capabilities. Home Zone looked extremely promising (and produced an encouraging Growl notification when I shut my phone off) but wound up with an AppleScript error. I think I should be able to achieve at least that level of success on my own using this and this.

UPDATE: Actually, this may be harder than I thought. It seems that Adium 1.2 broke pretty much every status-message-setting AppleScript in the known universe. If anyone's got one that works, do tell.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode>
  • Lines and paragraphs break automatically.
  • You may post block code using <blockcode [type="language"]>...</blockcode> tags. You may also post inline code using <code [type="language"]>...</code> tags.

More information about formatting options

Captcha
Are you a robot? We usually like robots, but not in our comments.
Copy the characters (respecting upper/lower case) from the image.