Bluetooth on Linux

Quick notes on using bluetooth over command line.

Setting up the basics

Install CLI utils: pacman -S bluez bluez-utils.

Enable bluetooth service: systemctl enable bluetooth.service / systemctl start bluetooth.service.

Turn the power of the bluetooth device on with

bluetoothctl power on

Then pair the device (using device id that shows with bluetoothctl devices). Then you still need to connect to a paired device, that doesn't happen automatically.

Playing music over bluetooth

After I paired and connected with a JBL bluetooth box, I still had to manually change the audio output. I used pavucontrol for that, but still need to learn how to do that over command line.

alsamixer is not recommended and too basic.

Pulseaudio

Use pulseaudio.

The config is in /etc/pulse/default.pa. There you can set default behavior for example:

load-module module-switch-on-connect
load-module switch-on-port-available

These are not enabled by default.

There's also behavior for what to do when a bluetooth device connects.

### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

This perhaps did load drivers (not sure if the if statement passed), but in any case this did not yet autoswitch to the bluetooth output. If I want that, I could set the autoswitch option from above.

Command line interaction with pulseaudio can be down with pacmd.

The pulseaudio command itself is just for running the audio deamon.

There's also pacmd list-sinks. That should show your output devices.

I think the best way to change output sinks is to change the default sink. You can use the name or the index under pacman list-sinks.

pacmd set-default-sink 1

After having set the default device to this one, the audio actually switched to bluetooth automaitcally after connecting with bluetoothctl

Also pactl list, which seems to do the very same thing... It seems slightly less complicated though, so my first preference is to use patcl. You can list sinks (or modules etc) simply with pactl list sinks.

Just get the names: pactl list sinks | grep "Name".

When I run it now, I indeed see that a device connected to bluetooth is running.

Also see managing sound on arch linux.

Dualshock 4 controller

bluetoothctl
power on
agent on
default-agent on
discoverable on
pairable on

Hold Share + PS button for pairing mode.

scan on
# look up MAC adress
pair [MAC adress]
trust [MAC adress]
connect [MAC adress]
quit