edit: 30 juli 2019 - see Thorgal789
post below and my
post right after that.
I started with BT-audio from the wiki page also, but I soon have found out that this does not work anymore. I assume, because of some changes to the bluetooth packages. I’m certainly not an expert, but did get a little bit further.
I want to use this bluetooth speaker to make some alert sounds as feedback.
I used pulseaudio. I believe this is preferred audio system by newer distro’s.
Code: Select all
sudo apt install pulseaudio pulseaudio-utils pulseaudio-module-bluetooth
sudo nano /etc/bluetooth/main.conf
(/etc/bluetooth/audio.conf is not used anymore)
add (or change if exist):
Code: Select all
# This section contains general options
[General]
Enable=Source,Sink,Media,Socket
Change/add the following configuration in your /etc/pulse/system.pa config.
Code: Select all
Sudo nano /etc/pulse/system.pa
# Modify: /etc/pulse/system.pa
### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif
.ifexists module-bluez5-discover.so
load-module module-bluez5-discover
.endif
and in this same file change, or add the line:
Code: Select all
load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulseaudio.socket
The /tmp/socket makes it possible to connect to pulseaudio with different users.
I added/changed the same lines in /etc/pulse/default.pa
In /etc/pulse/client.conf
change, or add the lines:
Code: Select all
default-server = unix:/tmp/pulseaudio.socket
autospawn = no
I had to remove all files from: /home/pi/.config/pulse/ and /root/.config/pulse/ to make this work.
Especially the client.conf file in there.
In /etc/pulse/daemon.conf I changed/added the line:
Code: Select all
exit-idle-time = -1
allow-module-loading = yes
enable-memfd = yes
First stop pulse audio:
Next, Start pulseaudio at boot as service (or daemon? I’m not sure about the difference)
For this part I used this source:
link )
Code: Select all
sudo nano /etc/systemd/system/pulseaudio.service
And change or add:
Code: Select all
[Unit]
Description=PulseAudio system service
[Service]
Type=notify
ExecStart=/usr/bin/pulseaudio
Restart=on-failure
[Install]
WantedBy=multi-user.target
Now enable and start this unit file by running the following commands:
Code: Select all
sudo systemctl --system enable pulseaudio.service
sudo systemctl --system start pulseaudio.service
It should be running now. You can check the status of the service with the command:
Code: Select all
sudo systemctl --system status pulseaudio.service
I got an error about a cookie file. I will report how I solved this later.
Now add the user who needs access to pulseaudio to the pulse and pulse-access groups:
Code: Select all
sudo usermod -aG pulse,pulse-access <username>
And I added root too.
sudo usermod -aG pulse,pulse-access root
change <username> with pi or your normal username.
Changes to groups are effective after you logout and log back in.
Bluetooth:
On ubuntu:
Code: Select all
sudo add-apt-repository ppa:bluetooth/bluez
sudo apt update
sudo apt upgrade
sudo apt install bluez bluetooth
sudo service bluetooth restart
sudo /etc/init.d/bluetooth start
or try using the method donwloading from kernel.org as described here:
link
I'm using version 5.49
I also installed Bluealsa. But now I'm not sure if this is nescesary.
source
Type:
then press enter and input the administrator password.
Next, enter
and press enter. Then type
and press enter. Type
and press enter one more time. The unique addresses of all the Bluetooth devices around will appear and look something like an alphanumeric XX:XX:XX:XX:XX:XX. If you make the device you want to pair discoverable (or put it into pairing mode), the device nickname may appear to the right of the address. If not, you will have to do a little trial and error or waiting to find the correct device.
To pair the device, type
Code: Select all
[Bluetooth] pair XX:XX:XX:XX:XX:XX
XX:XX:XX:XX:XX:XX is the device bluetooth address. Change it with the address of your speaker (for example)
Connect to the device, type
Then:
type 'exit' to leave bluetoothctl.
In order to pair up with Bluetooth devices, you need to add, or change the following text to the file /etc/dbus-1/system.d/pulse.conf:
Code: Select all
sudo nano /etc/dbus-1/system.d/pulseaudio-system.conf
Check if this file exist. In my case there where two files. One pulse.conf en this one. I merged them to pulseaudio-system.conf.
Code: Select all
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.pulseaudio.Server"/>
<allow send_destination="org.bluez"/>
<allow send_interface="org.bluez.Manager"/>
</policy>
<policy user="pulse">
<allow own="org.pulseaudio.Server"/>
<allow send_destination="org.bluez"/>
<allow send_interface="org.bluez.Manager"/>
</policy>
<policy context="default">
<deny own="org.pulseaudio.Server"/>
<deny send_destination="org.bluez"/>
<deny send_interface="org.bluez.Manager"/>
</policy>
</busconfig>
According to this same source I changed/added in the file:
/etc/dbus-1/system.d/bluetooth.conf
Code: Select all
<allow send_interface="org.bluez.ThermometerWatcher1"/>
<allow send_interface="org.bluez.HeartRateWatcher1"/>
<allow send_interface="org.bluez.CyclingSpeedWatcher1"/>
<!-- allow users of bluetooth group to communicate -->
<policy group="bluetooth">
<allow send_destination="org.bluez"/>
</policy>
It’s easiest to reboot the system now.
After this reboot, find out the name to use for the bluetooth device to make some noise.
(I still cannot get info without sudo. That I do not understand)
find the: bluez_sink.XX_XX_XX_XX_XX_XX.a2dp_sink” part. We will need this addres.
I use paplay like this:
Code: Select all
paplay -p --device=bluez_sink.XX_XX_XX_XX_XX_XX.a2dp_sink --volume=65536 /home/pi/sounds/dingdong-1.wav
volume 65536 is volume set to 100%. So be careful. You could set it in a range of 0 – 65536. paplay does not play mp3’s. Mplayer can.
Another method I use is by using mplayer, like this:
Code: Select all
mplayer -ao pulse::bluez_sink.XX_XX_XX_XX_XX_XX.a2dp_sink /home/pi/1.mp3 -softvol -volume 25
This is working well for me, but just for a while. After some time my bluetooth speaker disconnects. After that I had some trouble reconnecting.
In the next post I solved this.
Edit: some corrections
edit: 29 juli 2019 - made some changes
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.