Skip to content

Instantly share code, notes, and snippets.

@jadonk
Last active April 2, 2020 23:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/d05d96243bc26b3c08a5293d29f78839 to your computer and use it in GitHub Desktop.
Save jadonk/d05d96243bc26b3c08a5293d29f78839 to your computer and use it in GitHub Desktop.
Setup a Bluetooth speaker on BeagleBone Blue

You'll need to discover the Bluetooth ID of your speaker. In my case, it was 0A:EC:12:01:02:A9. Adjust the scripts below accordingly.

Initial setup:

apt-get update
apt-get install -y pulseaudio pulseaudio-module-bluetooth
gpasswd -a root pulse-access

Startup 'bluetoothctl' while the speaker is in discovery mode and do:

scan on
agent on
default-agent
pair 0A:EC:12:01:02:A9
connect 0A:EC:12:01:02:A9
trust 0A:EC:12:01:02:A9

Replace the last line in /etc/dbus-1/system.conf with:

   <policy user="root">
            <allow own="org.pulseaudio.Server"/>
            <allow send_destination="org.bluez"/>
            <allow send_interface="org.bluez.Manager"/>
    </policy>
    <policy user="pulse">
            <allow own="org.pulseaudio.Server"/>
            <allow send_destination="org.bluez"/>
            <allow send_interface="org.bluez.Manager"/>
    </policy>
    <policy context="default">
            <deny own="org.pulseaudio.Server"/>
            <deny send_destination="org.bluez"/>
            <deny send_interface="org.bluez.Manager"/>
    </policy>
</busconfig>

Then reboot.

After each boot:

# Load the PulseAudio audio manager and load Bluetooth modules
LANG=C pulseaudio -vvvv --log-time=1 -D --system --disallow-exit --disable-shm
pactl load-module module-bluetooth-policy
pactl load-module module-bluetooth-discover
# Trigger the Bluetooth connection
echo connect 0A:EC:12:01:02:A9 | bluetoothctl
# Set the Bluetooth speaker to be the default output
pactl set-default-sink bluez_sink.0A_EC_12_01_02_A9
# Play a sound
aplay /usr/share/sounds/alsa/Front_Center.wav    
@nagen1
Copy link

nagen1 commented Feb 23, 2018

When I tried $connect [device MAC] the below error showed up.
Attempting to connect to 08:EC:ED:34:9A:5B
Failed to connect: org.bluez.Error.Failed

To resolve this problem try below as additional step and it should work (I tried this on BeagleBone Blue Ubuntu OS)
https://unix.stackexchange.com/questions/258074/error-when-trying-to-connect-to-bluetooth-speaker-org-bluez-error-failed

This may be due to the pulseaudio-module-bluetooth package not being installed. Install it if it missing, then restart pulseaudio.

$sudo apt install pulseaudio-module-bluetooth
pulseaudio -k (in my case this showed up as > E: [pulseaudio] main.c: Failed to kill daemon: No such process )
pulseaudio --start (then I started)
If the issue is not due to the missing package, the problem in this case is that PulseAudio is not catching up. A common solution to this problem is to restart PulseAudio. Note that it is perfectly fine to run bluetoothctl as root while PulseAudio runs as user. After restarting PulseAudio, retry to connect. It is not necessary to repeat the pairing.

Bluetooth connects successfully.

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