The project github.com/Arkq/bluez-alsa brings this feature.
I’ve tried to take notes of the steps to make it work (thanks to Arkq and their help).
With volumio-2.118-2017-03-07-pi and on Raspberry PI3 + Hifiberry DacPlus.
Any comment to improve the process is welcome.
- Dependencies
sudo apt-get update
sudo apt-get install libasound2-dev
sudo apt-get install dh-autoreconf
sudo apt-get install libortp-dev
sudo apt-get install bluez pi-bluetooth bluez-tools libbluetooth-dev
sudo apt-get install libusb-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
sudo apt-get install libsbc1 libsbc-dev
2. Bluez-Alsa
sudo git clone https://github.com/Arkq/bluez-alsa.git
cd bluez-alsa
sudo autoreconf --install
sudo mkdir build && cd build
sudo ../configure --disable-hcitop --with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib
sudo make && sudo make install
3. Bluetooth
Create file /etc/bluetooth/audio.conf
[General]
Class = 0x20041C
Enable = Source,Sink,Media,Socket
Update file /etc/bluetooth/main.conf
[General]
Class = 0x20041C
4. Automation
Set BlueAlsa as a service
Create file /lib/systemd/system/bluealsa.service
[Unit]
Description=BluezAlsa proxy
Requires=bluetooth.service
After=bluetooth.service
[Service]
Type=simple
User=volumio
Group=audio
ExecStart=/usr/bin/bluealsa
[Install]
WantedBy=multi-user.target
And make it start at boot time
sudo systemctl daemon-reload
sudo systemctl enable bluealsa.service
Set bluealsa-aplay as a service
Create file /lib/systemd/system/bluealsa-aplay@.service
hw1:0 is the hifiberry audio device I want to use. There may be better way to link it.
[Unit]
Description=BlueAlsa-Aplay %I -dhw:1,0
Requires=bluetooth.service bluealsa.service
[Service]
Type=simple
User=volumio
Group=audio
ExecStart=/usr/bin/bluealsa-aplay %I -dhw:1,0
[Install]
WantedBy=multi-user.target
Bluetooth connection & disconnection detection
Create file /etc/udev/rules.d/99-input.rules
KERNEL=="input[0-9]*", RUN+="/home/volumio/a2dp-autoconnect"
And the corresponding script.
Create file /home/volumio/a2dp-autoconnect:
[code]#!/bin/bash
at each BT connection/disconnection start/stop the service bluealsa-aplay
function log {
sudo echo “[$(date)]: $*” >> /var/log/a2dp-autoconnect
}
BTMAC=${NAME//"/}
if [ $ACTION = “remove” ]
then
log "Stop Played Connection " $BTMAC
sudo systemctl stop bluealsa-aplay@$BTMAC
elif [ $ACTION = “add” ]
then
log "Start Played Connection " $BTMAC
sudo systemctl start bluealsa-aplay@$BTMAC
else
log "Other action " $ACTION
fi[/code]
Create also the log file (not sure but that’s the way I’ve made it work) /var/log/a2dp-autoconnect
And made them accessible:
sudo chmod a+rwx /home/volumio/a2dp-autoconnect
sudo chmod a+rw /var/log/a2dp-autoconnect
Reboot
- Start
using bluetoothctl
power on
agent on
default-agent
scan on => xx:xx of your device
pair xx:xx
trust xx:xx
exit
On your mobile, connect volumio. Should work.
Once the device is connected you should be able to play something …
6.Checking
To check if the services are all up and running: $ systemctl | grep blue
You should get something like that:
sys-subsystem-bluetooth-devices-hci0.device loaded active plugged /sys/subsystem/bluetooth/devices/hci0
sys-subsystem-bluetooth-devices-hci0:11.device loaded active plugged /sys/subsystem/bluetooth/devices/hci0:11
bluealsa-aplay@68:FB:7E:24:25:52.service loaded active running BlueAlsa-Aplay 68:FB:7E:24:25:52 -dhw:1,0
bluealsa.service loaded active running BluezAlsa proxy
bluetooth.service loaded active running Bluetooth service
system-bluealsa\x2daplay.slice loaded active active system-bluealsa\x2daplay.slice
bluetooth.target loaded active active Bluetooth
You can also check the bluetooth connection works in the log file /var/log/a2dp-autoconnect
You should get something like:
[Sun Mar 12 20:49:39 UTC 2017]: Stop Played Connection 68:FB:7E:24:25:52
[Sun Mar 12 20:49:50 UTC 2017]: Start Played Connection 68:FB:7E:24:25:52
[Sun Mar 12 20:55:34 UTC 2017]: Stop Played Connection 68:FB:7E:24:25:52
[Sun Mar 12 20:55:40 UTC 2017]: Start Played Connection 68:FB:7E:24:25:52