Skip to content

Instantly share code, notes, and snippets.

@xcession
Last active October 23, 2020 12:14
Show Gist options
  • Save xcession/5da7557231f0a0dc98651ea16cb89ede to your computer and use it in GitHub Desktop.
Save xcession/5da7557231f0a0dc98651ea16cb89ede to your computer and use it in GitHub Desktop.
[Arch Linux - Bluetooth] Setting up Bluetooth in Arch Linux #archlinux #bluetooth

Installation

  • Install the bluez package:
$ sudo pacman -S bluez
  • Install the bluez-utils package:
$ sudo pacman -S bluez-utils
  • Enable/start the bluetooth.service:
$ systemctl enable bluetooth.service
$ systemctl start bluetooth.service

Bluetooth Headset

  • Start the bluetoothctl command line utility:
$ bluetoothctl
  • Then enter:
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# scan on
  • Turn on the headset and make sure it is in paring mode. It should be discoverd shortly.
[NEW] Device 00:1D:43:6D:03:26 Lasmex LBT10

shows a device that calls itself Lasmex LBT10 and has MAC address 00:1D:43:6D:03:26.

  • Initiate the paring:
[bluetooth]# pair 00:1D:43:6D:03:26
  • After paring, connect the device:
[bluetooth]# connect 00:1D:43:6D:03:26

Finally, to automatically connect to this device in the future:

[bluetooth]# trust 00:1D:43:6D:03:26
  • You can now disable scanning and exit the program:
[bluetooth]# scan off
[bluetooth]# exit

Setting up auto connection

To make the headset auto connect you need to enable PulseAudio's switch-on-connect module. By add the following lines to /etc/pulse/default.pa:

# automatically switch to newly-connected devices
load-module module-switch-on-connect

Now make bluetoothctl trust your Bluetooth headset by running trust 00:1D:43:6D:03:26 inside the bluetoothctl console to prevent errors similar to:

bluetoothd[487]: Authentication attempt without agent
bluetoothd[487]: Access denied: org.bluez.Error.Rejected

By default, your Bluetooth adapter will not power on after a reboot. To power on the Bluetooth adapter after reboot, add the line AutoEnable=true in /etc/bluetooth/main.conf at the bottom in the [Policy] section:

[Policy]
AutoEnable=true

Media Control

To use the media controls they may be forwarded to MPRIS2, where they can be picked up by media players that support mpris for external control. Install bluez-utils and run:

$ mpris-proxy

In order to start up mpris-proxy in the background and/or when your system starts, you may create a systemd user script:

[Unit]
Description=Forward bluetooth midi controls via mpris2 so they are picked up by supporting media players

[Service]
Type=simple
ExecStart=/usr/bin/mpris-proxy

[Install]
WantedBy=default.target

Then start it:

$ systemctl --user start mpris-proxy

and enable it to start at login:

$ systemcrl --user enable mpris-proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment