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

Categories
Computers Linux

Acerfand crashes Acer Aspire One 110

I have an Acer Aspire One 110 Ab that I have upgraded with 1 GB RAM (for a total of 1.5 GB) as well as upgrading the BIOS to version 3309.

Before upgrading the BIOS, which was done in an attempt to improve the stability of 802.11 networking, the acerfand program worked wonders to keep the fan running as little as possible.

Once I upgraded the BIOS to 3309 the acerfand program no longer worked. Instead of turning the fan off the fan was running at full speed for a second every other second.

On March 14th, version 0.07 of acerfand was released and I tried it out in the hope that it would fix the fan issue for by BIOS version. While it did turn off the fan, it caused the computer to reboot after a few minutes. Clearly, this was even worse than the alternative.

I did some trial and error and changed the value 0x20 to 0x21 (two places) for the 3309 specific values. In other words, roughly half-way down in the file, my acerfand file now looks like this:

"${BIOS_VERSION_3309}")
	#change: handle 3309 seperate 0xAF -> 0x20
	R_FAN=55
	R_TEMP=58
	FAN_CMD_OFF=21
	FAN_CMD_AUTO=00
	RAW_FAN_STATE_OFF="0x21"
	;;

This has completely solved the issue. The fan now stays off as long as the temperature is below 70 degrees Celsius. The rest of the time (which is virtually always) it is dead silent. Case closed. For now.

Categories
Computers Mac

OS X panics when inserting USB memory

Suddenly my Macbook started crashing whenever I inserted a USB memory stick. Not just crashed – it completely froze.

iousbfamily-crash

The problem report report listed a module called IOUSBFamily and I had a vague idea that I had changed that some time back for something that had to do with my iPhone.

iousbfamily-report

It turns out the solution to the problem was rather simple. Just log onto Apple Developer Connection and search for IOUSBFamily and whatever version of OS X you are running. In my case I searched for “IOUSBFamily 10.5.6”.

Download the Mac OS X USB Debug Kit file for your version of OS X. The .dmg file will include the kernel extension with logging enabled as well as the standard one. Install the one without “log” in the file name. Then restart your computer. The problem should now be solved.

Categories
Computers

Count number of bits in a Ruby integer

How would one count the number of set bits in an integer? If it was a C/C++ application I guess I would do a for-loop and shift out the bits and keep a running sum. I would be hard pressed to do it in less than three lines of code and would probably do it in five to include the curly braces.

Given the same problem and having to find a solution in Ruby I came up with this:

v.to_s(2).split(//).inject(0) { |s,i| s + i.to_i }

In other words; first convert the integer to a binary string and split the string into an array. Then use the inject method to start with zero (remember even numbers are objects in Ruby) and iterate over the array with a code block, adding each digit in the binary string to get the total sum.

Categories
Computers Linux

Target fix for Statpress Reloaded

Statpress Reloaded by Manuel Grabowski is a nice and simple plugin that helps to keep track of the hit rate to WordPress blogs and is something I personally use it for this site.

statpress

Apart from the fact that the plugin is a bit slow it miscalculates the monthly target hit rates. This has been mentioned to the plugin maintainer but until that fix gets added, here is a short description and fix.

The following sections in statpress.php are repeated in four places and is used to normalise the number of hits so far this month over the entire month.

/ date("d", current_time('timestamp')) * date('d', mktime(0, 0, 0, date('m', current_time('timestamp'))+1, 0, date('Y', current_time('timestamp'))))

However, this uses entire days which leads to incorrect results. The error is more predominant early in the month and early in the days.

I have replaced the above segment (four instances) with this:

/ (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * 86400 * date('t')

This uses seconds since the beginning of month as the basis for normalisation which is more precise. It is not perfect – among other things it will fail exactly on midnight on the first of each month due to a divide by zero.

Categories
Computers Mac

Messenger for Mac signing out each night

Every night at precisely 01.00 CET (00.00 GMT) Messenger for Mac signs me out. When this happens a manual intervention is required in order to sign back in. I just can’t figure out why this is happening. The error message is “The system is unavailable now so you have been signed out of Microsoft Messenger”. I am running Microsoft Messenger for Mac version 7.0.1.
messenger-signout
messenger-version

Categories
Computers Linux

Increase upload size to Drupal site

If you run a Drupal site and want to upload big files you may have run into the default file size limit of 1 MB. While this is probably fine for most blogs it is way too small for most intranet deployments.

The limit for PHP is by default set to 2 MB for file uploads.

To increase this to 10 MB, add the following to the .htaccess file in your Drupal directory or to the Apache site definition:

php_value upload_max_filesize 10M
php_value post_max_size 20M

More information can be found here.

Categories
Computers Linux

Using Drupal to run an intranet

I have been looking for ways to replace a Sharepoint driven intranet with something else. The driving force behind this has mainly been one of platform compatibility. Sharepoint is great if you use Office and Internet Explorer on Windows. For all other users it is a usability nightmare.

There are lots of hosted or shrink-wrapped solutions for sale but the market of intranet solutions is now so mature that I felt there had to be open source solutions.

I found Alfresco, LifeRay and a few others and installed most of them. I was perplexed, however, by the sheer amount of features that were enabled out of the box. I really prefer something that starts off light and can then expand according to my needs. KnowledgeTree felt lighter but didn’t do much more than document management and I knew I also wanted a wiki as well as forums.

For a while I tried to integrate KnowledgeTree with MediaWiki and phpBB for a best-of-breeds solution. I couldn’t get all of the them to play nicely together and allow users to authenticate using accounts from a Windows Active Directory.

drupalorg

In the end I settled on Drupal. Why? It starts off light but has a truck-load of modules that can be added. I like the structure of the code. And it feels fresh – perhaps almost too light. I would have liked to see some professional free themes targeted for intranets, they would have helped to sell in the concept internally in competition with professional offerings.

The question of the authentication integration with Active Directory was solved very nicely by the module “Webserver authentication” and adding HTTP authentication to the web site in Apache where the web server is configured to use the bindings provided by Samba‘s WinBind. The only thing to remember is to set the Drupal administrator to the the same login name as the administrator in the Windows domain. After that you should disable the log out menu option in Drupal. The only thing remaining is to add some Javascript code to be able to provide a link to make the browser forget the cookie in order to force a relogin.

css.php