Raspbian - Connecting a bluetooth GPS using the command line

Following on from my earlier article - Connecting a bluetooth keyboard using the command line - I will now look at what is needed to connect a GPS device to my Raspberry Pi via bluetooth.

I covered installing both bluetooth and bluez - the Linux bluetooth stack - in the earlier article, so this is a good place to start if these have not been installed.

Since by this point the bluetooth stack should be installed, we simply need to pair the device with our Pi as as we did with our keyboard, however, GPS devices are quite different from the HID keyboard that we paired earlier. So first things first, lets make sure we can view the see the device:

# hcitool scan
Scanning ...
        00:02:78:17:E3:A7       BTGPS
        00:1D:4F:93:DB:E9       Steven’s Computer

We can also pair the device as we did the keyboard:

# bluez-simple-agent hci0 00:02:78:17:E3:A7 
RequestPinCode (/org/bluez/2298/hci0/dev_00_02_78_17_E3_A7)
Enter PIN Code: 0183
New device (/org/bluez/2298/hci0/dev_00_02_78_17_E3_A7)

The majority of bluetooth GPS devices use the RFCOMM Layer to transmit simple streams of position data to any connected device. As such, we must bind our device to the RFCOMM layer within the bluetooth stack. But before we do that, we need to configure the RFCOMM device by editing the file '/etc/bluetooth/rfcomm.conf' as follows:

# RFCOMM configuration file.
rfcomm0 {
        # Automatically bind the device at startup
        bind yes;
        # Bluetooth address of the device
        device 00:02:78:17:E3:A7;
        # RFCOMM channel for the connection
        channel 1;
        # Description of the connection
        comment "Bluetooth GPS device";

Our GPS device can now be bound to the RFCOMM interface with: # rfcomm bind /dev/rfcomm0 00:02:78:17:E3:A7

Testing the GPS device

Since we have bound the device to '/dev/rfcomm0', which is essentially a serial device, the simpliest method for testing what we've done so far is to 'cat' the device as we would a standard serial device, such as '/dev/ttyS0'. Providing this is has been sucessful we should see NMEA sentences streaming up the screen:

# cat /dev/rfcomm0


Processing the NMEA sentences


The NMEA sentances above are part of the NMEA_0183 data specification for the communication of marine electronic devices. The specification incorporates the data specification for a number of other such marine devices, including sonars, echo sounders, gyrocompasses and GPS devices, to name a few. As such, there is plenty of documentation that explains the protocol in great detail if one wanted to manually decode the sentences. However, we don't need to do that, we are using Linux!


gpsd - GPS service daemon


gpsd is a GPS service daemon that connects to a GPS device attached to the host computer via USB or serial port. Once a GPS device is attached to gpsd, we can then attach gpsd-aware clients to the daemon, which will then recieve ...

Since bluetooth's rfcomm layer is a serial protocol we can connect directly to this

So lets get started... firstly we must install gpsd, this is available in the Raspbian repos. Since we will want to test our installation a client would be hand to ... so we can install with: # apt-get install gpsd # dpkg-reconfigure -plow gpsd


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.