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
Release
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
$GPGGA,010155.000,5055.4215,N,00122.9385,W,1,04,2.3,30.2,M,47.6,M,,0000*7E
 
$GPGSA,A,3,05,26,02,08,,,,,,,,,2.5,2.3,1.0*3E
 
$GPGSV,3,1,12,08,71,146,26,05,67,279,38,07,50,061,29,10,46,147,24*7B
 
$GPGSV,3,2,12,26,38,269,42,02,23,219,20,13,17,079,17,28,10,147,19*79
 
$GPGSV,3,3,12,15,04,269,36,21,03,335,11,16,00,014,09,04,00,186,*77
 
$GPRMC,010155.000,A,5055.4215,N,00122.9385,W,0.14,7.79,230912,,,A*7A

 

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

Tags: 

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.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.