This was very helpful. I had ALSA set up on the Raspberry Pi 3B+ with a HiFiBerry AMP+ card connected to some speakers. I wanted to use the speakers as a bluetooth audio sink.
I had to add these lines to /etc/rc.local at startup to turn on bluetooth discoverability and enable pairing:
/bin/hciconfig hci0 piscan &
/bin/hciconfig hci0 sspmode 1 &
sspmode 1 is pairing with no passcode. Infuriatingly I can't get the passcode auth (mode 0) to work with a pin.conf on the bt-agent command line, every time I pair and enter the passcode on the android phone, I have to also start bluetoothctl and enter the same passcode at the bash prompt. This is super stupid since I want the use of this as a smart speaker to NOT require interacting with the linux command line.
I found that bluealsa sometimes won't start on the first try, so I added these lines to the service section of the aplay.service file as created above:
Code: Select all
[Service]
ExecStart=/usr/bin/bluealsa-aplay -v 00:00:00:00:00:00
Restart=on-failure
Restart=always
RestartSec=30
This makes it always restart if the bluealsa-aplay dies for any reason.
I also have the following /etc/systemd/system/bt-agent.service file:
Code: Select all
$ cat bt-agent.service
[Unit]
Description=Bluetooth Auth Agent
After=bluetooth.service
PartOf=bluetooth.service
[Service]
Type=simple
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
ExecStartPost=/bin/sleep 1
ExecStartPost=/bin/hciconfig hci0 piscan
ExecStartPost=/bin/hciconfig hci0 sspmode 1
[Install]
WantedBy=bluetooth.target
I also ran these commands to start them and make sure they start at boot:
Code: Select all
sudo systemctl enable bt-agent
sudo systemctl enable bluealsa-aplay
sudo systemctl start bt-agent
sudo systemctl start bluealsa-aplay
Changing the audio output volume using the volume keys on the phone DOES NOT WORK. There seems to be no way to set the volume. I checked bluetooth events by watching the output of "sudo dbus-monitor --system" and I see all the pairing, connect, playback start/stop events, but no events when I press the volume up/down. If there was any event I could listen on, I can change the volume 1+ and 1- using a command like this: "amixer sset 'Master' 1+" But so far there seems to be no way to make this happen when I press volume keys on the Android phone while playing media.
I wonder if this patch to bluealsa-aplay will eventually work if it gets merged in and shows up in the raspbian build:
https://github.com/hmbedded/bluez-alsa/ ... 78ebc4c76a