A. Talking to Bluetooth GPS devices with Linux
This is a guide for communicating with Bluetooth GPS devices on a Linux platform. As there are a wide range of GPS Bluetooth devices, and a fair number of Linux distributions, we focus on the GL50-BT device from San Jose Navigation on an Ubuntu Gutsy (7.10) distribution. However,
the ideas should be generally applicable to other Bluetooth devices, and to other recent Linux distributions. Much of this information is gleaned from a thread on Ubuntu forums, but is made specific here to Bluetooth GPS devices.
B. For the impatient
Impatience being one of the cardinal virtues of a FOSS programmer, if you do not have the time to go through the entire article, here is a minimal set of steps for getting your Bluetooth GPS device working:
- Get Bluetooth working on your computer: You will need to install the appropriate packages. On some machines, such as Acer laptops, you might also need to install a kernel module. Check that Bluetooth is working, with:
hcitool dev
This should display the ID of the Bluetooth device on your computer, something like:
hci0 00:16:CE:DE:3C:B1hcitool scan
will now scan for other devices that are in range. Make sure that Bluetooth on the GPS device is on, as some devices are discoverable only at startup, or when a button is pressed. You can also check that the scan is working by having another Bluetooth device, such as a mobile phone, within range. You should see something like:
00:01:53:02:DF:A5 GL50BT
If you have trouble detecting the device, one thing to ensure is that the batteries are in good shape. Bluetooth uses up a fair bit of power, and II have had trouble connecting when the batteries are low.
- Set up /etc/bluetooth/hcid.conf
- Set up /etc/bluetooth/rfcomm.conf
- Establish RF communications:
sdptool add --channel=1 OPUSH
sudo rfcomm bind /dev/rfcomm0 00:01:53:02:DF:A5
Use the channel no. specified in /etc/bluetooth/rfcomm.conf, and the Bluetooth ID for the GPS device as reported by “hcitool scan”. - Read data fom the GPS device:
cat /dev/rfcomm0
will read realtime NMEA data from the device, but included with this will be binary data in the device buffersudo gpsd /dev/rfcomm0
will start gpsd using the proper device node, and
gpspipe -r
will show you properly formatted NMEA sentences.
On to the detailed instructions.
C. Packages to install
This is what I have installed, though I am not sure if all packages are needed, nor if I have missed some that are not included by default in Gutsy. Please let me know of any required modifications:
- bluez-gnome
- bluez-utils
- gnome-bluetooth
- kdebluetooth
- cutecom
- gpsd
- gpsd-clients
- gpsdrive
Also, useful are
gpsd seems to work with the GL50-BT, though I did have some problems, and am not yet completely satisfied.
D. Get bluetooth working on your laptop
This might involve having the proper drivers, and the appropriate kernel modules. For an Acer laptop, you should use the acerhk kernel module. Thus,
sudo modprobe acerhk
echo on > /proc/driver/acerhk/blueled
The blue LED on the front should now come on. “hcitool dev” should also show you something like
hci0 00:16:CE:DE:3C:B1
Check http://www.cakey.de/acerhk/ for supported model numbers. If you do not see your model number, and the above instructions do not work, you can often force the series to the closest model number lower than the actual model number. Thus, for the unsupported Acer Travelmate 4200, use:
sudo rmmod acerhk
sudo modprobe acerhk force_series=4000
echo on > /proc/driver/acerhk/blueled
Likewise, the Acer Aspire 5550 can be coerced into working with
sudo modprobe acerhk force_series=5020
The documentation for this driver in the Linux kernel source has more details.
E. Check device visibility:
Turn the GL50-BT off, start “hcitool scan”, turn it on, hold the little white button, labelled “connection”, down for a couple of seconds, and release. The connection button can also be used to re-establish a dropped connection while the GPS is running, but this does not seem entirely reliable.
hcitool scan
should show you something like:
00:01:53:02:DF:A5 GL50BT
00:1D:FD:EC:AC:44 Rahul
The GPS device here is the one labelled GL50BT, while the other one is a Bluetooth-enabled mobile phone that was in range. The first string of digits is a device-specific ID.
F. Edit /etc/bluetooth/hcid.conf
Mine looks like:
#
# HCI daemon configuration file.
#
# HCId options
options {
# Automatically initialize new devices
autoinit yes;
# Security Manager mode
# none – Security manager disabled
# auto – Use local PIN for incoming connections
# user – Always ask user for a PIN
#
security none;
# Pairing mode
# none – Pairing disabled
# multi – Allow pairing with already paired devices
# once – Pair once and deny successive attempts
pairing multi;
# Default PIN code for incoming connections
passkey “1234″;
}
# Default settings for HCI devices
device {
# Local device name
# %d – device id
# %h – host name
name “%h-%d”;
# Local device class
class 0×3e0100;
# Default packet type
#pkt_type DH1,DM1,HV1;
# Inquiry and Page scan
iscan enable; pscan enable;
discovto 0;
# Default link mode
# none – no specific policy
# accept – always accept incoming connections
# master – become master on incoming connections,
# deny role switch on outgoing connections
lm accept;
# Default link policy
# none – no specific policy
# rswitch – allow role switch
# hold – allow hold mode
# sniff – allow sniff mode
# park – allow park mode
lp rswitch,hold,sniff,park;
}
From my incomplete understanding of the file format:
- The “autoinit yes” and “security none” options are important.
- In the device section, the “lm master” is what is recommended, though things seemed to work for me with “lm accept”. Not sure what the difference is.
- In the device section, the “class 0×3e0100″ is important. Part of the bit settings in the class indicate that this is a location device. However, there are apparently other ways (sdptool) of setting up communications.
G. Edit /etc/bluetooth/rfcomm.conf
Mine now is:
#
# RFCOMM configuration file.
#
rfcomm0 {
# Automatically bind the device at startup
bind no;
# Bluetooth address of the device
device 00:01:53:02:DF:A5;
# RFCOMM channel for the connection
channel 1;
# Description of the connection
comment “GL50BT GPS device”;
}
Notes:
- The device ID string in “device 00:01:53:02:DF:A5″ is specific to a GPS unit. Use the one reported for the GL50-BT by “hcitool scan”.
- The comment string is arbitrary.
H. Establish the RF communication:
sdptool add --channel=1 OPUSH
should return something like,
OBEX Object Push service registered
and,
sudo rfcomm bind /dev/rfcomm0 00:01:53:02:DF:A5
should set up /dev/rfcomm0 for communication with the device. Again, the last string is the device bluetooth ID, e.g., as reported by “hcitool scan”.
I. Read data from the device
You can check quickly that things are working with:
cat /dev/rfcomm0
Be warned that binary characters in the output might be interpreted as ANSI escape sequences, and scramble your terminal settings. Pipe output into less. (For gnome-terminal, you can recover from a scrambled terminal with Terminal > Reset and Clear, followed by hitting keyboard return.)
A better way is to use gpsd. E.g.,
sudo gpsd /dev/rfcomm0
will set it running in daemon mode. You can examine NMEA sentences from the GL50-BT with
gpspipe -r
One can also run cutecom, using device /dev/rfcomm0. All the usual GL50 device-specific commands, @PCgs, @PCsr, @PCrr, etc., work as expected. Programmatic readout of stored data should also work, but I have not tried that as of yet.
J. Resuming connection, and data reading
Note that once the above commands (C-H) are done, there is no need to redo them unless the machine is rebooted. Thus, one can turn off the GPS device, turn it on again (maybe checking that it is visible with “hcitool scan”), and reading GPS data from /dev/rfcomm0 should still be possible. Likewise, gpsd should still be running, so that rerunning “gpspipe -r” should start showing NMEA sentences.







2 Trackbacks/Pingbacks
16 Comments
sgosnell, January 21, 2008:
You don’t need all the packages you installed. The bluez stuff is all obsolete, and shouldn’t be used. One of the bluetooth packages, for whatever distro you’re running, is enough. I’ve also had problems with gpsd, and have basically given it up. It’s not necessary.
buckycat, January 21, 2008:
Thank you for your comments. I had thought that bluez-utils, for example, was needed to get hcid, etc., but I do need to check out what a minimal set of packages would be.
As for gpsd, I very much like the concept of having a GPS daemon. The gpsd site lists good reasons as to why it has trouble with some GPS devices, and I think that it would be useful to work on improving gpsd. One thing that I would like to see is to have it respond to udev alerts from plugging in USB GPS devices.
Regards,
Gora
sgosnell, January 21, 2008:
All the documentation I’ve been able to find, especially on the bluez home site, indicates that it’s obsolete, no longer maintained, and shouldn’t be used. Any package for a standard distro should have the same things, improved and better. On my Asus Eee, I just did an apt-get of bluetooth, and that was enough to make bluetooth work.
I agree that the concept of having a gps daemon is good, but I’ve never been able to make anything recognize the GPS using it, either USB or bluetooth. There isn’t much documentation available for it, and what there is isn’t very informative. If you can improve it and make it work, good on you.
sgosnell, January 21, 2008:
I finallly got gpsd working. I downloaded and compiled it, and “gpsd /dev/rfcomm0″ seems to enable it, after running hciconfig to start the dongle, and binding it to rfcomm0. Roadnav finally sees a gps on gpsd. I made a shell script, put it on my system tray, and now I think I’m ready to navigate with Roadnav. I have two bluetooth gps devices, three nav systems for them (Palm, N800, EeePC), and I’ll have to decide which to use. I know I’m keeping the Palm for at least awhile, because I know it works. The maemo apps for the N800 are very new, and not ready for prime time, but I do want to check them and see how they progress. I’ll probably use the Palm for primary nav, and switch between the Eee and N800 for testing.
buckycat, January 22, 2008:
Good to hear that you got gpsd working. I will also check up on removing requirements of the bluez-* packages.
Currently, besides my laptop, I have a Nokia E51 that can talk to the Bluetooth GPS device. However, the laptop seems more reliable! One thing that I have noticed is Bluetooth communications get problematic, without other warning, when the battery is low either on the phone, or on the GPS device. Makes sense, I suppose, as Bluetooth seems quite power hungry.
I really have to take a look at Maemo. The problem has been that I do not have easy access to a Maemo-enabled device. How big are these tablets?
Regards,
Gora
jaloma, February 6, 2008:
Thanks for this great tutorial, i get now my BT 929 connect to the EEEPc 4G and gpsdrive. At next i will try a real tracking with my car.
bfn
jaloma
buckycat, February 8, 2008:
Dear Jaloma,
You are most welcome. We will soon be putting up a site to demonstrate solutions to GPS tracking, and offering the possibility of uploading your track logs. Actually, I think that there might already be sites doing that, but we will do a better job
Regards,
Gora
zcat, September 26, 2008:
Hi. have been reading LOADS of posts to get my latop to pair with E51. Running Ubuntu Hardy with all updates and with all the packages you suggest. Also gnome phone manager. The hcitool finds it sdp tool gives info……..
BUT when I try to connect to phone, the phone asks for passkey, I enter that of hcid.conf? (ie 1234 default or other s I tried), BUT still asks for passkey, set to no security…stilll asks for passkey?! WTF cannot connect…
In gnome-bluetooth the device is found and trusted but still…
and trying hid –connnect gives me same troubles.
Did not make any oth erchanges to config file like rfcom since sdptool browse XX:XX:XX:XX:XX:XX gives channels already set.
Whatever I try I get ask for passkey on phone?!!WTF Tried downgrading Bluez-utils but need the bluez-pcmcia or cannot get Bekkin pcmia adaptot to work (no built in bluetooth on this thinkpad T42…)
The connection all works on windoze OK, and the Belkin setup disk that installed obex tools and gprs wicj after successful pairing just works..as it all should
ARRGG I left windows for linux some time ago. I would really like this to work HELP please
zcat, September 29, 2008:
Pairing Working!
BTW I have Nokia e51 and Thinkpad T42 laptop with Ubuntu Hardy and Belkin pcmcia Bluetooth adaptor
>hcitool scan –class #finds the class of device
>sudo gedit /usr/bin/mypinwrapper #create this file with following content:
echo “PIN:1234″
> sudo gedit/etc/bluetooth/hcid.conf #mine is shown below, change class to whatever was found to be the class of your device, change “auto”, “multi” and point to “pin_helper” file:(default passkey remains 1234):
#
# HCI daemon configuration file.
#
# HCId options
options {
# Automatically initialize new devices
autoinit yes;
# Security Manager mode
# none – Security manager disabled
# auto – Use local PIN for incoming connections
# user – Always ask user for a PIN
#
security auto;
# Pairing mode
# none – Pairing disabled
# multi – Allow pairing with already paired devices
# once – Pair once and deny successive attempts
pairing multi;
# pin helper
pin_helper /usr/bin/mypinwrapper;
# Default PIN code for incoming connections
passkey “1234″;
}
# Default settings for HCI devices
device {
# Local device name
# %d – device id
# %h – host name
name “%h-%d”;
# Local device class change to whatever your device is
class 0×5a020c;
# Default packet type
#pkt_type DH1,DM1,HV1;
# Inquiry and Page scan
iscan enable; pscan enable;
discovto 0;
# Default link mode
# none – no specific policy
# accept – always accept incoming connections
# master – become master on incoming connections,
# deny role switch on outgoing connections
lm accept;
# Default link policy
# none – no specific policy
# rswitch – allow role switch
# hold – allow hold mode
# sniff – allow sniff mode
# park – allow park mode
lp rswitch,hold,sniff,park;
}
>sudo gedit /etc/default/bluetooth
enable HID, DUND and PAND (change from =0 to =1)
>sudo /etc/init.d/bluetooth restart
Now it should work PROVIDED:
-start bluetooth preferences (gnome-bluetooth), TRUST and BOND to trusted the phone (should see its name…if not goto services tab and restart all the services)
-NOW INITIATE PAIRING ON THE PHONE. This is really strange. After bonding, the phone and laptop successfully communicate by recogising each other and the phone beeps and a pop-up asks for PASSKEY. If you enter here it will NOT work. WTF! You need to initiate paring from phone which was not obvious or easy to find.
On phone Goto Connections>Bluetooth>Hit Right key or forward on Phone>Options>New paired device
Asks for passkey and asks to accept connection YAY! it works
Now to try out the syncing…
Dusan, February 6, 2009:
Hi, you are always talking about file hcid.conf if I don’t have this file should I create it? or is there something else what can I do? I have changed first file rfcomm.conf
I have Ubuntu 8.10
Gora Mohanty, February 8, 2009:
Hi Dusan,
It seems that the Bluetooth stuff in Ubuntu 8.10 has changed, and everything is now done through the bluetooth-applet in bluez-gnome. Will check up on this tomorrow (when I can get hold of a Bluetooth GPS unit) and update this.
Regards,
Gora
ben van 't ende, February 8, 2009:
Hey Gora,
The only thing that kept me from upgrading to 8.10 is the fact that bluetooth is broken. I have read reports that this only seems to be fixed in the most recent jaunty alpha4.
I am following this thread: http://ubuntuforums.org/showthread.php?p=6691648#post6691648
It looks I will skip Intrepid alltogether. I have it running on my eeepc with gnome perfectly though (no bluetooth).
gRTz
ben
Gora Mohanty, February 13, 2009:
Dear Dusan, Ben,
I just retried the above instructions on Ubuntu 8.10 with a Holux M-241 device, and they worked. Just go ahead and create /etc/bluetooth/hcid.conf if it does not exist.
If it still does not work for you, please let me know what GPS device you are using, and what error messages you see.
Regards,
Gora
ben van 't ende, February 16, 2009:
hey tHNx for checking it out? ik think i will have a go at it next weekend. weren’t you the one with the openmoko/
gRTz
ben
Gora Mohanty, February 16, 2009:
Sure, no problem. Let me know how things go.
Yes, I do have an OpenMoko (where did you see that I did?), and try to do things with it from time to time. However, thus far it has largely been a toy, and we have not done serious work with it. Hope to change that soon.
Regards,
Gora
ben van 't ende, February 16, 2009:
Rahul told me you have one;-) Still waiting for a good opportunity to buy one. I wanted to wait a little longer until the models would be a little slicker. Can’t find you on our common facebook group unfortunately.
gRTz
ben
Leave a comment