Update 2016-08-17: I’ve been through also 14.04 LTS and 16.04 LTS, see the comments below for the small differences in configuration.

Still out of office for the New Year I can think about Open Seas … As you all know (?) I am a long time fan of OpenCPN navigation tool and I have promoted its virtues on an Linux system  in an article. Now, I have this new Clevo 270EM laptop with (C)Ubuntu 12.04.1 pre-installed and I would like to use my excellent Nokia LD-3W GPS Bluetooth Appliance with it (just for learning, for the future box which I would actually build for the maritime usage one day). Unfortunately not manufactured anymore, the Nokia LD-3W is some excellent small piece of hardware ! I use it everywhere, especially in my car. But it excels also in the city, being always available and accurate even when walking on narrow streets, beating easily any phone with built-in GPS device. The battery life is excellent. So why not maritime use, since it seems to resist well the humid conditions as proven by my multiple trekking trips.

There is no easy way (in this particular case)

Sorry about that. You may want to try the below, standard method which works for most of the Bluetooth devices (such as phones) like a dream. But we may find out that OpenCPN will not receive the NMEA data from Bluetooth GPS device this way. This said not to disappoint you at the end.

Ubuntu 12.04.1 Bluetooth Apps Bluez

Make sure that you have the Bluez packages with utilities installed. They are really good!

If you do not have that Active Bluetooth Device icon in any taskbar, the device is perhaps not activated. In my Clevo 270EM I needed to press Fn-F12. In the Settings, you need also to turn the Bluetooth Device ON, of course...

If you do not have that Active Bluetooth Device icon in any taskbar, the device is perhaps not activated. In my Clevo 270EM I needed to press Fn-F12. In the Settings, you need also to turn the Bluetooth Device ON, of course…

Bluetooth devices, Nokia N9 Phone connected and paired already

This is the starting point for this article. If you do not know how to connect your phone, the below explanation is also good for your that, just put it in a discoverable Bluetooth mode.

Bluez - Set up of a new Bluetooth enabled GPS device

Using the Bluetooth setup wizard the GPS device pairing is going to be fun !

Bluez - Search and Find !

Turn on the modest but powerful Nokia LD-3W and Bluez finds it for you in no time, provided that it is somewhere in this planet….

Bluez - Set the 0000 pin-code

Nokia LD-3W is a headless device (a black box, if you like) with but one single button, therefore it has the dreaded ‘0000’ PIN-code. Ask the wizard to use that code instead of the fancy, overkilling security automatically generated one.

Bluez - Ready to Connect

OK, just hit that button.

Bluez - Connected !

Et voilà, we are connected !

Bluez Bluetooth Manager showing now the phone and the GPS device

This is a good sign, you should mark the new GPS device as ‘TRUSTED’ while you are here. Then hit the Settings button to start exploiting the available Services on this device. For GPS, there is but the Bluetooth serial line service available.

Bluez Bluetooth connection assistant - serial port

There is not much choice here…

Bluez Bluetooth connection assistant - serial port - end

… and here even less.

Bluez Bluetooth connection assistant - serial port - nice Ubuntu touch

This oblique pop-up windows is a nice touch, if you have time to read the message, you may find out that the device name is /dev/rfcomm0.

Bluez Bluetooth Manager shows data from Nokia LD-3W

Bluez Bluetooth Manager shows clearly that data is constantly received from Nokia LD-3W

Now it should work with OpenCPN, right ?

I warned you, this is the dreaded annoyances.org speaking. Let’s give it a try, though.

OpenCPN 3.0.2 on Ubuntu 12.04.1 Bluetooth GPS but nothing happens

OpenCPN 3.0.2 on Ubuntu 12.04.1 set on Bluetooth GPS over /dev/rfcomm0 but nothing happens.

Let’s not give up !

That’s why you are reading this article, right ? This international team (south-african-american-french-finnish-to-start-with) will beat any big monopoly closed system 4 – 0 (a soccer score) !! Sorry if it is getting a bit more complex from now on, though.

Which googled suggestions are NOT working

Dynamically created /dev/rfcomm0 device is not actually available for the non-root user : it looks like that it is reserved for some GPRS applications or such:

canne@clevo:~$ ls -l /dev/rfcomm0
crw-rw---- 1 root dialout 216, 0 Jan  2 10:11 /dev/rfcomm0

But setting this to /etc/group

dialout:x:20:root,ubuntu,canne,nobody

does not change anything. Also, the obvious solution of running OpenCPN with sudo (or otherwise as root) does not help, either.

Let’s cut in a bit deeper

The exact Linux kernel version matters, as well as the Linux distro, in my case (C)Ubuntu 12.04.1 LTS.

canne@clevo:~$ uname -a
Linux clevo.homenet.org 3.5.0-18-generic #29-Ubuntu SMP
Thu Oct 25 07:26:14 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

It is noteworthy that if you repeat the above procedure from scratch after a reboot (i.e. create the /dev/rfcomm0 device again), you can read the GPS device information as root, from the terminal.

canne@clevo:~$ sudo su -
[sudo] password for canne: 
root@clevo:~# cat /dev/rfcomm0
$GPGGA,091145.000,435 ... C
$GPGSA,A,3,22,03,06, ... *35
$GPGSV,3,1,12,19,84, ... *70
$GPGSV,3,2,12,11, ... *7B
$GPGSV,3,3,12,18,18, ... *79
$GPRMC,091145.000,A, ... A*64
$GPGGA,091146.000,4350.1753,N, ... 0*5F
$GPGSA,A,3,22,03, ... 2.9*35
...

But you cannot read the /dev/rfcomm0 device as a normal user.

canne@clevo:~$ cat /dev/rfcomm0
cat: /dev/rfcomm0: Device or resource busy

Busy ?

root@clevo:/etc/udev/rules.d# fuser /dev/rfcomm0
/dev/rfcomm0:         1149
root@clevo:/etc/udev/rules.d# ps -ef | grep 1149
root      1149     1  0 09:51 ?        00:00:03 /usr/sbin/bluetoothd

Well, that makes sense, the device is used by the Bluetooth daemon. But maybe the serial line cannot be shared ? Let’s kill the device by removing it from the Bluez Bluetooth Manager. (right-click the icon).

The Suggested Solution

Using the above observations, I concluded that it is necessary to :

  1. Not to share the rfcomm device with anybody else, such as bluetoothd
  2. Address the non-root user access problem with udev ACL access rights

Creating a manually set-up device, say /dev/rfcomm9

The instructions are largely inspired by those which I found from blog.petrilopia.net. Add the following lines in the /etc/bluetooth/rfcomm.conf file with your favourite text editor :

root@clevo:/etc/bluetooth# vi rfcomm.conf
...
rfcomm9 {
#    # Automatically bind the device at startup
    bind no;
#
#    # Bluetooth address of the device (your device)
    device 00:02:76:c7:82:38;
#
#    # RFCOMM channel for the connection (this is the default)
    channel    1;
#
#    # Description of the connection
    comment "Nokia LD-3W";
}
...

Prepare the PIN-code (with your BT-address, of course) and test the connection :

root@clevo:~# mkdir -p /var/lib/bluetooth/00:02:76:c7:82:38
root@clevo:~# echo "00:02:76:c7:82:38 0000" \
>/var/lib/bluetooth/00:02:76:c7:82:38/pincodes
root@clevo:~# rfcomm connect 9
Connected /dev/rfcomm9 to 00:02:76:C7:82:38 on channel 1
Press CTRL-C for hangup

Hangup and wait until you do not see anymore the /dev/rfcomm9 device (which was created dynamically and its binding will be removed). Remember, if it is not going away, use fuser(1) to find out the process (ex. OpenCPN) who is using it.

root@clevo:~# ls -l /dev/rfcomm*
crw-rw---- 1 root dialout 216, 9 Jan  2 14:51 /dev/rfcomm9
...
root@clevo:~# ls -l /dev/rfcomm*
ls: cannot access /dev/rfcomm*: No such file or directory

The next thing is to make the device node with adequate access rights by creating a udev rule, which is done by creating the below file (with canne replaced with your group – and not user name) :

/etc/udev/rules.d/60-extra-acl.rules
KERNEL=="rfcomm[0-9]*", NAME="%k", GROUP="canne", TAG+="udev-acl", TAG+="uaccess"

Connect the device again (in Nokia LD-3W you can see from the three turning lights that it has got both the Bluetooth connection and a GPS satellite fix) :

root@clevo:~# rfcomm connect 9
Connected /dev/rfcomm9 to 00:02:76:C7:82:38 on channel 1
Press CTRL-C for hangup

This time leave the above connection running. In another shell as root (or with sudo), test that data is flowing in :

root@clevo:~# cat /dev/rfcomm9
$GPGGA,144009.780,, ..
...
root@clevo:~#

Note that you are not left hanging, but you get a prompt again after the buffer is emptied. Now try the same thing as you :

canne@clevo:~$ cat /dev/rfcomm9
$GPGGA,144018.000,4350.1649,N...
...
canne@clevo:~$

Looks promising ! Let’s test with OpenCPN, running it as ourselves, from the desktop button, but modifying in the configuration dialog (as above) /dev/rfcomm0 to /dev/rfcomm9.

OpenCPN reads NMEA from /dev/rfcomm9 as non-root user

After changing the device to /dev/rfcomm9, the NMEA data is flowing into OpenCPN as a spring stream!

The Final Touch – Let’s Make It Persistent

You do not probably want to go through all the mayhem every time you restart the application / your computer ? Let’s make it persistent !

root@clevo:/etc/bluetooth# vi rfcomm.conf
...
rfcomm9 {
#    # Automatically bind the device at startup
    bind yes;
...

Restart your system. At next reboot the /dev/rfcomm9 device node is created automatically and the first application which opens the device gets the NMEA stream.  If the stream is not there (i.e. the device is turned off) you will not get the connection back, automagically on the fly.

Practically, this means that you need to make sure that your Nokia LD-3W device (or other external Bluetooth GPS) is powered on, preferrably for sufficiently long time that it has got a satellite fix. Only then start OpenCPN. This is somewhat annoying but I do not have an answer for that. However, as the battery life of Nokia LD-3W allows it to be turned on all day long, that is perhaps not a big deal, although more in-depth analysis and testing would be required for serious navigation usage.

Happy And Precise Navigation for 2013 !! Be careful out there.