GPSD startup and shutdown

(19 October 2009) I used "system", "administration", "synaptic package manager" to load and install the package "GPSD" version 2.38-lubuntu3. GPSD is a program which runs permanently (i.e. a DAEMON) after the first plugging-in of a GPS device; or at least that is what is supposed to happen. It didn't. Below you will find the fix for the start-up problem i.e. when you plug in a gps receiver gpsd starts up and listens to the receiver, permitting you to use other applications which depend on it. However, for at least the case of receivers emulating character interfaces using USB, unplugging and replugging the receiver will not allow you to continue using gpsd. I have not fixed the problem, but I think I know what the problem is. Below you will find the (lengthy) explanation.

Launching the gpsd daemon

I found GPSD 2.38-lubuntu installation places (amongst lots of other placements) the following files in the associated locations:

the rules in 40-gpsd.rules are fired when USB devices have information corresponding to common GPS devices. They are all "tty" (one character at a time) devices in that file. They cause the creation of a directory entry e.g. "gps1" in /dev and the execution of gpsd.hotplug.wrapper. Unfortunately on my Ubuntu this script fails (work on next version looks as if it may fix these) for 2 reasons:

  1. Two variables are set "false" in /etc/default/gpsd which is executed by .wrapper That script file requires them both to be "true". In /etc/default/gpsd it is written that I must not edit that file but use a command line application 'dpkg-reconfigure gpsd'. When I run that it creates a (crude) window which just asks me if I want to start gpsd at boot time (I don't) and has no option to set the variables to "true". So I disobeyed and edited the file. Maybe in the next version of Ubuntu there will be a gui to configure it.
  2. An attempt is made to use a library in /lib/udev. The library no longer exists in that directory. This is being fixed in the "karmic" version of Ubuntu.

Both these are easy to fix for yourself for Ubuntu 9.04 a.k.a "Jaunty". Use a text editor (I use the nano editor); For example, in a terminal do "sudo nano /lib/udev/gpsd.hotplug.wrapper" then,

in place of the line:

. /lib/udev/hotplug.functions

put in the following to replace the missing function:

# This was formerly in /lib/udev/hotplug.functions

wait_for_file() {

[ -e "$1" ] && return 0

local count=0

while sleep 1; do

let count=count+1

[ -e "$1" ] && return 0

if [ $count -gt 60 ]; then

return 1

fi

done

}

If you are happy to disobey the "do not edit" instructions try "sudo nano /etc/default/gpsd" and change the word "false" to "true" for both USBAUTO and START_DAEMON variables. Now gpsd should load when you plug in a usb receiver. It will however remain running in the background when you unplug the receiver.

The USB plug and unplug problem

I wanted a "computer illiterate" to be able to plug/unplug the receiver in a car with minimal interaction (e.g. to take the computer into a house without having to reboot). The symptoms of my problems were:

  1. If I unplug and replug the receiver, all fixes coming from gpsd to my gps application stop. This is independent of the number of times unplug/replug. If, after the first unplug/replug, I relaunch my application which then reconnects to the daemon, fixes start arriving again. This works for the first 4 times of unplug/replug. Thereafter no fixes are delivered until I kill the gpsd daemon. After that, replugging relaunches the daemon and all is well.
  2. The first time of plugging creates a device /dev/ttyUSB0 but when you unplug it does not vanish. The next time /dev/ttyUSB1, then 2,3,4 after which unplugging the device makes /dev/ttyUSB4 vanish and re-appear as you plug/unplug but there are no fixes delivered to ttyUSB4.

Because I had fixed the "plug in" script I presumed that I had done something to upset the "unplug" scripts. Remember that this explanation applies to Ubuntu Jaunty netbook remix running on an eeepc - your mileage may vary.