Skip to content

Instantly share code, notes, and snippets.

@0
Last active May 15, 2024 07:01
Show Gist options
  • Save 0/c73e2557d875446b9603 to your computer and use it in GitHub Desktop.
Save 0/c73e2557d875446b9603 to your computer and use it in GitHub Desktop.
Connecting a Bluetooth device for serial communication on Arch Linux.

The following are instructions for connecting a Bluetooth device for serial communication on Arch Linux using BlueZ 5.31.

Prerequisites

The following packages are required:

  • bluez: bluetoothd
  • bluez-utils: bluetoothctl, rfcomm

Pair

  1. Start daemon: systemctl start bluetooth

  2. Pair using bluetoothctl:

    power on
    agent on
    scan on
    ... wait ...
    scan off
    pair <dev>
    
  3. Create serial device: rfcomm bind 0 <dev>

You should now have /dev/rfcomm0.

Unpair

  1. Remove serial device: rfcomm release 0

  2. Unpair using bluetoothctl:

    remove <dev>
    power off
    
  3. Stop daemon: systemctl stop bluetooth

Troubleshooting

Check rfkill list to make sure that the Bluetooth device is not blocked.

@lukasz-kwasniewski
Copy link

great!

@dimitar-kunchev
Copy link

Awesome guide! It helped me out just perfect.

If I may add a few things for people reading it:

  • for me the bluetooth service was not enabled to start on boot, nor was the rfcomm module loaded. Surprisingly rfcomm bind... command doesn't spit errors in that case - just exits and doesn't create the serial port.
  • Once you have paired a device it will be remembered by the core bluetooth module. So after reboot (host and peripheral) you don't have to do the bluetoothctl commands - just go to step 3 (rfcomm bind...) and when you open the serial port it will connect.
  • I was surprised how well all this works. Tried bullying it around by loosing connection, restarting peripherals and etc while working and even when the serial port was kept open and commands were executing everything kept re-establishing connection and resuming just nicely. No need to re-bind the serial port again or anything (until the next host reboot that is).

Tested with debian kernel 4.10 on a Cubieboard2 using CSR8510 dongle from adafruit (product ID 1327).

@adlerweb
Copy link

adlerweb commented Jul 5, 2017

The rfcomm-utility is now considered deprecated and was removed from the official package. You can still find it at au (bluez-utils-compat or bluez-rfcomm).

@keinstein
Copy link

@adlerweb what should be used instead? Today, I came across this page and it still worked on my Debian Testing/Sid system.

@ryanstout
Copy link

@adlerweb Same here, any replacement for rfcomm?

@E1k3
Copy link

E1k3 commented Jan 25, 2018

Not that I am aware of, but if you find one, please share it here and on unix.stackexchange

@hpsaturn
Copy link

hpsaturn commented Apr 6, 2020

Good, with my current version of Debian, Blueman applet fails after pair, it did can't create the serial device (rfcomm bind), but with bluetoothctl works fine. Thanks.

@Hritik14
Copy link

Hritik14 commented Dec 3, 2020

Weird for issue on Archlinux.
After pairing, when I attempt to connect via bluetoothctl itself, I get these:

[bluetooth]# connect 38:0B:3C:XX:XX:XX
Attempting to connect to 38:0B:3C:XX:XX:XX
[CHG] Device 38:0B:3C:XX:XX:XX Connected: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device 38:0B:3C:XX:XX:XX Connected: no

Made me scratch my head for an hour when I found this gist and just rfcomm bind 0 <dev> worked.

EDIT: Just figured out the even the wiki suggests to only pair. Damn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment