4

I want to see my usb bluetooth dongle as a device ttyUSB*. It's possible? It shows "hci mode" in lsusb command.

    $ lsmod 
    Module                  Size  Used by
    rfcomm                 33168  0 
    btusb                  11595  0 
    bluetooth             193568  5 btusb,rfcomm
    rfkill                 18202  1 bluetooth
    snd_bcm2835            16304  0 
    snd_pcm                77560  1 snd_bcm2835
    snd_timer              19998  1 snd_pcm
    snd                    58447  3 snd_bcm2835,snd_timer,snd_pcm
    snd_page_alloc          5145  1 snd_pcm
    leds_gpio               2235  0 
    led_class               3562  1 leds_gpio

    $ lsusb
    Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
    Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
2
  • Could you clarify what you're trying to do? Connect to a remote serial device over bluetooth perhaps?
    – Gagravarr
    Commented Aug 20, 2013 at 21:56
  • Yeah! I want to use a simple serial python module to communicate two bluetooth devices. Commented Aug 21, 2013 at 11:55

1 Answer 1

4

What you want to do is possible, but how you're approaching it isn't correct

In order to talk serial over a bluetooth link, you need to use rfcomm to setup a serial connection. With that in place, you then open the rfcomm /dev/ entry, and a connection is initiated over bluetooth (or an error returned). Finally, you then read and write from the rfcomm device to send and receive your serial data.

If you are only ever going to be talking to a single static Bluetooth device, your best bet is to define the link in /etc/bluetooth/rfcomm.conf so that the rfcomm device is always created. If you're going to be talking to lots of different devices, you'll need to do something (perhaps using hcitool scan or sdptool browse) to identify the bluetooth address + channel, then use rfcomm bind .... to setup the rfcomm object, and finally connect to that from python.

If you're new to all this, I'd suggest you follow tutorials like this one or this one to get started.

If you wanted to connect to the Dial Up Networking rfcomm serial service, and there was only one device offering that in range, you'd do something like:

$ hcitool dev
Devices:
hci0    74:AA:BB:CC:80:FF

$ hcitool scan
Scanning ...
AA:BB:CC:AA:BB:CC   Gagravarr's Phone

$ sdptool browse | grep -A 10 'Dial-Up Networking'
Service Name: Dial-Up Networking
Service RecHandle: 0x10005
Service Class ID List:
  "Dialup Networking" (0x1103)
  "Generic Networking" (0x1201)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 1
Profile Descriptor List:
  "Dialup Networking" (0x1103)

$ rfcomm bind /dev/rfcomm1 AA:BB:CC:AA:BB:CC 1

# Open /dev/rfcomm1 in python and read/write to it

With that, we scan to find the address of the remote device (must be visible!), we sdp browse to find the rfcomm channel of the remote service, then rfcomm bind to create a /dev/ entry that'll connect us to that channel on that host. Open /dev/rfcomm1 and you're away! (Well, assuming you have set the permissions up properly that is!)

3
  • 1
    Basically you have to use the RFCOMM mode know as the SPP Profile of the Bluetooth Device to use it as a TTY interface. Some Bluetooth serial dongles give you a UART on USB and all this code stuff happens on the dongle transparently. I have one like that and its just like sending text to a com port and the other side gets it. Really great answer and will come in handy later! +1beer
    – Piotr Kula
    Commented Aug 21, 2013 at 13:57
  • If I need to communicate 2 bluetooth devices (both using rfcomm) they need to be paired? I was able to generate the rfcomm0 into raspberry, but in my x86 (running archlinux) I can't, working on this. Commented Aug 29, 2013 at 16:51
  • To talk to two different devices, you'll need to setup a different rfcomm device for each one
    – Gagravarr
    Commented Aug 29, 2013 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.