Connecting_Bluetooth_device_to_Phoniebox - MiczFlor/RPi-Jukebox-RFID GitHub Wiki

Connecting Bluetooth device to Phoniebox

Taken from the Phoniebox@GitHub issues forum

Connecting your Raspberry Pi Phoniebox to Bluetooth speakers or headsets:

  • Have a finished Phoniebox running (this howto was tested on the Phoniebox Classic meaning: no Spotify, version 1.1.7)
    • Tested on Raspberry Pi Zero W
    • Raspbian Image "2018-10-09-raspbian-stretch-lite"
    • Phoniebox 1.1.7 Classic - without Spotify

Make an update and install the required software:

[!NOTE] The package bluealsa isn't available anymore since bullseye and there is currently no replacement (see Unofficial workaround for Bullseye). For bookworm you can use bluez-alsa-utils instead.

sudo apt update && sudo apt upgrade
sudo apt install bluealsa
sudo reboot

The reboot is necessary!

Switch on your Bluetooth speakers / gadgets. Then:

sudo bluetoothctl

And type in the following commands in this order:

power on
agent on
scan on

Now the Phoniebox is looking for nearby Bluetooth equipment, which looked like this in my case:

pi@phoniebox:~ $ sudo bluetoothctl
[NEW] Controller B8:27:EB:26:53:17 phoniebox [default]
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:26:53:17 Discovering: yes
[NEW] Device FC:58:FA:DD:AA:D2 MD 43438

Note down the Mac address of your hardware, we need it later. In my case: [NEW] Device FC:58:FA:DD:AA:D2 MD 43438

Now the pairing happens. This is what I did, you need to replace the MAC address with the one from your hardware: pair FC:58:FA:DD:AA:D2

trust the hardware trust FC:58:FA:DD:AA:D2

connect to the hardware connect FC:58:FA:DD:AA:D2

Stop the discovery mode scan off exit

Create a new file sudo nano /etc/asound.conf

This is the content of the new file (in my case, again use your MAC address). I called my device here pcm.btspeaker. You can change that name to e.g. pcm.sonosspeaker`

pcm.btspeaker {
    type plug
    slave.pcm {
        type bluealsa
        service "org.bluealsa"
        device "FC:58:FA:DD:AA:D2"
        profile "a2dp"
        delay -20000
    }
    hint {
        show on
        description "Medion Partybox"
    }
}

Try if it works. If you used a different name than pcm.btspeaker you need to change it in the following command: aplay -D btspeaker /usr/share/sounds/alsa/Front_Center.wav

Almost done, you need to edit the mpd.conf file: sudo nano /etc/mpd.conf

Look for audio_output and edit some lines. In my case to this:

        type            "alsa"
        name            "My ALSA Device"
        device          "btspeaker"    # see https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/284#issuecomment-443497319
        mixer_type      "software"      # optional

Done and good luck! Questions, suggestion, etc in the thread linked at the top of this document.

Unofficial workaround for bullseye

see #2480 for original post

This is an unofficial workaround for the missing bluealsa and bluez-alsa-utils package on bullseye. Following this instruction is at own risk and may have unknown side effects.

  • add a new apt source list with the bookworm repo
echo "deb http://raspbian.raspberrypi.org/raspbian bookworm main" | sudo tee /etc/apt/sources.list.d/bookworm-bluetooth.list
  • update and install bluez-alsa-utils from the bookworm repo (accept all prompts)
sudo apt update
sudo apt install bluez-alsa-utils
  • remove the list again, to not interfere on future installations
sudo rm /etc/apt/sources.list.d/bookworm-bluetooth.list
sudo apt update
  • reboot and follow the description from top