Set a Nokia N70 Clock from a Bluetooth GPS

From rukapedia
Revision as of 15:41, 15 July 2006 by Peter (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

As soon as I started to fool around with geocoding photographs using GPS traces, I realized that it was important to be able to sync the clock in my Nokia N70 phone (taking the photos) with the GPS time (received and logged by my GPSlim 236 Bluetooth GPS).

So I wrote a Python script that attempts to do just that: it connects to a Bluetooth GPS, gets the UTC time, attempts to figure out the local time zone setting on the phone, and updates the phone's time.

I'm new at Python, new at GPS, and new at Series 60, so this is a primitive first attempt; I relied heavily on the excellent work of Nick Burch, especially his S60 Python NMEA Location Viewer script, to make this work.

Challenges

As I've documented in Time Zones, Python and the Nokia N70, there isn't proper time zone support on the Nokia N70 (or maybe it's a general Series 60 phone limitation, I'm not sure). This makes figuring out how to translate the GPS time (always GMT/UTC) into local time a little harder than usual. As such the script assumes that the difference between GMT (as returned by time.gmtime()) and local time (as returned by time.localtime()) reflects the difference between GMT and local time; there's an additional little kludge to try to adjust properly for DST by comparing the phone's GMT value with the GPS time -- if the hour is the same, then we assume no DST, if the phone is one hour ahead, then we assume DST.

I welcome comments on better ways of handling all this.

System Requirements

I've developed and tested this script on a Nokia N70 phone using a GPSlim 236 Bluetooth GPS. I don't know if it works on any other combination of Series 60 phone and Bluetooth GPS, but I'd venture a guess that it would.

Before you can use this script, you'll need to have Python for Series 60 installed an operating. This is fortunately quite easy to do, and is very well documented. No additional Python libraries are required.

The script depends on the presence of the e32.set_home_time() Python function, which appears to only be in more recent releases.

Download Source Code

You can browse the source code from a browser, or grab the latest version of the source code using Subversion at:

svn://svn.reinvented.net/GPS/gpstime

or

http://svn.reinvented.net/GPS/gpstime

Sample Usage

The only change you should need to make to the source code is to set the address of your Bluetooth GPS on the following line:

gps_addr='00:0B:0D:16:D1:BD'

I've you've already paired your Bluetooth GPS with a Mac OS X machine, then you can easy look up the address in System Preferences | Bluetooth -- highlight the GPS on the Devices tab, and find the Device Address line, then change the dashes to colons, and copy this address into the Python script. I suspect similar facilities exist in other operating systems. I plan to add a "select device" dialog in a future update of the script to eliminate the need for this step.

Save the updated source code, and then transfer it to your phone; install the script, start Python on the phone, make sure your GPS is on and talking to satellites, and then select Options | Run script and select the gpstime.py script you installed.

If everything goes as planned, you should see a pop-up telling you that the script has connected to the GPS, and another telling you that it's set the time.