Friday, March 23, 2012

Update: Convert that old iPhone into a GPS Tracker

If you have not already, take a look at the previous post. This is an update on that covering my Django server side component.

In the first part we created a simple python script which announced the GPS co-ordinates of the device to a web server. So to complete the solution we will do the following.
  • Create a model and view to store posted tracker co-ordinates
  • Create a view to visualize the data with google maps API
I won't cover setting up django itself, there are plenty of good docs on the django site for that. Once you have django up and running create a new application therein like this:
python manage.py startapp tracker
create tracker/models.py and tracker/views.py with the following code: http://pastebin.com/0rxDhaX5

create tracker/templates/tracker/plot.html with the following code: http://pastebin.com/T3ACVDpY

Add the following to your urls.py
(r'^tracker/(?P.*)', 'DJANGOPROJECT.tracker.views.tracker'),
(r'^plot/', 'DJANGOPROJECT.tracker.views.plot'),
Now add the APP to you INSTALLED_APPS in settings.py
'DJANGOPROJECT.tracker',
Now the python app on the device will be able update the location models in the django application. And you will be able to view the current position via the /plot/ url.

Kegan

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




Friday, October 2, 2009

Hudson servers FAIL

I noticed the worst of all coding bugs! as is with many java development houses, we use hudson for all our building. And I discovered today that when hudson.dev.java.net is down, the web interface for your hudson server starts to break..

For some fucked up reason, Hudson dev team thought it would be shit cool to make calls to their website from all hudson servers project specific configuration pages..

see the request here I intercepted.
hudson.yourdomain.com:80 127.0.0.1 - - [02/Oct/2009:17:30:54 +0200] "\x16\x03\x01" 501 292 "-" "-"
hudson.yourdomain.com:80 127.0.0.1 - - [02/Oct/2009:17:30:54 +0200] "\x16\x03\x01" 501 292 "-" "-"
hudson.yourdomain.com:80 127.0.0.1 - - [02/Oct/2009:17:30:54 +0200] "\x16\x03\x01" 501 292 "-" "-"
hudson.yourdomain.com:80 127.0.0.1 - - [02/Oct/2009:17:30:54 +0200] "\x16\x03\x01" 501 292 "-" "-"

WTF were you thinking!!!

Anyway so if you have the missing batch task buttons bug or general hudson weirdness like you get a submitForm error when you try save settings,
add a over-ride for

127.0.0.1 hudson.dev.java.net

on your pc which you are trying to access your hudson with. You can direct it at any apache server anywhere!

please goto hudson forums and WTF in there!

Kegan

Wednesday, September 23, 2009

Using Jython to query JMX Objects / Attributes

I was tinkering today with re-implementing some nagios and cacti checks to use jython to query jmx objects and attributes since I am getting tired of re-compiling my java code jmx query-er.

Anyway, here is the basic code in a nut shell. You need to adapt this to your needs ofcourse.

#START
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

from array import array
# put correct auth info in here
ad=array(java.lang.String,["username","password"])
n = java.util.HashMap()
n.put (javax.management.remote.JMXConnector.CREDENTIALS, ad);
# this is a example but you probably want the url as a URL object or similar...
jmxurl = javax.management.remote.JMXServiceURL("service:jmx:rmi:///jndi/rmi://10.0.0.233:12086/jmxrmi")
testme = javax.management.remote.JMXConnectorFactory.connect(jmxurl,n)
connection = testme.getMBeanServerConnection();

# The actual query
object="java.lang:type=Memory"
attribute="HeapMemoryUsage"

# Execute
attr=connection.getAttribute(javax.management.ObjectName(object),attribute)
print attr

# Close the connection
testme.close()
#END

Wednesday, July 29, 2009

Importing CVS into SVN with history

Converting old CVS repos and their history is a question that always comes up. So heres a mini-howto convert cvs to svn and preserve the history.

Firstly install cvs2svn, on Debian based distros you can grab it with apt:
sudo apt-get install cvs2svn

cvs2svn can also be downloaded from http://cvs2svn.tigris.org/

First we need to setup a place to work and create a CVSROOT dir else cvs2svn wont be happy.
mkdir -p ~/oldcvs/CVSROOT
mkdir ~/newsvn/

Now lets copy the CVS repo's data into ~/oldcvs/modulename
cp -r /path/to/cvs/modulename /home/user/oldcvs/modulename
cvs2svn --encoding=iso8859_10 --dumpfile=/home/user/newsvn/modulename.SVN ~/oldcvs/modulename
for Encodings check http://docs.python.org/library/codecs.html#standard-encodings
also dumpfile didnt like the ~ in the path so full path needed here!

If all goes well you should end up with a nice report of all the revisions and their mother.
Now we need to import our newly create .SVN file into subversion, in my case I need to create a new project for it aswell like so:
svnadmin create /path/to/svn/repos/modulename

Then just import the dump into our SVN repo we created earlier
svnadmin load /path/to/svn/repos/modulename <~/newsvn/modulename.SVN

All done.
Due to the unavailability of cheap iPhone 3G's in Sweden, I nabbed one in a second hand store in Switzerland for 300 CHF ( 2200 SEK ) and another two online for about 3000 SEK each.

Each phone was locked to some or other provider. Here is my experience in jailbreaking and unlocking a Swisscom locked iPhone 3G.

Firstly get-a-mac, I dont do windows and never will. You will need PwnageTool 3.0 for mac. Get it from one of these:
Procedure
  1. Update the iPhone to 3.0 via iTunes.
  2. Launch PwnageTool and click the expert button, click the iPhone 3G.
  3. You should see the 3.0 firmware in the main window, this is from the iTunes library actually so its trustable.
  4. Click the firmware for 3.0 and Next
  5. Click General and Next
  6. Check "Activate the phone", this makes the phone activate without the provider sim
  7. Check "Enable baseband update", this makes the the phone unlock-able via Cydia
  8. Resize the root partition to at least 700mb pref 1gb if you can spare that.
  9. Neuter bootloader should be unchecked
  10. under Cydia choose "manage sources" and add http://repo666.ultrasn0w.com
  11. Click next through Packages and Logos until you can click the Build button and then Next again
  12. Follow instructions in PwnageTool on how to put your phone into DFU mode
  13. Restore you custom image onto you iPhone via opening iTunes and hold down Option and click restore
  14. Choose your Custom firmware which was generated by PwnageTool
  15. And watch the jailbreaking process
Next we need to unlock your phone to access GSM network, quite easily, all you need to do turn off your 3G and open Cydia and search for ultrasn0w (thats a numerical ZERO ) and install it, reboot the phone and voila!

Saturday, February 21, 2009

Fixing time sync messed up VOB files

I have many home video discs recorded on a Sony mini DVD cam which are giving me hell trying to import them into iMovie. Seems even playback was only running the first 20 seconds of any VOB file and then stopping. 

Resolved my issues with a nifty little mac app called Mpeg Streamclip

It opened up the streams and identified and corrected the time issues right away! I then could export direct to a Quicktime format h.26X format and get my movies into iMovie!

I love free software...

K