The Garmin Edge 205 Under Linux
Michael Klier recently decided to shut down his blog. Luckily he provides a tarball of all his posts and used a liberal license for his contents. With his permission I will repost a few of his old blog posts that I think should remain online for their valuable information.
This post was originally posted October, 23rd 2007 at chimeric.de and is licensed under the Creative Commons BY-NC-SA License.
A while ago I wrote about getting myself a GPS unit to be able to record the routes I ride on my bike. I finally decided to get a Garmin Edge 205. It is mainly designed for biking but you can of course use it for navigation or geocaching as well.
I don't want to go into any detail about the features of the device itself. It's easy to use and besides recording the route, speed, and elevation profile it is also able to calculate your energy consumption based on your size, age and weight. The more interesting question is: Does it work under Linux?
The answer is: It does! In fact it works really well. All you need to access it is gpsbabel, the Swiss army knife for GPS data (which is also available for Windoze). Recent Linux kernels also contain a driver module named garmin_gps
but gpsbabel doesn't work well with it. I wasn't able to read any data from my device as long as the kernel module was loaded. But that's no problem at all because gpsbabel is able to natively talk to the Garmin Edge 205.
In order to keep udev from loading the kernel module whenever you plug in the device you have to blacklist it. On Arch Linux this is simply a matter of adding !garmin_gps
to the list of modules in your /etc/rc.conf
.
MODULES={ ... !garmin_gps}
After making sure that the aforementioned module isn't loaded anymore it's time to check if the device is detected by gpsbabel. To do that simply connect it to your computer and run the following command:
% sudo gpsbabel -i garmin -f usb:-1 Password: 0 3309180752 450 EDGE205 Software Version 2.40
The option -f usb:-1
tells gpsbabel to scan and list all connected devices. In case you have more than one, you can specify which device you'd like to access ie. -f usb:0
. If you omit the device id, -f usb:
, gpsbabel will use the first device it finds (that's useful if you only have one device).
After verifying that gpsbabel found the GPS unit you can try to read the stored track data (I don't know much about the various gps data formats yet - but after reading the man page of gpsbabel I decided that the GPX format suits me best).
% sudo gpsbabel -t -i garmin -f usb: -o gpx -F test.gpx
If everything works well you should end up with a file named test.gpx
that contains a lot of XML style data. If not you can increase the verbosity of the above script by adding the debug option -D2
.
One not so nice thing about the above command is that it will fetch all data on the Garmin Edge 205 and store it in one single file. gpsbabel supports various filters which you can use to limit the amount of data which is fetched. In our case the interesting filter is the one to manipulate track lists. This filter supports a start/stop option which enables you to limit the saved data to a given time range.
The following command reads all track data recorded on 2007-10-20 between 1AM and 23PM and drops everything else which is not in this time range:
% sudo gpsbabel -t -i garmin -f usb: -x track,start=2007102001,stop=2007102023 -o gpx -F 20071020.gpx
Remembering all that every time you want to fetch some data from your Garmin Edge 205 isn't really nice so I wrote a little script. It accepts one parameter in the form YYYYMMDD. This way you can specify the date for which the data should be fetched. If you omit this parameter, it will fetch the data of the current day instead . The script also defines a directory where the files are stored. If you intend to use this script you have to modify it to your needs. The script also checks if the generated .gpx
doesn't contain any track data (that's the case if the file is exactly 9 lines long) and deletes these files instantly.
- gpsimport.sh
#!/bin/sh # @author Michael Klier <chi@chimeric.de> # small tool to import gps track info from a garmin edge 205 GPS_DIR=/home/chi/gps GPS_BIN=/usr/bin/gpsbabel if [ "$UID" != "0" ]; then echo "ERROR: only root can run this script" exit 1 fi if [ ! -n "$1" ]; then DATE=$(date +%Y%m%d) else DATE=$1 fi cd $GPS_DIR $GPS_BIN -t -i garmin -f usb: -x track,start=${DATE}0001,stop=${DATE}2359 -o gpx -F ${DATE}.gpx if [ -f ${DATE}.gpx ]; then # "empty" track files contain exactly 9 lines if [ $(cat ${DATE}.gpx | wc -l) == "9" ]; then rm ${DATE}.gpx else chown chi:chi ${DATE}.gpx fi fi exit 0
As always, this script isn't foolproof or perfect ! Here's an example on how to invoke it:
% sudo gpsimport.sh 20071020 % ls ~/gps 20071020.gpx
So that all-together is nice - but it would be even nicer if we could just plug in the device after a trip and the data for the current day would be fetched automatically. Thanks to udev this is absolutely no problem. But in order to write an appropriate udev rule we have to find out some relevant data about our device first. You could do that by using udevinfo
which is a command line tool provided by udev itself. But it's not that intuitive to use when it comes to USB devices. A better tool to do that is usbview (must be run as root).
The above output of usbview tells us that the vendor id of our device is “091e”. That's everything we need to write a custom udev rule.
On Arch the udev rules are located under /etc/udev/rules.d/
. We will store our own rules in a separate file /etc/udev/rules.d/95-user.rules
. The corresponding rule to add to this file looks like this:
- 95-user.rules
# Garmin Edge 205 Data Import ACTION=="add", SUBSYSTEM=="usb_device", ATTRS{idVendor}=="091e", RUN="/home/chi/bin/gpsimport.sh"
As you can see the rule triggers the above script whenever we plug in the Garmin Edge 205 to our computer. After adding the new rule we have to restart udev. On Arch this is done by executing /etc/start_udev
.
That's it! Whenever you plug the Garmin Edge 205 to your computer the udev rule will be triggered and the GPS track data of the current day will be imported to your ~/gps
directory .