Bluetooth and serial ports

On my Asus Ee PC laptop I run openSuSE 11.4. As I want decent maps to help with geocaching I installed MemoryMap using wine. To make it even more useful I want to be able to display my current location on the map.

For some time I have had a BlueNEXT GPS (BN-900GR) which is a 32 channel GPS receiver that outputs the data via bluetooth. To connect this with Memorymap I needed to create a virtual serial port and make it look like a windows port. I had lots of problems as all the tutorials I could fine related to older versions of bluez or init scripts and they no longer worked. To make it work I did the following :

First create a udev script that will run when the bluetooth device is activated. In my case I use a minature usb bluetooth adaptor that I plug in to activate the service.

I created the file    /etc/udev/rules.d/50-bluetooth.rules

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/lib/udev/rfcomm"
ACTION=="remove", SUBSYSTEM=="bluetooth", RUN+="/lib/udev/rfcomm"

The script /lib/udev/rfcomm is run when the bluetooth system starts or stops.

/lib/udev/rfcomm contains

#!/bin/sh
#
if [ "$ACTION" = "remove" ] ; then
  rfcomm release all
else
  rfcomm bind all
fi

If the script is called when the bluetooth system is stopped then rfcomm is called to release all the links otherwise rfcomm is called to create all the links. Make sure the file has execute permission.

When rfcomm is called with bind all, it reads its configuration file at /etc/bluetooth/rfcomm.conf . On my system this is

# RFCOMM configuration file.
#
rfcomm0 {
#
# Automatically bind the device at startup
   bind yes;
#
#
# Bluetooth address of the device
    device 00:1C:88:00:80:96;
#
# RFCOMM channel for the connection
   channel 1;
#
#
# Description of the connection
   comment "Bluetooth GPS";
}

The device hex numbers are for my GPS, you will need to change these to match your device. The device number can be found once you have paired the device with your computer.

Running rfcomm bind all creates the serial device  /dev/rfcomm0. You can test it is working by using the command 

cat /dev/rfcomm0

The NMEA raw data strings will be printed on the screen until you issue cntl C.

If your normal user is not the super-user, and I hope it isn't, you will not be able to use this port because of permission problems. The easiest way around this is to add your normal user to the "dialout" group. [This is true on openSuSE but on other distributions check which group owns the rfcomm0 serial port (ls -al /dev/rfcomm0) ]

To use this port in a wine application you need to map it to a windows port. Go to the directory ~/.wine/dosdevices and issue the command

ln -s /dev/rfcomm0 com1

All windows programs can now use the bluetooth serialport by accessing com1