Sunday, March 18, 2012

Convert that old iPhone into a GPS Tracker

Background
So I have been pondering for ages what to do with my old iPhone 3G, and after finding my steering lock broken on my motorcycle, I have decided to turn it into a GPS tracker to fit to my motorcycle.

Find my phone doesn't seem to work on my jailbroken device, so I have gone for my own implementation.

My solution is this. A python script on the phone will periodically query the CoreLocation subsystem for the phone location and then post the in a RESTlike manner to a django web service running on one of my websites. I won't cover the django web service in this post, but needless to say you can adapt this script to advertise the location of the phone to you in a variety of ways.

Once I have the location, just pasting the coordinates into google maps will show where the phone is located.

Requirements:
iPhone 3G running iOS 4.2.1 Jailbroken
Python ( Cydia )
pyobjc ( Cydia )
OpenSSH ( Cydia )
Some public web server you have access to. ( I host my own, if you don't have access to one, maybe use some other nifty trick / API / twitter to send yourself the location. )

If you haven't already, jailbreak your phone. You can google that separately as I'm not going to cover the details of that. Just remember that if you need to network unlock your phone, pay special attention to the modem firmware you load. The default one that comes with 4.2.1 is not unlockable at this stage without breaking the GPS.

Once jailbroken, use cydia to install Python, Pyobjc, VIM and OpenSSH. Now that we have all the software we need, ssh into your phone, the default username is root and password is alpine.

Get the script http://pastebin.com/mHwigZXT and adapt to you needs. You need to create a web service to receive the coordinates or conjure up some other creative way. I thought about using twitter REST API via python to twit the location.

I have just setup my own django app that is logging the REST calls to a specific url with location coordinates and accuracy. You can go low-tech and just use the apache logs of your server to track your phone as-well. Just pasting the coordinates into google will show you where the phone is.

Implementation
Get the script http://pastebin.com/mHwigZXT

Name the script without any extension, e.g. "location" ( I had troubles running it from launchctl as location.py )

SCP the script up to your phone : scp location root@10.0.0.100:/var/mobile/ ( username root passwd alpine )

SSH into your phone, chmod +x /var/mobile/location and then execute the script manually to check it. It takes a while to load all the objects and location, so be patient. 15 seconds or so at least.

To get your application to launch at boot time and to re-run the script every 15 minutes, you need to create a application plist file and put it in the right location. I have made one for you!

Get the application plist file file from http://pastebin.com/1jdb1d3d

scp that to your phone with:
scp com.my.tracker.plist root@10.0.0.100:/System/Library/LaunchDaemons/

reboot the phone.

And thats that. You should now see some calls to your apache server with a URL containing the coordinates of you phone.

Remember to leave WIFI and 3G and location services enabled! ;)

Integration
I have integrated the phone into my motorcycle and even wired to up to the bike to let it charge when the bike runs. There is also a small solar panel which charges the phone slowly to extend the life.

have fun!

Kegan




2 comments:

  1. Any ideas how to resolve this?

    uname -a
    Darwin iPhone 11.0.0 Darwin Kernel Version 11.0.0: Sun Apr 8 21:51:47 PDT 2012; root:xnu-1878.11.10~1/RELEASE_ARM_S5L8940X iPhone4,1 arm N94AP Darwin

    root# ./location
    Traceback (most recent call last):
    File "./location", line 3, in
    import objc, sys, getopt, urllib, time, socket
    File "/usr/lib/python2.5/objc/__init__.py", line 17, in
    _update()
    File "/usr/lib/python2.5/objc/__init__.py", line 14, in _update
    import _objc
    ImportError: dlopen(/usr/lib/python2.5/lib-dynload/_objc.dylib, 2): Symbol not found: _OBJC_CLASS_$_Object
    Referenced from: /usr/lib/python2.5/lib-dynload/_objc.dylib
    Expected in: /usr/lib/libobjc.A.dylib

    ReplyDelete