This tutorial is for a2dp only. I've moved to pulseaudio bluetooth meanwhile to use other features automatically.
Compilation instructions for bluealsa a2dp are on the repo page.
Make sure user PI is in the right groups for udev, pulse access, etc (audio, bluetooth, pulse-access, plugdev)
Disable onboard sound, it sucks (comment out/remove the line dtparam=audio=on
in /boot/config.txt
) and use an external USB soundcard (I just got this one https://www.aliexpress.com/item/Ugreen-USB-2-0-to-3-5mm-Audio-External-Sound-Card-Microphone-Earphone-Speaker-Adapter-for/32507625943.html and it works fine. Previously I used LX-3000's soundcard I had around).
autobt.py
goes in /home/pi/autobt.
. Technically, this is the place you can integrate stuff like on line #4 where you can send commands, but you need threads or a way to interrupt and listen to commands (didn't research, don't know python).
You also need to download https://raw.githubusercontent.com/pauloborges/bluez/master/test/bluezutils.py in the same dir. If other dependencies are missing, they should be available using apt install ...
This is used to auto-trust any connected device (phone etc). My android 8 phone (OnePlus 5) doesn't allow playing without trusting the device first and disconnects after a while otherwise.
It sets the pin to 0000 if your device requires a pin pairing.
The x.service
files go in /etc/systemd/system
Edit /etc/bluetooth/audio.conf
and make it look like (you can set your own class here):
[General]
Class=0x20041C
Enable=Source,Sink,Media,Socket
Edit /etc/bluetooth/main.conf
and change:
Name
to whatever you want (I don't think this is the right place, but it doesn't hurt)DiscoverableTimeout=0
(unless you do something fancy in a script)- At the bottom, set
AutoEnable=true
Edit /var/lib/bluetooth/[your-bt-addr-here-or-use-tab-tab]/settings
and add (I think this goes in one of the confs above, not sure where though - audio.conf or main.conf)
[General]
Discoverable=true
Edit /etc/asound.conf
and add this but change with your BT address
defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "B8:27:EB:52:72:77"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000
Run systemctl daemon-reload
and for each services run systemctl enable x.service
and systemctl start x.service
.
A reboot shouldn't hurt...
Also, for better performance overall, try to remove the burden on your pi (if you plan use on PiZeroW) by unused services like samba...
@besi do try to implement soon because I will wipe my bench RPi soon to start a new project - that is if you need any help