md
Bluetooth, BlueALSA and Buster
Last Update: November 12, 2019. First version: July 2, 2019
<-A Note on BlueAlsa 0.9 with BlueZ 5.49 and 5.50 on Rasbian Stretch --
<-A Note on BlueAlsa 0.9 with BlueZ 5.43 on Rasbian Stretch

With the new version of Raspbian, Buster, available since June 20, 2019, I decided to look into what that means for Bluetooth on the Raspberry Pi. The short answer is that not much has changed for the Buster Lite: some tweaking still needs to be done to use Bluetooth. For Buster Desktop (either version), Bluetooth should work without a problem. Below is a list of the preliminary steps required to both send an audio stream from the Raspberry Pi to a Bluetooth speaker and to play an audio stream from a Bluetooth device such as a tablet through an audio device connect to the Raspberry Pi. BlueALSA, the Bluetooth Audio ALSA Backend is used as a bridge. If you would rather use PulseAudio, you will have to look elsewhere for information.

The "investigation" was done with a Raspberry Pi 3 Model B run as a headless server with a freshly installed OS:

  Raspbian Buster Lite
  Minimal image based on Debian Buster
  Version:         June 2019
  Release date:    2019-06-20
  Kernel version:  4.19
  Size:            426 MB

This post remains valid for the newest version currently available (as of Nov 12, 2019).

  Raspbian Buster Lite
  Minimal image based on Debian Buster
  Version:         September 2019
  Release date:    2019-09-06
  Kernel version:  4.19
  Size:            435 MB

First, let's look at the state of things when booting the Raspberry Pi after doing an update and upgrade.

pi@raspberrypi:~ $ sudo apt update && sudo apt upgrade -y ... pi@raspberrypi:~ $ sudo reboot Connection to raspberrypi.local closed by remote host. Connection to raspberrypi.local closed. ... michel@hp:~$ ssh pi@raspberrypi.local Opening an ssh session from the destktop computer ... pi@raspberrypi:~ $ sudo systemctl status blue* ● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-07-02 17:41:37 ADT; 20min ago Docs: man:bluetoothd(8) Main PID: 505 (bluetoothd) Status: "Running" Tasks: 1 (limit: 2319) Memory: 2.7M CGroup: /system.slice/bluetooth.service └─505 /usr/lib/bluetooth/bluetoothd Jul 02 17:41:37 raspberrypi systemd[1]: Starting Bluetooth service... Jul 02 17:41:37 raspberrypi bluetoothd[505]: Bluetooth daemon 5.50 Jul 02 17:41:37 raspberrypi systemd[1]: Started Bluetooth service. Jul 02 17:41:37 raspberrypi bluetoothd[505]: Starting SDP server Jul 02 17:41:37 raspberrypi bluetoothd[505]: Bluetooth management interface 1.14 initialized Jul 02 17:41:37 raspberrypi bluetoothd[505]: Sap driver initialization failed. Jul 02 17:41:37 raspberrypi bluetoothd[505]: sap-server: Operation not permitted (1) Jul 02 17:41:37 raspberrypi bluetoothd[505]: Failed to set privacy: Rejected (0x0b) ● bluetooth.target - Bluetooth Loaded: loaded (/lib/systemd/system/bluetooth.target; static; vendor preset: enabled) Active: active since Tue 2019-07-02 17:41:37 ADT; 20min ago Docs: man:systemd.special(7) Jul 02 17:41:37 raspberrypi systemd[1]: Reached target Bluetooth. pi@raspberrypi:~ $ groups pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

The good news is that Raspbian Buster contains version 5.50 of the Official Linux Bluetooth protocol stack BlueZ which is the most recent available. But, the unit file has not been modified so that a failed attempt at loading the nonexistent SIM access profile (sap) is still being made. The default user (pi in this case) is still not a member of the bluetooth group and blueALSA is not installed.

These are all problems that were encountered before. I will not go into the details but here are steps to take to be able to both "source" and "sink" sound streams over Bluetooth on a Raspberry Pi running the latest version of Rasbpian.

  1. Install the blueALSA proxy.
    pi@raspberrypi:~ $ sudo apt install bluealsa Reading package lists... Done ... bluealsa.service is a disabled or a static unit, not starting it. Processing triggers for libc-bin (2.28-10+rpi1) ...
  2. Adding the ability to play an audio stream from a Bluetooth device out to a sound interface on the Raspberry Pi. If all that is required is to send an audio stream from the Rasberry Pi to a Bluetooth device such as a speaker, then this step is not necessary, but it is not harmful either.
    pi@raspberrypi:~ $ sudo nano /lib/systemd/system/bluealsa.service
    [Unit] Description=BluezALSA proxy Requires=bluetooth.service After=bluetooth.service [Service] Type=simple User=root ExecStart=/usr/bin/bluealsa -p a2dp-source -p a2dp-sink
  3. Add pi to the bluetooth group.
    pi@raspberrypi:~ $ sudo adduser pi bluetooth Adding user `pi' to group `bluetooth' ... Adding user pi to group bluetooth Done.

    I have received some emails suggesting that I had forgotten to include the sudo prefix when invoking bluetoothctl in my previous posts on using bluetoothctl in Stretch. As in Buster it was necessary to add the user to the bluetooth group in Stretch. However it was also necessary to edit the bluetooth configuration file /etc/dbus-1/system.d/bluetooth.conf as explained in the section entitled Updating BlueZ of my note entitled Bluetooth Audio with Rasbian Stretch on the Raspberry Pi 3. This is not the case with Buster.

  4. Edit the bluetooth unit file to stop loading the SIM profile.
    pi@raspberrypi:~ $ sudo nano /lib/systemd/system/bluetooth.service
    [Unit] Description=Bluetooth service Documentation=man:bluetoothd(8) ConditionPathIsDirectory=/sys/class/bluetooth [Service] Type=dbus BusName=org.bluez ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap NotifyAccess=main #WatchdogSec=10 #Restart=on-failure CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE LimitNPROC=1 ProtectHome=true ProtectSystem=full [Install] WantedBy=bluetooth.target Alias=dbus-org.bluez.service

    This will get rid of the sap related error messages, but it is not mandatory. Everything will work without changing the unit file.

Reboot and check that everything works.

pi@raspberrypi:~ $ sudo reboot Connection to raspberrypi.local closed by remote host. Connection to raspberrypi.local closed. ... michel@hp:~$ ssh pi@raspberrypi.local Opening an ssh session from the destktop computer ... pi@raspberrypi:~ $ sudo systemctl status blue* ● bluealsa.service - BluezALSA proxy Loaded: loaded (/lib/systemd/system/bluealsa.service; static; vendor preset: enabled) Active: active (running) since Tue 2019-07-02 19:00:00 ADT; 48s ago Main PID: 438 (bluealsa) Tasks: 4 (limit: 2319) Memory: 2.6M CGroup: /system.slice/bluealsa.service └─438 /usr/bin/bluealsa -p a2dp-source -p a2dp-sink Jul 02 19:00:00 raspberrypi systemd[1]: Started BluezALSA proxy. ● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-07-02 19:00:00 ADT; 48s ago Docs: man:bluetoothd(8) Main PID: 437 (bluetoothd) Status: "Running" Tasks: 1 (limit: 2319) Memory: 2.9M CGroup: /system.slice/bluetooth.service └─437 /usr/lib/bluetooth/bluetoothd --noplugin=sap Jul 02 19:00:00 raspberrypi systemd[1]: Starting Bluetooth service... Jul 02 19:00:00 raspberrypi bluetoothd[437]: Bluetooth daemon 5.50 Jul 02 19:00:00 raspberrypi systemd[1]: Started Bluetooth service. Jul 02 19:00:00 raspberrypi bluetoothd[437]: Starting SDP server Jul 02 19:00:00 raspberrypi bluetoothd[437]: Excluding (cli) sap Jul 02 19:00:00 raspberrypi bluetoothd[437]: Bluetooth management interface 1.14 initialized Jul 02 19:00:00 raspberrypi bluetoothd[437]: Endpoint registered: sender=:1.6 path=/A2DP/SBC/Source/1 Jul 02 19:00:00 raspberrypi bluetoothd[437]: Endpoint registered: sender=:1.6 path=/A2DP/SBC/Sink/1 Jul 02 19:00:00 raspberrypi bluetoothd[437]: Failed to set privacy: Rejected (0x0b) ● bluetooth.target - Bluetooth Loaded: loaded (/lib/systemd/system/bluetooth.target; static; vendor preset: enabled) Active: active since Tue 2019-07-02 19:00:00 ADT; 48s ago Docs: man:systemd.special(7) Jul 02 19:00:00 raspberrypi systemd[1]: Reached target Bluetooth. pi@raspberrypi:~ $ sudo systemctl restart bluetooth.service pi@raspberrypi:~ $ sudo systemctl status bluetooth.service ● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-07-02 19:01:31 ADT; 8s ago Docs: man:bluetoothd(8) Main PID: 659 (bluetoothd) Status: "Running" Tasks: 1 (limit: 2319) Memory: 588.0K CGroup: /system.slice/bluetooth.service └─659 /usr/lib/bluetooth/bluetoothd --noplugin=sap Jul 02 19:01:30 raspberrypi systemd[1]: Starting Bluetooth service... Jul 02 19:01:31 raspberrypi bluetoothd[659]: Bluetooth daemon 5.50 Jul 02 19:01:31 raspberrypi systemd[1]: Started Bluetooth service. Jul 02 19:01:31 raspberrypi bluetoothd[659]: Starting SDP server Jul 02 19:01:31 raspberrypi bluetoothd[659]: Excluding (cli) sap Jul 02 19:01:31 raspberrypi bluetoothd[659]: Bluetooth management interface 1.14 initialized Jul 02 19:01:31 raspberrypi bluetoothd[659]: Endpoint registered: sender=:1.15 path=/A2DP/SBC/Source/1 Jul 02 19:01:31 raspberrypi bluetoothd[659]: Endpoint registered: sender=:1.15 path=/A2DP/SBC/Sink/1

I checked and the following worked.

I will not cover the details of these operations which were the subject of previous posts.

Baby Bluetooth Steps on Raspberry Pi 3 - Raspbian (Stretch)
Setting up blueALSA, basic explanation of bluetoothctl to pair and connect Bluetooth devices, using ALSA utilities to play sound to Bluetooth speakers and control the volume. (May 14, 2018 original publication December 14, 2018)
Bluetooth Audio with Rasbian Stretch on the Raspberry Pi 3
As above but installing a newer version of BlueEz. Added section on receiving sound from a Bluetooth enabled device such as an Android tablet. (May 13, 2018 original publication January 29, 2018)

The sharp-eyed reader will have spotted the remaining error, Failed to set privacy: Rejected (0x0b), when the bluetooth service is started. A simple restart of the service solves the problem.

pi@raspberrypi:~ $ sudo systemctl restart bluetooth.service pi@raspberrypi:~ $ sudo systemctl status bluetooth.service ● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-07-03 16:36:33 ADT; 7s ago Docs: man:bluetoothd(8) Main PID: 722 (bluetoothd) Status: "Running" Tasks: 1 (limit: 2319) Memory: 648.0K CGroup: /system.slice/bluetooth.service └─722 /usr/lib/bluetooth/bluetoothd --noplugin=sap Jul 03 16:36:33 raspberrypi systemd[1]: Starting Bluetooth service... Jul 03 16:36:33 raspberrypi bluetoothd[722]: Bluetooth daemon 5.50 Jul 03 16:36:33 raspberrypi systemd[1]: Started Bluetooth service. Jul 03 16:36:33 raspberrypi bluetoothd[722]: Starting SDP server Jul 03 16:36:33 raspberrypi bluetoothd[722]: Excluding (cli) sap Jul 03 16:36:33 raspberrypi bluetoothd[722]: Bluetooth management interface 1.14 initialized Jul 03 16:36:33 raspberrypi bluetoothd[722]: Endpoint registered: sender=:1.15 path=/A2DP/SBC/Source/1 Jul 03 16:36:33 raspberrypi bluetoothd[722]: Endpoint registered: sender=:1.15 path=/A2DP/SBC/Sink/1

In a previous post I suggested a "brute force solution" based on that obvservation.

pi@rasberrypi:~ $ crontab -e
... #For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command @reboot sleep 5 && sudo systemctl restart bluetooth.service

Ben Windsor proposed an alternate solution which is a one line addition to the bthelper unit file.

pi@raspberrypi:~ $ sudo nano /lib/systemd/system/bthelper@.service
[Unit] Description=Raspberry Pi bluetooth helper Requires=bluetooth.service After=bluetooth.service [Service] Type=simple ExecStartPre=/bin/sleep 2 ExecStart=/usr/bin/bthelper %I

I suggest reading the explanation by the author. Obviously, he has a much better grasp of what is going on than I do. As with the sap related error message, this one could also be ignored and everything will work. In other words, all the error messages displayed when the bluetooth service is started can be ignored in Buster as they could in Stretch.

<-A Note on BlueAlsa 0.9 with BlueZ 5.49 and 5.50 on Rasbian Stretch --
<-A Note on BlueAlsa 0.9 with BlueZ 5.43 on Rasbian Stretch