Archive for the ‘apple’ Category.

HOWTO: Lojack your iPhone and track its location

Update: After further testing, it seems there are a couple of major problems with this setup. The first is that the iPhone doesn’t appear to update if it goes to sleep and isn’t plugged into mains power. The second is that the GPS coordinates I’m getting are wildly inaccurate for my location (varying by a few hundred kilometres) so I figure there’s something wrong with the “findme” application called below. I’ll keep looking for a better way, but for now take this article with a grain of salt.

In this article I’ll explain how to program your jailbroken iPhone to automatically upload its location to a server of your choosing at regular intervals. This will work whenever your iPhone is switched on and has a network connect (3G or Wifi).

As I’m going on holidays tomorrow, I’m going to be in situations where theft of personal belongings is a lot more likely. So after coming up with the idea this afternoon, I spent the last few hours hacking together a tracking solution for my phone. It idles silently in the background, popping up every fifteen minutes to write a latitude/longitude pair to a timestamped database on my server.

This tutorial is going to be a whirlwind because it’s 11pm and there’s so much to explain. And I have a holiday to go to.

You will need:

  • One jailbroken iPhone: I used an iPhone 3G, not sure if this is possible with an original iPhone. To jailbreak your phone, use QuickPWN. Disclaimer, warranty, own risk etc etc.
  • MobileTerminal, OpenSSH, Netatalk and cURL, installed as packages from within Cydia
  • findme, a script written by Erica Sadun and available in a binaries package on her site
  • access to a server with PHP5 & MySQL (possible with other configuration but outside the scope of this article)
  • a moderate level of coding chops – I rate this project “moderately difficult” because of the diverse areas of skill required.

The basic steps involved are:

  1. Preparing your iPhone to be messed with
  2. Teaching your iPhone to query its location using GPS
  3. Constructing a server-side script to record location data
  4. Teaching your iPhone to run the location script at regular intervals
  5. Outputting the data in a readable format

Let’s get started.

The Setup

After jailbreaking your iPhone you will install MobileTerminal, OpenSSH, Netatalk and cURL through Cydia. Then you’ll need to connect to your phone to drop files onto its disk. The easiest way is to connect over Appletalk, but if you’re handy with a command line (or don’t have a Mac) you can ssh root@10.1.1.1 with default password ‘alpine’ and your iPhone’s actual IP address (get this in settings -> network) from your PC.

Drop the findme script into /bin. Now make it executable using chmod 775 findme. When you invoke findme from the command line, it will return some XML containing your phone’s latitude and longitude, like this:

<?xml version=”1.0″?><SearchResults><Success>true</Success><Latitude>-33.887242</Latitude><Longitude>151.256718</Longitude><Method>Skyhook WiFi Location</Method></SearchResults>

(Eagle-eyed readers will noticed I’ve given myself a fancier address in this example.)

The Storage

So now we’ve got a process on your iPhone that delivers GPS over XML. The next step is to transfer that information to a database. For this part, I’m relying heavily on Erica Sadun’s iPhone Lojack article on TUAW, which goes over the same stuff as this article but using Twitter as the output channel.

What we want to do is post the output of findme to a PHP script which then posts the data. You’ll need to create a shell script and upload it to the same folder as findme. Here’s a template:

#! /bin/sh
curl –basic –url http://www.yourserver.com/lojack/index.php5 \
–data status=”`findme`” \

Save this file as ‘loc’ (no extension) and copy it to the same directory as ‘findme’. Don’t forget to make it executable: chmod 755 loc

Now, on your server at the path specified above, create a PHP file that grabs the posted status message and writes it to a database. This script assumes you have a database with a table called ‘locs’ containing two DECIMAL(9,6) fields and a TIMESTAMP field with the current time as its default entry:

< ?php

$username=”username”;
$password=”password”;
$server=”localhost”;
$database=”mylocations”;

$status = $_POST['status'];
$status = stripslashes($status);

$xml = simplexml_load_string($status);

//echo “Status: ” . $status;
$lat = $xml -> Latitude;
$lon = $xml -> Longitude;
echo $lat . ” ” . $lon;

$conn = mysql_connect( $server, $username, $password ) or die(“Err:conn”); //connect
$rs = mysql_select_db( $database, $conn ) or die(“Err:db”); //select db
$sql = “insert into `locs` (lat, lon) values ($lat, $lon)”; //the query
$rs = mysql_query( $sql,$conn );

? >

Now you should be able to invoke loc from the command line (shell, whatever) and it will send the XML to your server script, which will parse out the GPS coordinates and save them to a database. If it’s not working, try removing the comment slashes from //echo “Status: ” . $status; to see what results cURL is getting.

Timing is Everything

Great, so that script sorts out a single location upload. To be useful as a lojack, we want this upload to occur at a regular interval. For that, we’ll use the iPhone’s own LaunchDaemon service. Modify the instructions found in step 4 of the TUAW article to suit your setup. Here’s the script I’m using, com.apple.lojack.plist:

<?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.lojack.upload</string>
<key>ProgramArguments</key>
<array>
<string>/bin/loc</string>
</array>
<key>StartInterval</key>
<integer>900</integer>
</dict>
</plist>

The 900 in the script above specifies this script will run every 900 seconds (15 minutes). You’ll need to restart your iPhone before the LaunchDaemon will work.

Output your results

It’s no good storing all this away on a server somewhere. You need to make it user-friendly. This script will query the database and print the output according to your choice: vanilla, or in tables with links to Google Maps:

< ?php

$username=”username”;
$password=”password”;
$server=”localhost”;
$database=”mylocations”;
$layout = $_POST['layout'];
$conn = mysql_connect( $server, $username, $password ) or die(“Err:conn”); //connect
$rs = mysql_select_db( $database, $conn ) or die(“Err:db”); //select db
$query1 = mysql_query(“SELECT * FROM locs”);

echo ‘<form action=”where.php5″ method=”post”>’;
echo ‘<input type=”radio” name=”layout” value=”plain”>Plain<br>’;
echo ‘<input type=”radio” name=”layout” value=”table”>table<br>’;
echo ‘<input type=”submit”></form>’;

if ($layout == “plain”) {
while ($table1 = mysql_fetch_array($query1))
{
echo $table1[0] . “,” . $table1[1] . “,” . $table1[2] . “,” . $table1[3] . “<br>”;
}
}

if ($layout == “table”) {
echo “<table border=1><tr><td>Timestamp</td><td>Latitude</td><td>Longitude</td><td>id</td><td>Link</td></tr>”;
while ($table1 = mysql_fetch_array($query1))
{
echo “<tr><td>$table1[0]</td><td>$table1[1]</td><td>$table1[2]</td><td>$table1[3]</td><td><a href=\”http://maps.google.com/maps?q=$table1[1],$table1[2]\”>Map</a></td></tr>”;
}
echo “</table>”;
}

? >

While I’d love to show you the results, I’m not quite ready to share the intimate details of my physical location with all of you. Hopefully this article can act as a guide for those with a little knowledge in all of these areas – let me know in the comments if there’s anything that’s unclear. In the future I’d like to build a way to render the data collected as a heat map, or a series of paths – but for now, I’ve got a beach to go and lie on.

How to connect your iPhone/iPod to UNSW Uniwide wireless internet

UNSW provides a campus-wide wireless network for students and staff to access the internet – the UniWide network. Any mobile device with support for 802.11x and WPA encryption can connect to the network. Two access methods are provided: WPA-Enterprise authentication and WPA-Personal Web Authentication. These instructions demonstrate how to connect an iPhone or iPod to the network with WPA-Enterprise. (If your device does not support WPA-Enterprise, see the WPA-Personal instructions.)

Contrary to IT Services’ website instructions, iPhones and iPods running the 2.0 firmware (including all iPhones sold in Australia) do support WPA-Enterprise. Connecting to the ‘uniwide’ network is superior to ‘uniwide webauth’, because it does not require the user to enter their username and password in a browser to get online. This connection also does not time out after 30 minutes. Instructions follow:

Continue reading ‘How to connect your iPhone/iPod to UNSW Uniwide wireless internet’ »

iPhone App Store suggestion: “Try Before You Buy”

One problem with the Apple’s online App Store for its iPhone/iPod Touch applications is that deciding whether to spend money on an application is more difficult than it should be. I have a simple solution to this: let us try the application before we buy it. Or at least give us a day to play with the application before you charge our account.

The App Store allows users to post reviews of applications; this helps others to decide if an application is worth their money. However, there’s no guarantee that Apple will allow a plurality of opinions on its website – especially the honest, rude and invective reviews that (for better or worse) can have a big influence on purchasing decisions. And as far as I can see, there’s no system in place for distributing review copies of software (even to large, mainstream media outlets), as happens with all other commercial software platforms. Even existing iPhone App Store review sites focus on free applications, leaving developers like Adamcode, makers of iPhone budget software ‘Spend’, to compile their own reviews from the blogosphere.

(By the way, if you’re looking for some basic, but great, software to manage your budget, Spend is a worthwhile investment. I can never remember to take notes or get receipts, but my iPhone is always with me.)

As I said before, the solution is simple: let us download a trial version of the product without paying, then give us the option to pay for it after 24 hours (or whatever time/usage limit the developer decides), or to have it wiped from our iPhone. I guarantee this will lead to greater revenue for Apple’s developer community (and thus more development for the iPhone) if people don’t fear being burned by poor purchasing decisions.

Could Apple do this? Apple already does online movie rentals, so we can assume they’ve got the technology to make content disappear after a given period of time. Developers also know this is a hurdle for potential customers, because they are making ‘lite’ versions of paid applications (such as ‘Spend Lite’ from aforementioned Adamcode). I’d love to try out a game like Crash Bandicoot Nitro Kart 3D, but I’m wary of spending $AU13 on a piece of junk. If I could try it out for a day, it would make my purchasing decision much more informed.

Are there any applications you want to buy, but would like to try first?