Categories
Computers Gadgets Linux

Track your whereabouts with a Nokia phone

This is a follow-up article to a previous story on how to use the GPS in a Nokia phone. The last article described how to use a Python script to query the phone on the position. In this article we will add to the Python script to make it also dispatch position reports as UDP packets as well as a server script that saves the data to a sqlite3 database which is then used to display a web page with a map. The end result will look something like this:

tracker

All files are contained in the attached file at the end of this article. The server scripts have been written for Ubuntu 8.04 but will no doubt work on other distributions. Please note that you will need to install a couple of packages (php-sqlite3, php5-sqlite3 and libdbd-sqlite3-perl) to make the scripts run. The various scripts assume that they are all placed in the same location (i.e. in the web site folder). Read the security section below to ensure that the scripts are not publicly available.

Client script
The script ‘tracker.py’ should be copied to the phone according to the instructions in the previous article. Before copying it to the phone it must be edited. You will want to change the server host, the port and the secret.

Sqlite3 database
The data is kept in a sqlite3 database. The initial database is created by running the script create_database.sh. Do not run that script again as it will completely wipe the database.

Server script
Edit the file ‘tracker_server.pl’ and set the port number (line 8 ) and the secret (in the regexp on line 23) to the same values that you set in the client script. The server is then started by running the server script ‘./tracker_server.pl &’. Add the command to /etc/rc.local if you want it to start automatically when the server is restarted.

Web pages
Create a web site and point the document root to the folder where you put the files. Then reload the server.

Start the script
Finally, start the script on the phone and wait for it to acquire a GPS fix. This should cause the new position to be reflected on the web page.

Security
As mentioned above it a wise thing to prevent access to the script files if they are located in the same folder as the web pages. The easiest is to add an .htaccess file in the web folder with the following content:

<FilesMatch "\.(db|pl|sh|py)$">
Deny from all
</FilesMatch>

Attachments
tracker.zip

Categories
Computers Gadgets

Use Python to access the built-in GPS in a Nokia phone

For some reason I have agreed to participate in one of the longest bike rides here in Sweden this year, the 300 km Vätternrundan. During the race every bike rider has an RFID tag on the leg which is read as you pass various points along the course. Apparently there are only a handful of locations where the tags are read and I wanted to do better than that.

I thought about using a phone with built-in GPS and send the positions in real-time to my server so that my loved ones can see where I am during the race. First I hoped to be able to use my iPhone 3G but the lack of background processes in a non-jailbroken iPhone meant it was a no-go. I then turned to my previous phone, a Nokia N82.

Doing a native application didn’t seem necessary for this type of application. I really just need a small hack to send periodical updates to an Internet server (which I will also write). I knew that it was possible to write Python applications for Series 60 phones but to be able to access internal resources like the GPS required signed applications.

Various Internet sources spoke about how to access the GPS information from Python but they all seemed to lack some detail that made it not quite work. At the end I got it working and this is how I did:

  1. Download and install Python for S60
  2. Download Python Script Shell with a test UID
  3. Sign the Python Script Shell by using this web page
  4. Download LocationRequestor with a test UID
  5. Sign the LocationRequestor .sis file with the same web page as above
  6. Move the two signed .sis files to the phone and install them
  7. Move the attached script to your phone (e.g. using Bluetooth) and place it under C:\Python or E:\Python. Personally I prefer the latter since I can then reset my phone and have all the files intact on the memory card
  8. Start Python and run the script

The above has been tested on a N82 (v 30.0.019) but may work on other similar phones with built-in GPS (e.g. N95).

In a future article I will follow up with an updated script that also sends the GPS data to a remote server. Stay tuned.

Attachments
gps.zip

Categories
Computers Linux

Ruby on Rails application could not be started

If you try to run an application with Passenger (mod_rails) and get the error “No such file or directory – /nonexistent” it could be due to some files in the Rails application being owned by root. To fix the issue just change the owner to some other user.

passenger_error

css.php