Volumio + Bluez-Alsa (a2dp bluetooth support)

Discuss about Hardware diy and tweaks

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.

Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby phweyland » Sun Mar 12 2017 22:05

The project https://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.

1. Dependencies
Code: Select all
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
Code: Select all
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
Code: Select all
[General]
Class = 0x20041C
Enable = Source,Sink,Media,Socket

Update file /etc/bluetooth/main.conf
Code: Select all
[General]
Class = 0x20041C

4. Automation
Set BlueAlsa as a service
Create file /lib/systemd/system/bluealsa.service
Code: Select all
[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
Code: Select all
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.
Code: Select all
[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
Code: Select all
KERNEL=="input[0-9]*", RUN+="/home/volumio/a2dp-autoconnect"

And the corresponding script.
Create file /home/volumio/a2dp-autoconnect:
Code: Select all
#!/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

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:
Code: Select all
sudo chmod a+rwx /home/volumio/a2dp-autoconnect
sudo chmod a+rw /var/log/a2dp-autoconnect

Reboot

5. 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:
Code: Select all
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:
Code: Select all
[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
Random avatar
phweyland
Sunday DIYer
Sunday DIYer
 
Posts: 12
Joined: Mon Feb 13 2017 20:37

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby valentinmumble » Mon Mar 13 2017 19:19

Working great!
Random avatar
valentinmumble
Fresh off the boat
Fresh off the boat
 
Posts: 3
Joined: Thu Jan 19 2017 10:11


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby george-ou812 » Tue Mar 14 2017 14:01

Great work, I'm currently using blue-alsa, bluez5 etc and works well on my ARM platform. However as blue-alsa appears to be more of a pcm input that needs a specific client's mac, I have to change the mac with each mobile / tablet that I which to play music from. A real hassle as it's supposed to be a BT speaker!
I noticed you have a daemon that fires up bluealsa-aplay + mac, under the section Automation ( And the corresponding script. Create file /home/volumio/a2dp-autoconnect: ) Am I correct in assuming that via this you are passing the phone's / tablet's mac and connecting via that mac automatically, e.g once BT connection established? If so, brilliant! The pairing and trusting I've already done using a modified simple-agent instead of bluetoothctl. Using your posted information regarding the automation, will it seamlessly pick up a different mac each time ( if pre-paired and trusted ) and play?

Cheers.
Random avatar
george-ou812
Fresh off the boat
Fresh off the boat
 
Posts: 4
Joined: Tue Mar 14 2017 13:44


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby phweyland » Tue Mar 14 2017 16:13

Using your posted information regarding the automation, will it seamlessly pick up a different mac each time ( if pre-paired and trusted ) and play?

Yes, you are right. Once paired and trusted, any device connects and plays (one at a time).
I've tried to skip the pairing and trusting step but so far I've not found the way (in particular to set up a predefined key to allow an automatic pairing).
Random avatar
phweyland
Sunday DIYer
Sunday DIYer
 
Posts: 12
Joined: Mon Feb 13 2017 20:37


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby george-ou812 » Wed Mar 15 2017 14:29

Yea the automatic pairing trusting bit was tricky, I use a slightly modified bluez5 simple-agent set-up that runs in the background so any phone/table can come along, connect, put in the pin and play music. Next time around they connect and play ( no intervention speaker side ). Fortunately this paring stuff still works with bluealsa as it bolts up to bluez anyway. My only issue is now introducing one of these pre-paired / trusted macs to bluealsa-aplay at rum time. My ARM's not playing ball with the "udev input[0-9]" bit, any pointers how udev sees the BT/HCI signals or whatever triggers it?
Random avatar
george-ou812
Fresh off the boat
Fresh off the boat
 
Posts: 4
Joined: Tue Mar 14 2017 13:44


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby phweyland » Wed Mar 15 2017 19:57

any pointers how udev sees the BT/HCI signals or whatever triggers it?

This part comes from here : https://gist.github.com/oleq/24e09112b07464acbda1
But I've not been very far about the understanding of udev itself...
In my case I'm using the on board BT. An USB BT may behave a bit differently.

Could you share or quickly explain how you have set the simple-agent with pin with bluez5 ?
Random avatar
phweyland
Sunday DIYer
Sunday DIYer
 
Posts: 12
Joined: Mon Feb 13 2017 20:37


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby george-ou812 » Wed Mar 15 2017 22:27

A lot of bluez5 references use bluetoothctl for manual connection its ok but useless in practical use because you want to point your phone at your hardware and just play. Here's a list of what I start, my boards a Freescale imx running 4.1.35 kernel, you may have to do a few tweaks...

start bluetoothd // if not already

hciconfig hci0 up // bring up your hcix BT device, same if USB-BT or build in BCMxxx - I use both
hciconfig hci0 reset
hciconfig hci0 piscan // this and below imitate bluetoothctl in the way of discovery , pin etc
hciconfig hci0 leadv
hciconfig hci0 sspmode 0
bluealsa ( or pulseaudio -D ) // from https://github.com/Arkq/bluez-alsa - cross-compiled to suit...
simple-agent-pin -c NoInputNoOutput & // this still comes with the current bluez, mines modified a little for pin.

Try with just simple-agent // no pin first. You may need to comment out the pin line => hciconfig hci0 sspmode 0

At this stage you should be able to auto pair and trust.

bluez5 simple-agent mods:

PAIRING_CAPABILITIES = "NoInputNoOutput"
PIN_CODE = "0000"
.......
@dbus.service.method(AGENT_INTERFACE, in_signature="os", out_signature="")
def AuthorizeService(self, device, uuid):
print("AuthorizeService (%s, %s)" % (device, uuid))
# authorize = ask("Authorize connection (yes/no): ")
# if (authorize == "yes"):
return
# raise Rejected("Connection rejected by user")
@dbus.service.method(AGENT_INTERFACE, in_signature="o", out_signature="s")
def RequestPinCode(self, device):
print("RequestPinCode (%s)" % (device))
return PIN_CODE
.......
@dbus.service.method(AGENT_INTERFACE, in_signature="o", out_signature="")
def RequestAuthorization(self, device):
print("RequestAuthorization (%s)" % (device))
# auth = ask("Authorize? (yes/no): ")
# if (auth == "yes"):
return
# raise Rejected("Pairing rejected")

Hope this helps.
Random avatar
george-ou812
Fresh off the boat
Fresh off the boat
 
Posts: 4
Joined: Tue Mar 14 2017 13:44


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby phweyland » Fri Mar 17 2017 20:29

Thank you George, I'll make a try asap.
EDIT 21/03:
I've made progress based on your infos. I still see some misbehavior.
The first pairing and then the cycle, connect, play, disconnect works fine, but
1. If I forget the connection from my mobile, I cannot pair again. I've to remove the device in bluetoothctl to pair again. Sometimes I've to restart also the simple-agent script to make the sound work.
2. I don't see any "RequestAuthorization xx" and "Release" messages. The last one seems more critical.
It seems that something is missing to manage the complete loop: pair, forget, pair ...
Any idea ?
Random avatar
phweyland
Sunday DIYer
Sunday DIYer
 
Posts: 12
Joined: Mon Feb 13 2017 20:37


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby george-ou812 » Tue Mar 21 2017 21:39

The settings above work very reliably for me, so a few questions for you so I can help ( possibly... )
1 ) What's your platform - RPI?
2 ) Linux flavour?
3 ) The back-end of Bluez5, pulseaudio or bluealsa? ( Currently I use pulseaudio hence why I'm here and want to get rid of it )
4 ) HCI device, built in BT ( BCMxxxx etc ) or USB-BT device
5 ) Bluez5 version.

Check your private email ( here )
Random avatar
george-ou812
Fresh off the boat
Fresh off the boat
 
Posts: 4
Joined: Tue Mar 14 2017 13:44


Volumio + Bluez-Alsa (a2dp bluetooth support)

Postby Caravan Volumio » Thu Mar 30 2017 09:10

Hi Guy's.
I have built a tiny music player & internet radio for my caravan.
Hardware is
Raspberry Pi Zero W
Hifi Berry Dac Zero
128Gb USB pen holding my complete music Lib (converted to MP3)

Software is volumio-2.118-2017-03-07-pi
It all works well connected from the DAC to the Aux In on the Caravan Radio.

I also have a Studio Series Bluetooth speaker and I'd like to stream to it.

I've followed the build -Volumio + Bluez-Alsa (a2dp bluetooth support).
Did it on an old Pi B to use it's wired connection. Had to install all dependencies individually & created the necessary files using nano at the root level.
I've just fire up the Zero with this build and have paired the StudioSeries speaker. But not getting any audio from Volumio.

Running $ systemctl | grep blue gives the following output

volumio@volumio:~$ systemctl | grep blue
sys-subsystem-bluetooth-devices-hci0.device loaded active plugged /sys/subsystem/bluetooth/devices/hci0
● bluealsa.service loaded failed failed BluezAlsa proxy
bluetooth.service loaded active running Bluetooth service
bluetooth.target loaded active active Bluetooth

$ ls /var/log/a2dp-autoconnect gives me - ls: cannot access /var/log/a2dp-autoconnect: No such file or directory

Any ideas about where my problem lies?

One other thing. While working through the build I kept encountering the folowing.

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_GB.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
I did run $ sudo dpkg-reconfigure locales. Set them to none, but this seemed to make no difference. In the end I did the build ignoring perl: warning.
Thanks for your time
Regards
Roger
Random avatar
Caravan Volumio
Sunday DIYer
Sunday DIYer
 
Posts: 10
Joined: Tue Mar 28 2017 16:02

Next

Return to Diy and Tweaks

Who is online

Users browsing this forum: No registered users and 0 guests