Connect Bluetooth sound devices using command-line
Published on Nov 22, 2019 by Sachin.
Every time I try to play something on the Bluetooth device from my laptop I have trouble connecting to the devices using the GUI. The UI crash most of the time or show unexpected behavior. Looks like the GNOME interface is not very helpful when interfacing with Bluetooth devices.
This prompted me to use the more reliable command-line utilities which I’m going to share in this post. The post describes in detail the packages and commands needed with examples to help connect the Bluetooth sound devices from laptop. I am using Fedora 29 as my GNU/Linux distro.
Enable Bluetooth controller
First and foremost the controller on the system needs to be enabled or
unblocked. The rfkill
command provided by util-linux
1
package is helpful here. The util-linux
provides basic system utilities.
The system may have a hardware switch(Hard blocked) and the software
switch(Soft blocked, usually in the system setting) to turn on the Bluetooth
controller. The status of both hardware & software switches can be verified
using rfkill list
command:
1: # rfkill list 2: 0: tpacpi_bluetooth_sw: Bluetooth 3: Soft blocked: yes 4: Hard blocked: no 5: 1: phy0: Wireless LAN 6: Soft blocked: no 7: Hard blocked: no
Use the device index number to enable/unblock the controller:
1: # rfkill unblock 0
After the controller is enabled
1: # rfkill list 2: 0: tpacpi_bluetooth_sw: Bluetooth 3: Soft blocked: no 4: Hard blocked: no 5: 1: phy0: Wireless LAN 6: Soft blocked: no 7: Hard blocked: no 8: 15: hci0: Bluetooth 9: Soft blocked: no 10: Hard blocked: no
Install Bluetooth utilities and enable the service
Once the controller is enabled, we need utilities to interact with the device
mostly to list all the devices available around and connect the device. The
bluez
2 package from http://www.bluez.org provides necessary
Bluetooth utilities.
Start the Bluetooth service:
# systemctl start bluetooth
Connect Bluetooth device
Start scanning3 the devices around:
1: # bluetoothctl scan on 2: Discovery started 3: [CHG] Controller 4C:EB:42:XX:XX:XX Discovering: yes 4: [NEW] Device 06:99:13:XX:XX:XX ARTIS BT99 5: [CHG] Device F6:9F:77:XX:XX:XX RSSI: -52 6: [CHG] Device F6:9F:77:XX:XX:XX ManufacturerData Key: 0x0200 7: CTRL + C
List all the discovered devices using bluetoothctl devices
command:
1: # bluetoothctl devices 2: Device 06:99:13:XX:XX:XX ARTIS BT99 3: Device D8:55:A3:XX:XX:XX shuttle 4: Device F6:9F:77:XX:XX:XX GOQii S 5: Device 8C:2D:AA:XX:XX:XX GSS’s Mac Pro
Pair the device using bluetoothctl pair
command:
1: # bluetoothctl pair 06:99:13:XX:XX:XX 2: Attempting to pair with 06:99:13:XX:XX:XX 3: [CHG] Device 06:99:13:XX:XX:XX Connected: yes 4: [CHG] Device 06:99:13:XX:XX:XX UUIDs: 0000110b-0000-1000-8000-00805f9b34fb 5: [CHG] Device 06:99:13:XX:XX:XX UUIDs: 0000110e-0000-1000-8000-00805f9b34fb 6: [CHG] Device 06:99:13:XX:XX:XX ServicesResolved: yes 7: [CHG] Device 06:99:13:XX:XX:XX Paired: yes 8: Pairing successful
Trust the device:
1: # bluetoothctl trust 06:99:13:XX:XX:XX 2: [CHG] Device 06:99:13:XX:XX:XX Trusted: yes 3: Changing 06:99:13:XX:XX:XX trust succeeded
To display device information use bluetoothctl info
command:
1: # bluetoothctl info 06:99:13:XX:XX:XX 2: Device 06:99:13:XX:XX:XX (public) 3: Name: ARTIS BT99 4: Alias: ARTIS BT99 5: Class: 0x00240404 6: Icon: audio-card 7: Paired: no 8: Trusted: no 9: Blocked: no 10: Connected: no 11: LegacyPairing: no 12: UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) 13: UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) 14: RSSI: -64
The device is not connected which indicated by Connected: no
parameter. To
connect the device, use the MAC address as an argument to bluetoothctl
connect
command:
1: # bluetoothctl connect 06:99:13:XX:XX:XX 2: Attempting to connect to 06:99:13:XX:XX:XX 3: [CHG] Device 06:99:13:XX:XX:XX Connected: yes 4: [CHG] Device 06:99:13:XX:XX:XX Paired: yes 5: Connection successful
1: # bluetoothctl info 06:99:13:XX:XX:XX 2: Device 06:99:13:XX:XX:XX (public) 3: Name: ARTIS BT99 4: Alias: ARTIS BT99 5: Class: 0x00240404 6: Icon: audio-card 7: Paired: yes 8: Trusted: yes 9: Blocked: no 10: Connected: yes 11: LegacyPairing: no 12: UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) 13: UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
Finally use the Gnome Sound Settings to use the Bluetooth device as sound output:
Figure 1: Gnome Sound Settings
The Bluetooth Sound device is now ready to play the media.