Page 1 of 1

Cannot connect Pi to Bluetooth headphones

Posted: Thu Jan 09, 2020 4:40 pm
by henriquesga
Hi! I've only gotten my first Pi yesterday, and though I've got it working, I cannot seem to connect it to my Bluetooth headphones. Unfortunately there doesn't seem to be any guides for using Bluetooth from the command line - I'm running Raspbian headless from my computer, through SSH - and instructions I've been able to find aren't working.

I've read through multiple solutions, including installing multiple packages such as pulseaudio and blueman, but none have worked, so I'm hoping posting on a forum could help.

Here is the terminal logs of what I've been trying to do:

Code: Select all

pi@raspberrypi:~ $ sudo bluetoothctl
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:A6:32:37:4E:DF Discovering: yes
[NEW] Device 5C:FB:7C:E4:70:93 JBL TUNE500BT
[CHG] Device 90:32:4B:1F:71:6A RSSI: -65
[CHG] Device 90:32:4B:1F:71:6A TxPower: 0
[bluetooth]# trust 5C:FB:7C:E4:70:93
[CHG] Device 5C:FB:7C:E4:70:93 Trusted: yes
Changing 5C:FB:7C:E4:70:93 trust succeeded
[bluetooth]# pair 5C:FB:7C:E4:70:93
Attempting to pair with 5C:FB:7C:E4:70:93
[CHG] Device 5C:FB:7C:E4:70:93 Connected: yes
[CHG] Device 5C:FB:7C:E4:70:93 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:FB:7C:E4:70:93 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:FB:7C:E4:70:93 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:FB:7C:E4:70:93 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:FB:7C:E4:70:93 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:FB:7C:E4:70:93 ServicesResolved: yes
[CHG] Device 5C:FB:7C:E4:70:93 Paired: yes
Pairing successful
[CHG] Device 5C:FB:7C:E4:70:93 ServicesResolved: no
[CHG] Device 5C:FB:7C:E4:70:93 Connected: no
[bluetooth]# connect 5C:FB:7C:E4:70:93
Attempting to connect to 5C:FB:7C:E4:70:93
Failed to connect: org.bluez.Error.Failed
[bluetooth]# quit
pi@raspberrypi:~ $ sudo service bluetooth status
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-01-09 15:54:26 GMT; 38min ago
     Docs: man:bluetoothd(8)
 Main PID: 470 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   Memory: 3.7M
   CGroup: /system.slice/bluetooth.service
           └─470 /usr/lib/bluetooth/bluetoothd --noplugin=sap

Jan 09 15:54:26 raspberrypi systemd[1]: Started Bluetooth service.
Jan 09 15:54:26 raspberrypi bluetoothd[470]: Starting SDP server
Jan 09 15:54:26 raspberrypi bluetoothd[470]: Excluding (cli) sap
Jan 09 15:54:26 raspberrypi bluetoothd[470]: Bluetooth management interface 1.14 initialized
Jan 09 15:54:26 raspberrypi bluetoothd[470]: Failed to set privacy: Rejected (0x0b)
Jan 09 16:21:40 raspberrypi bluetoothd[470]: a2dp-sink profile connect failed for 5C:FB:7C:E4:70:93: Protocol not available
I hope this is enough information, since I don't remember all the steps I've taken to try to work through the problem, but I'm happy to do any troubleshooting suggested.

Re: Cannot connect Pi to Bluetooth headphones

Posted: Sun Jan 12, 2020 7:37 am
by peppe8o
Hi,
connecting bluetooth Headphones is quite hard from a terminal (i suppose you are using a lite version of Raspbian). In last days I also fighted with this and come to a working solution (I don't know if it is correct, but it works).
Before starting. Stack pipeline should be the following:
BlueZ → PulseAudio → ALSA
so, you should install also bluealsa and pulseaudio in a fresh installation.

With default settings, you will see SAP (Sim Access Profile) error in bluetooth service status. You can correct this by appengin "--noplugin=sap" option to ExecStart parameter in /lib/systemd/system/bluetooth.service.

After this correction, a "set privacy failure" error comes from bluetooth service. This can be corrected by restarting bluetooth service (but error come out at each reboot) or working on "/lib/systemd/system/bthelper@.service" file and adding "ExecStartPre=/bin/sleep 2" to this file.

Now, start pulseaudio with "pulseaudio --start" and pair your headphones. You can test them by recording with the command (xx.xx.xx.... is bluetooth device MAC address):
arecord -D bluealsa:DEV=xx:xx:xx:xx:xx:xx,PROFILE=sco test.wav

or playing the same file with:
aplay -D bluealsa:DEV=xx:xx:xx:xx:xx:xx,PROFILE=sco test.wav

Again, I don't know if this is correct, but it works (tested in a Raspberry PI 3 Model B+).

For complete guide, see https://peppe8o.com/2020/01/fixed-conne ... pberry-pi/