Skip to content

Instantly share code, notes, and snippets.

@stefan-wegener
Created February 22, 2019 09:03
Show Gist options
  • Save stefan-wegener/db61bd83a19b4901a2dbc6d78e237b63 to your computer and use it in GitHub Desktop.
Save stefan-wegener/db61bd83a19b4901a2dbc6d78e237b63 to your computer and use it in GitHub Desktop.
Bluetooth + Pulseaudio + Linphone on a Raspberry Pi

Bluetooth

Add user pi to bluetooth group

sudo adduser pi bluetooth
newgrp bluetooth

Change capabilities of bluetooth-service (/lib/systemd/system/bluetooth.service) add CAP_NET_RAW

CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW

Install bluealsa

sudo apt-get install bluealsa

Restart system. Afterwards connecting to a Bluetooth device is possible via:

bluetoothctl

scan on
pair X:X:X:X
trust X:X:X:X
connect X:X:X:X

scan off
exit

To enable an autoreconnect of a specific device on each reboot do sudo crontab -e and add

@reboot sleep 15 && /bin/echo -e 'connect X:X:X:X \n quit \n' | bluetoothctl

Linux Audio

Download example file and test if playing audio is working

wget http://www.music.helsinki.fi/tmt/opetus/uusmedia/esim/a2002011001-e02.wav
aplay -D bluealsa:HCI=hci0,DEV=X:X:X:X,PROFILE=a2dp a2002011001-e02.wav

Pulseaudio

See https://github.com/davidedg/NAS-mod-config/blob/master/bt-sound/bt-sound-Bluez5_PulseAudio5.txt#L121 Install pulseaudio

sudo apt-get install pulseaudio pulseaudio-module-bluetooth pulseaudio-module-zeroconf

Add pi-user to pulseaudio groups

sudo adduser pi pulse
sudo adduser pi pulse-access

Edit /etc/dbus-1/system.d/pulseaudio-system.conf

<busconfig>

  <policy user="pulse">
    <allow send_destination="org.bluez"/>
  </policy>

</busconfig>

Edit /etc/pulse/system.pa add

### Bluetooth Support
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

Create /etc/systemd/system/pulseaudio.service

[Unit]
Description=Pulse Audio

[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1

[Install]
WantedBy=multi-user.target

Enable service

sudo systemctl daemon-reload
sudo systemctl enable pulseaudio.service

Maybe restarting is also required here. Afterwards again connect to the bluetooth device and try

aplay a2002011001-e02.wav

Linphone

sudo apt-get install linphone

Start linphone-console and register client and set soundcard

linphonec

linphonec> register sip:<address>@<server> <server> <password>

linphonec> soundcard list
0: ALSA: default device
1: ALSA: bcm2835 ALSA
2: PulseAudio: default

linphonec> soundcard use 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment