TUAW Responds: iPhone LoJack
Way back, one of our readers begged for an iPhone LoJack solution. He wanted his iPhone to "call home" regularly in case of loss or, let's be more realistic, theft. Over the past week, I finally had a chance to give this request some time, and I put together findme. It's a command-line program that returns the location of the cell phone tower nearest to your iPhone. When run, it tells you the tower id, plus its latitude and longitude courtesy of Google Maps.
Still, how to get the location report to a place you can get it... but nobody else can... and without receiving a zillion SMSes? For this part of the puzzle, enter Twitter. Twitter dev Britt Selvitelle helped walk me through the setup for a private account that allows your iPhone to phone home but keeps the location data relatively secure.
To do this, create a new Twitter account just for your iPhone (it will need its own unique email address, separate from your main account, so have one handy). Open the Settings panel, and look for the "Protect My Updates" checkbox. It's towards the bottom of the page, just above the Save button. Check this and click Save. With protected updates, only the Twitter users you approve will see the updates for this iPhone-only account (just you? you + spouse? spouse, kids, and "special friends?" Up to you).
Update: I've put an updated version of findme (findme-better) into the TUAW folder on my site. Please let me know if this works better for location for you. To use, just copy to your iPhone (you may have to use Firefox if you get errors after downloading with Safari), rename to "findme" and replace the original findme.
After creating your phone's Twitter account, you're ready to set up your iPhone to tweet in on a regular basis. Here's how.
1. Install findme Add findme to your local binaries folder. Under 1.1.3, I've been using /var/root/bin for my utilities. If you use another location, substitute that path for mine. Make sure to chmod 755 findme so that it can be executed.
2. Make sure you have curl It's a standard part of the BSD distribution, if memory serves. You'll need it to contact Twitter. Your iPhone will only be able to call in via curl and Twitter if it has Internet access, through EDGE or WiFi.
3. Create a tweet shell script Copy the following text into a new text file, and add it to your binaries folder.
#! /bin/sh
curl --basic --user username:password \
--data status="`/var/root/bin/findme`" \
http://twitter.com/statuses/update.xml
Use the proper path to findme and substitute your actual username and password. Make the file executable, i.e.
chmod 755 tweet
4. Create a launch daemon In /System/Library/LaunchDaemons, you'll find a simple daemon that runs once a day, called com.apple.daily.plist. Copy this to com.sadun.tweet.plist, and edit it as follows:
- Update the Label to com.sadun.tweet.
- Kill the two lines that relate to "nice". You don't want your lojack to be usurped by other processes.
- Change the program arguments to /var/root/bin/tweet.
- Change the start interval from 86400, according to your needs. 86400 is once a day (60 seconds * 60 minute * 24 hours). Right now, I have mine running every ten minutes (600) because I needed to check that the LaunchDaemon was functioning properly.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.sadun.tweet</string>
<key>ProgramArguments</key>
<array>
<string>/var/root/bin/tweet</string>
</array>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>
5. Reboot. This allows our iPhone to restart, loading your new launch daemon.
The findme software was written around material orginated by the iPhone dev team and by Hisper of the Google Maps online developer forum, and was helped by Saurik -- because the iPhone's built in host name resolution is horrible. Thanks also to aCujo for his help. The Twitter curl calls are courtesy of Britt's brilliant assistance. You can drop him a note to say thank you. Thanks also go to Mike Rose, whose idea it was to use Twitter instead of SMS.
Tip: If you find that your tweets are full of "Location Not Found" messages, edit the tweet shell script and duplicate the curl call. This runs the call twice. Usually the "Location Not Found" message goes away the second time.
Another Tip: If you're traveling across the country, change your start interval to 15 minutes or a half hour and use a public Twitter account. (Remember to reboot after making changes to the Launch Daemon). Your friends will be able to track your progress using the Google Maps URL that's tinyURL'ed into each tweet.
Enjoy your newfound location awareness!

Get a WordPress.com Blog
![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 3 of 7)
Lucky888 said 2:03AM on 2-22-2008
I love this idea. Security for phones, laptops and cars now adays are great. It gives a better security peace of mind...
Reply
mitch said 3:21AM on 2-22-2008
I tried installing findme and it's almost working but not quite.
If I run findme from the terminal (through SSH) it reports my location, etc. back in the terminal.
If I run tweet (terminal / ssh) then it works fine - I get a message on my twitter account with location, etc.
However, I can't get everything to happen automatically (I assume my problem is with the plist). Once, everything is installed, is there some sort of activation or something I need to do to make it go?
Any ideas?
Reply
Austin said 3:28PM on 2-22-2008
@mitch:
Did you solve your problems with the plist? I am having the same problems you were having in your earlier post (#41). tweet and findme work, but only when I run it in the terminal.
-Austin
hygt said 2:41PM on 3-23-2008
Same, did you solve it?
yomomma said 9:22AM on 2-22-2008
Sweet App. i think this might be enough to get me into programming for the iphone, i kinda been holding out for the devkit, but this is cool!
If you could modify the google maps url a bit, it would drop a pin at the tower location, ie http://maps.google.com/maps?q=36.9,-86.9 instead of http://maps.google.com/maps?ll=36.9%2c-86.9
Would also be nice if the google maps link would open in Maps on the iphone but i'm not sure what needs to change for that.
Reply
Elias said 11:33AM on 2-22-2008
Erica,
Do you plan on porting/re-releasing your apps when the official SDK comes out?
Reply
Shai said 11:26AM on 2-22-2008
This is available in installer through my source http://ride4.org/shai.xml
Please ignore my previous comment
Reply
Jorge Asch said 11:42AM on 2-22-2008
If your phone locks-automatically, the automated process will not work. As long as your iphone is being used, the Scheduled Task or the cron job runs fine. If you finish using the phone, and it locks itself, tweet will not run anymore.
(at least I've been unsucessful un my attempts). Too bad, because I had already moved off twitter and created my own CGI that recorded everything on a database, used Google Maps API to graph my route, and put pins on all the towers I've 'touched' over the last 24 hours.
Reply
Jon said 3:00PM on 2-22-2008
I have the same problem.. I set it up so it connects to my own server and records the data, however once I lock it and put it in my pocket, it doesn't connect anymore.
This makes it a bit useless if it has to be unlocked for it to work, doesn't it?
Shai said 5:45PM on 2-22-2008
please please please contact me @ shaiss at gmail dot com
I've been trying all day to do what you did and would really appriciate some guidence.
Please let me know and thank you
Shai said 5:58PM on 2-22-2008
please please please contact me @ shaiss at gmail dot com
I've been trying all day to do what you did and would really appriciate some guidence.
Please let me know and thank you
The Tuesday Night Tech Show said 12:22PM on 2-22-2008
No idea why this isn't working for me--I followed the instructions five different times, nothing is happening. Sigh, can't there be an installer for this somehow? Screenshots?
Reply
mitch said 12:28PM on 2-22-2008
How far have you gotten?
If you give details, solutions may be offered.
Balazs said 12:33PM on 2-22-2008
It isn't working for me either. tweet itself works, however when it goes to execute findme I get:
zsh: exec format error: /var/root/bin/findme
What's up with this?
mitch said 12:38PM on 2-22-2008
what happens when you launch findme directly?
mitch said 12:28PM on 2-22-2008
Erica,
Very cool little app.
It took me a bit of tinkering but it works great.
I second the request for the pin to drop when viewing the map.
Thanks!
Reply
Balazs said 12:41PM on 2-22-2008
If you are getting an error such as:
zsh: exec format error: /var/root/bin/findme
download the findme binary from Erica's FTP site using Firefox not Safari. This has happened before because of the way Safari handles downloading of files. Weird. Thanks Erica!
Reply
Traci Collins said 12:51PM on 3-04-2008
This is a silly newbie question, but how do you get the findme file onto the iPhone? I don't find a way to make Safari on the iPhone download and save the file and I haven't been able to find a third party app that will let me copy individual files to a specific location on my iPhone. I must be overlooking something simple but this is driving me crazy. Any help would be appreciated. Thanks.
Balazs said 1:13PM on 2-22-2008
Right, so it seems to work now, except only on WiFi. I don't have EDGE coverage at my house, so it only uses GPRS. Can that be a problem?
When I run /var/root/bin/tweet from the terminal on the iPhone, after long delay, I get this:
curl: (52) Empty reply from server.
I can get on the internet though through Safari, so I don't know what's causing the problem.
Reply
chris said 2:33PM on 2-22-2008
find me works nicely, great idea. tweet, however does not?
Each time i run i get the error, cannot resolve host '' /private/var/root/bin/tweet:4: no such file or directory: http://twitter.com/statuses/update.xml....
Any help or advice would be greatly appreciated. thx
Reply