<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://labs.echoditto.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>EchoDitto Labs - Presence Detection via the iPhone and Wifi - Comments</title>
 <link>http://labs.echoditto.com/iphone-presence-detection</link>
 <description>Comments for &quot;Presence Detection via the iPhone and Wifi&quot;</description>
 <language>en</language>
<item>
 <title>Presence Detection via the iPhone and Wifi</title>
 <link>http://labs.echoditto.com/iphone-presence-detection</link>
 <description>&lt;p&gt;So, as Phil mentioned, we all got iPhones as a holiday bonus.  And they&#039;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&#039;t happen I immediately scurried over to Pentagon City and bought a beautiful internet lozenge.&lt;/p&gt;

&lt;p&gt;Since then I&#039;ve been figuring out all of the amazing things it can do for me.  On Thursday I had a stroke of inspiration.  I&#039;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&#039;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&#039;ve owned that does wifi.  This seems like an opportunity to do presence detection on the cheap.&lt;/p&gt;

&lt;p&gt;My approach is pretty simple: ping the iPhone.  If it&#039;s there, I probably am, too.  But how to ping it?  The iPhone uses DHCP to get an address.  At home I&#039;ve got a router running the &lt;a href=&quot;http://wrt54g.thermoman.de/&quot;&gt;SveaSoft firmware&lt;/a&gt;.  It&#039;s simple enough to configure DNSMasq to always dole out the same IP address to my iPhone&#039;s MAC.&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;PING_COUNT=`ping -c 3 192.168.2.21 | grep &quot;bytes from&quot; | wc -l`
test $PING_COUNT -eq 3 &amp;&amp; RESULT=&quot;here&quot; || RESULT=&quot;not here&quot;
RIGHT_NOW=`date`
echo &quot;$RIGHT_NOW - $RESULT&quot; &gt;&gt; status.txt&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Here are the results from the first 24 hours:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://www.flickr.com/photos/sbma44/2205107306/&quot; title=&quot;creating my own orwellian self-surveillance system by sbma44, on Flickr&quot;&gt;&lt;img src=&quot;http://farm3.static.flickr.com/2318/2205107306_592ab67fc3_o.jpg&quot; width=&quot;516&quot; height=&quot;404&quot; alt=&quot;creating my own orwellian self-surveillance system&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started the script at about 1:05, spent a little time playing with the iPhone, then went to sleep (leaving the phone on &amp;amp; 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&#039;t touch my phone at all during that pre-bus hour.&lt;/p&gt;

&lt;p&gt;So all in all this looks pretty promising.  Will detection via wifi have the granularity of Bluetooth?  No, probably not.  The phone doesn&#039;t seem to dial in to the network as frequently.  It&#039;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&#039;s why it connected less often during the nighttime.  Or maybe it dials back its network activities based upon how recently it&#039;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&#039;s hard to say.&lt;/p&gt;

&lt;p&gt;But although Bluetooth&#039;s instant detectability is needed for some purposes &amp;mdash; turning on appliances, launching programs, changing IM status, that sort of thing &amp;mdash; it&#039;s less necessary for what I have in mind: letting my friends know whether I&#039;m in town at the moment.  I&#039;ll probably alter the script a bit so that it doesn&#039;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.&lt;/p&gt;

&lt;p&gt;Incidentally, Bluetooth presence detection is, of course, well within the iPhone&#039;s capabilities. &lt;a href=&quot;http://metaquark.de/homezone/&quot;&gt;Home Zone&lt;/a&gt; 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 &lt;a href=&quot;http://www.apple.com/downloads/macosx/system_disk_utilities/proximity.html&quot;&gt;this&lt;/a&gt; and &lt;a href=&quot;http://www.adiumxtras.com/index.php?a=xtras&amp;xtra_id=2087&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; 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&#039;s got one that works, do tell.&lt;/p&gt;</description>
 <comments>http://labs.echoditto.com/iphone-presence-detection#comments</comments>
 <category domain="http://labs.echoditto.com/taxonomy/term/153">bluetooth</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/142">iphone</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/152">presencedetection</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/154">proximitydetection</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/151">wifi</category>
 <pubDate>Wed, 23 Jan 2008 19:11:15 -0800</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">62 at http://labs.echoditto.com</guid>
</item>
</channel>
</rss>
