Bluetooth Console

One of the nifties things I have on my cell phone is a bluetooth capability: the ability to communicate with other devices nearby at relatively high speeds over a wireless protocol. Bluetooth is a very useful tool for development: I don’t have to worry about USB cables or anything else, and I can talk equally well to my Linux desktop with an abicom BT adapter as I can to my Powerbook with its built-in bluetooth.

One thing that no one has mentioned yet about the new Python release is the Bluetooth console. It took some doing, but I finally got it connected to my Linux desktop, and found an app that will let me connect to the port. Now, I basically have a way to tell my phone what to do over Bluetooth:

[crschmidt@peanut ~]$ sudo cu -l /dev/rfcomm0 
Connected.
Python 2.2.2 (#0, Dec  2 2004, 18:12:32) 
[GCC 2.9-psion-98r2 (Symbian build 540)] on symbian_s60
Type 'copyright', 'credits' or 'license' for more information.
Type 'commands' to see the commands available in this simple line editor.
>>> 

This has sped up my application development significantly: with this in place, I can start to experiment with different code at a rapid rate: without sending almost identical files to the phone several dozen times to test them, nor typing on the 3650’s keypad to enter my code. I just type into a normal tty, and it acts exactly like a local python interpreter.

This is also possible, and documented as such, using TCP/IP over GPRS instead of Bluetooth. However, the speed restrictions of that cause it to be much less practical. It’s like typing into ssh over bluetooth: sure, it’s okay, but you almost never want to do it if you can avoid it.

Here’s what I ended up doing to get it working:
– Get a working bluez install. Bluez is the standard Linux protocol stack, and is built in to most recent kernels.
– Test that you can talk to the phone, using hcitool scan, hcitool info.
– Register an “SP” (serial port) service with sdpd. sdptool add --channel=3 SP
– Ensure that sdpd is running
– Set up an rfcomm port to receive the communications: rfcomm listen /dev/rfcomm0 3
– (On Phone) Open Python, then bt_console.py
– On the computer, you should see:

[crschmidt@peanut ~]$ sudo rfcomm listen /dev/rfcomm0  3
Waiting for connection on channel 3
Connection from 00:60:57:41:86:C2 to /dev/rfcomm0
Press CTRL-C for hangup

– Using taylor-uucp, type cu -l /dev/rfcomm0
– Welcome to the phone!

If you want to test to make sure it’s working, you can do something simple like:

import appuifw
appuifw.note(u'Howdy!', 'info')

from there, refer to the excellent Nokia documentation for more tips and tricks on what you can do. I think this is definitely a great example of what power the distribution has, and I’m surprised that more people haven’t been writing about it. Has anyone besides me (and Nokia employees) gotten this working?

14 Responses to “Bluetooth Console”

  1. Steve Pomeroy Says:

    That sounds really nifty. I think I’m going to have to give it a go while I’m still on break. I don’t know python, but that is largely irrelevent 😉

  2. Chris Double Says:

    I’ve got this working as well under Linux (using the kdebluetooth suite of tools) and Windows. It’s very very useful I agree. I don’t think it could be used for testing bluetooth apps though could it? For example, connecting to a bluetooth GPS (which is what I’m doing at the moment via C++). How many bluetooth connections can the phone make at a time?

  3. Christopher Schmidt Says:

    Chris: you’re right that it can only make one connection at a time. However, you can use the TCP console (There’s documentation in Programming for Python) to connect over TCP/IP, which would then let you do connections over Bluetooth. However, you gotta keep in mind that it’s slow, and you may not be able to connect on a port you want to over GPRS/other data plans depending on your carrier and service plan.

    Which phone do you have? Which GPS? I’m thinking of a Delorme Bluelogger.

  4. Chris Double Says:

    I’ve used the TCP console and it’s not too painful. I’ve used worse that’s for sure! I’ve got a Nokia 7610 and a Nokia 3650. I upgraded to the 7610 but kept the 3650 around for testing to make sure things still work on the earlier version phones.

    I have a Leadtek Bluetooth GPS (http://www.66.com/route66/products.php?cid=UK&sec=5&ssec=0&prodid=891). It’s pretty neat. I use Bluesky GPS and Power Nagivation and they both work fine. I also wrote a C++ app that gets the GPS NMEA data and logs it to the MMC card so I can one day analyse the logs.

    I tried getting the cell id location data via C++ to map with the GPS data and I was able to do it with synchronous calls but not with async notification of changes. The async changes worked on the 3650 but crashes the 7610. I see the Python API has synchronous calls so I might try that out but doing a call every second might be a bit draining. That’s why I preferred the async version.

    I’m quite excited about the Python release. It’s very nice.

  5. Christopher Schmidt Says:

    Chris: Yeah, the GPS you have looks nice, but the price tag is out of my range. I’m thinking of the bluelogger instead which seems like a good tool.

    I’m going to do something similar: GPS + GSM stumbling using a GPS + cell phone.

    Seems like everything is going to have to be synchronous for these kind of apps in python, at least for the time being. However, I think that the Python development scene will accelerate quickly, and we may see things coming out pretty soon that makes that not the case.

    I’ve never dealt with callbacks though, so I wouldn’t know how to deal with them even if I had the option.

  6. Chris Double Says:

    I got the GPS through an online auction so got it much cheaper thankfully. I looked through my notes and realise it wasn’t the async notification of the cell id changing that was the problem. That worked fine. It was the notification of the signal strength that was causing the problem. I should probably just leave that out. I’ll look at writing a Python wrapper for it maybe. I look forward to seeing how your GPS/GSM stumbling goes with Python. Location based stuff has lots of potential I think.

  7. Nick Says:

    Just a quick note: on my fc3 install you actually need: sdptool add SP –channel=3

  8. Mark Eichin Says:

    On Mac OS X, it looks like you just want “kermit -l /dev/cu.Bluetooth-PDA-Sync” to talk to the mac side of the bt_console session.

  9. nedrichards :: Nick Richards » Bluetooth Console Says:

    mentation for your Series 60 phone you might be interested in these instructions on how to access the phones console via Bluetooth in Linux. Just a quick note: on my FC3 install y […]

  10. snoopy Says:

    >> […] without sending almost identical files to the phone several dozen times to test them, […]
    Have you tried / heard of p3nfs ( http://www.koeniglich.de/p3nfs.html )? It’s a nfs-application for S60 running quite fine on my 3660 using bluetooth.

  11. Mayank Jain Says:

    Hi,
    this is how i did it…
    1) emerge -v taylor-uucp #for cu utility & i’m using gentoo!
    2) rfcomm listen /dev/rfcomm0 1 #as my /etc/bluetooth/rfcomm.conf had channel=1
    3) sdpd
    4) rfcomm listen /dev/rfcomm0 1
    5) in a new terminal, run “cu -l /dev/rfcomm0”

    but still… i cannot repeat my previous command… 🙁

    cya,
    makuchaku

  12. Taras Says:

    Thanks for mentioning that this works over tcp/ip. Gnubox + the tcp/ip console work very well. It’s much less of a pain in the ass to setup than bluetooth directly.

    See http://www.rlachenal.com/bluetooth-6600-linux/

  13. ton Says:

    I could not get btconsole to babble with a non-English version of Windows, Python on the phone would crash on trying to setup a connection. It turns out that in windows my bt serial port is listed with characters that are not recognized. Renaming this in windows to e.g. Serial port cured my problem

  14. giorgia Says:

    Hi, I have a problem with btconsole.py script. I work on linux machine with an usb-bluetooth key and a 6600 with PythonForSeries60.SIS (from PythonForSeries60_for_2ndEd_SIS.zip). I can use bluetooth with bluez lib, ussp-push, rfcomm, etc, but when I launch bt_console.py from 6600, I got an error ( error: (2, ‘No such file or directory’) ) in line 129 of btconsole.py (in c:/system/libs/):

    addr,services=socket.bt_discover()

    Help me, please….