Starting gpsd automatically with a bluetooth GPS

I’ve lost a bit time trying to have gpsd starting automatically upon connection of my bluetooth GPS receiver (Holux M-1000) and finally I’ve found a solution that is probably not the best but is enough good for me.

At first I had to struggle against the quite completely broken bluetooth support of ubuntu intrepid.
Providentially the Blueman project is keeping a PPA repository with the last version of their fantastic Bluetooth Manager and up to date bluez packages.

Installing the Blueman manager and their bluez packages solved the most of my problems: thank you guys!

The gpsd distribution comes already with a set of udev rules (see /etc/udev/rules.d/50-gpsd.rules) that match some devices by vendor and product id and a set of hotplug scripts that are invoked upon detection of devices to start and stop the gpsd daemon. Sadly this seems to work only with serial or usb devices as the sysfs subsystem does not seem to keep any of such information for my blootooth device.

But let’s see what happens when the device is attached to a serial port …
Running udevadm monitor –udev reveals the following events:

add  /devices/pci0000:00/0000:00:02.1/usb2/2-1/2-1.4/2-1.4:1.0/bluetooth/hci0/hci0:43 (bluetooth)
add  /devices/virtual/tty/rfcomm0 (tty)
move /devices/pci0000:00/0000:00:02.1/usb2/2-1/2-1.4/2-1.4:1.0/bluetooth/hci0/hci0:43/rfcomm0 (tty)

so the device is recognized and a virtual serial port is created and relocated under the bluetooth device sub-tree.

Checking the information of the relocated rfcomm device with udevadm info -a -p /devices/… reveals that it inherits the address of the gps device as attribute:

looking at device '/devices/pci0000:00/0000:00:02.1/.../bluetooth/hci0/hci0:43/rfcomm0':
   KERNEL=="rfcomm0"
   SUBSYSTEM=="tty"
   DRIVER==""
   ATTR{address}=="00:A6:01:39:D0:A0"
   ATTR{channel}=="1"

Good! The device address can be used to write a rule for udev!

At this point I’ve got fresh versions of the GPSd’s hotplug scripts as the ones that come with ubuntu are a bit outdated and broken.
These scripts are available on the GPSd’s project subversion: I’ve got gpsd.hotplug and gpsd.hotplug.wrapper from the trunk and copied them to /lib/udev.

So I’ve added the following two rules to /etc/udev/rules.d/50-gpsd.rules

ACTION=="add", SUBSYSTEM=="tty", ATTR{address}=="00:A6:01:39:D0:A0", SYMLINK="gps%n", \
                    ENV{HOLUX_M1000}="present", RUN+="/lib/udev/gpsd.hotplug.wrapper"
ACTION=="remove", SUBSYSTEM=="tty", ENV{HOLUX_M1000}=="present", RUN+="/lib/udev/gpsd.hotplug.wrapper"

Note how the ADD rule sets an environment variable ENV{HOLUX_M1000} that is used for matching the REMOVE event.

I’ve reloaded the udev rules with udevadm control reload_rules … et voilĂ  … gpsd starts automatically when connecting my gps device.

This entry was posted in experiments and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *