Nokia Bluetooth Serial Console

This post would be of interest to the tiny fraction of the world population which has:

  1. A Nokia S60 phone with bluetooth capability.
  2. A computer running Linux. Specifically Ubuntu Gutsy.
  3. A bluetooth interface on the computer.
  4. A Python installation on the phone.
  5. An inability to connect the Python bluetooth console on the phone to the computer.

If by chance you happen to be part of that tiny fraction, read on.

When I was running Kubuntu Feisty, getting the bluetooth connection up and running was a complete snap. Basically, it just worked. Which was a good thing then but a bad thing now since on Gutsy, it just doesn’t work and it took me quite a while to figure out how to set it up myself.

As it turns out, the KDE Bluetooth framework is undergoing some massive code refresh and as things stand, the latest version of the framework doesn’t include quite a bit of the functionality that was present in the earlier releases. And it just so happens that Gutsy ships with this latest version. Which means that the stuff that KDE Bluetooth did automatically for me in Feisty, needs to be done manually in Gutsy.

So here we go. First, make sure your phone is visible to the PC by running hcitool scan in a shell.

antrix@cellar:~$ hcitool scan
Scanning ...
        00:18:C5:44:49:9E       marvin

Make note of your phone’s bluetooth address. Next, edit /etc/bluetooth/rfcomm.conf and configure it for use with the phone. The contents should read:

rfcomm0 {
        bind no;
        # replace with you phone's bluetooth address.
        device 00:18:C5:44:49:9E;
        channel 2;
        comment "Nokia N73 - Marvin";
}

Another problem with Gutsy is that /etc/bluetooth/hcid.conf doesn’t have a pin_helper configured. This is the program that’s supposed to ask you for a PIN when you make a bluetooth connection from the phone. A quick work around is to just set a passkey in hcid.conf and then restart the bluetooth stack (sudo /etc/init.d/bluetooth restart).

Once the configuration steps are done, initiate a bluetooth device pairing from the phone and when the phone prompts for a passkey, just input the one set in hcid.conf.

Now we’ll test if the serial link works. Run this in a shell:

antrix@cellar:~$ sudo rfcomm bind /dev/rfcomm0
antrix@cellar:~$ rfcomm
rfcomm0: 00:18:C5:44:49:9E channel 2 clean

Then, open a serial connection to /dev/rfcomm0 using a serial communication tool such as minicom. We’ll just use good old screen.

antrix@cellar:~$ screen /dev/rfcomm0

You should get a blank screen. Type AT and press enter. That should get you an OK from the phone. If you speak the AT command set, you can try more commands like typing ATDT 98898998 and your phone should start dialing that number. (Anyone remember using serial modems to make dial up networking connections?!)

Quit screen (Ctrl+a followed by \). Then:

antrix@cellar:~$ rfcomm
rfcomm0: 00:18:C5:44:49:9E channel 2 closed
antrix@cellar:~$ sudo rfcomm release /dev/rfcomm0
antrix@cellar:~$ rfcomm

Releasing the channel makes it available for use again. Now we’ll start a listener on /dev/rfcomm0 to which the Python Bluetooth console will connect.

antrix@cellar:~$ rfcomm listen /dev/rfcomm0 2
Waiting for connection on channel 2

Then open Python shell on the phone and from Options, launch Bluetooth console. When prompted on which device to connect to, connect to your computer. If you get an error on the phone that says, ‘No serial ports found!’, then on the computer run sdptool add --channel=2 SP which’ll advertise a serial port service on channel 2. Reinitiate the bluetooth console connection from the phone.

Once the bluetooth serial link is established, our console where rfcomm is patiently listening will print:

antrix@cellar:~$ rfcomm listen /dev/rfcomm0 2
Waiting for connection on channel 2
Connection from 00:18:C5:44:49:9E to /dev/rfcomm0
Press CTRL-C for hangup

Then, open a new shell and once again, use screen or minicom to open a connection to /dev/rfcomm0. If all went well, you should be greeted by the familiar Python console:

print u"hello"
hello
>>>
>>> import appuifw
>>> appuifw.note(u"hello world")
>>>

HTH!