14

When trying to connect a new device through the Raspberry Pi I take the following steps without success. I can re-pair as many times as I want with any device, but I can never connect.

Other devices can create a connection with the Pi when it's discoverable (after being paired).

[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 33:22:11:CC:BB:AA Discoverable: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[bluetooth]# pair AA:BB:CC:11:22:33
Device AA:BB:CC:11:22:33 not available
[NEW] Device AA:BB:CC:11:22:33 Pixel XL
Request confirmation
[agent] Confirm passkey 123456 (yes/no): yes
[CHG] Device AA:BB:CC:11:22:33 Modalias: bluetooth:v000Fpw83523957
[CHG] Device AA:BB:CC:11:22:33 UUIDs:
        [[UUIDS-123456-234324-25325-23532523tu]]
[CHG] Device AA:BB:CC:11:22:33 Paired: yes
[bluetooth]# connect AA:BB:CC:11:22:33
Attempting to connect to AA:BB:CC:11:22:33
Failed to connect: org.bluez.Error.Failed
[CHG] Device AA:BB:CC:11:22:33 Connected: no
[CHG] Controller 33:22:11:CC:BB:AA Discoverable: no

This is a Raspberry Pi3 and the version info from bluetooth ctl is here:

Version 5.23
udjamaflip
  • 411
  • 1
  • 3
  • 9

4 Answers4

17

So it turns out that when I looked into the bluetoothctl logs on the Raspberry Pi that I was getting this error:

a2dp-source profile connect failed for AA:BB:CC:11:22:33: Protocol not available

You can look this by running:

sudo cat /var/log/syslog | grep -i protocol 

Which is reported all over the internet as being resolveable through this command:

pactl load-module module-bluetooth-discover

Which gives THIS error:

Failure: Module initialization failed

This answer here resolved my issue with that command (I added 2 more steps after for clarity): https://askubuntu.com/a/689297/82021

After performing the file modifications in this answer do the following:

  1. Reboot your Pi
  2. pactl load-module module-bluetooth-discover

After all this, I can now pair AND connect any bluetooth device using Raspbian on my RPi3.

udjamaflip
  • 411
  • 1
  • 3
  • 9
  • I get the same issue when trying to connect my desktop to my raspberry pi. I'm testing your solution now, but I find it strange because this is not an audio application and your solution uses pulseaudio. Strange! Were you connecting to an audio device? – Julian Cienfuegos Oct 07 '17 at 00:53
  • 1
    My device also wasn't audio, it was phones and computers – udjamaflip Oct 07 '17 at 01:38
  • Setting up bluetooth to make my laptop and desktop communicate took me 5 minutes. Making my desktop and Rpi 2.0 B has taken two days so far and still no luck. This solution causes "systemctl start bluetooth" to fail for me, with the "sap-server: Operation not permitted (1) error". Very very strange. Will report back if I find a solution. I wonder if this fix you've posted is particular to the model 3? – Julian Cienfuegos Oct 07 '17 at 02:33
  • I'm having this same problem but your solution doesn't seem to help. I guess it's outdated? – Nathan Bird Dec 31 '18 at 16:31
  • Should it be the exact same error the above 2 answers should work still. I recently (early December) used this to resolve the issue on a new Pi install. – udjamaflip Jan 01 '19 at 23:31
  • I try to connect my bluetooth headset, but after doing what you sugested, I get sudo pactl load-module module-bluetooth-discover Connection failure: Connection refused pa_context_connect() failed: Connection refused. Do you have maybe some hints for me? – bernhardh Jan 26 '21 at 22:59
6

I realize this is over 3 years old now, but after looking at the answers given here, I found that I didn't even have pulse audio installed (Pi OS Lite (Buster) on RPi4).

After installing bluez-tools and pulseaudio, I was able to run: pactl load-module module-bluetooth-discover and got the error: Failure: Module initialization failed

I started installing pulse audio modules one by one (eg. pulseaudio-module-bluetooth), but in the end decided they all looked pretty important for future shenanigans. This resolved all issues for me:

sudo apt-get install pulseaudio*

result:

~$ pactl load-module module-bluetooth-discover

20

  • Thank you! After spending many hours on the internet and trying out many solutions including the selected answer here, your solution is what solved my problem on Pi4B. – ali14 Apr 17 '21 at 01:15
1

I solved this fixing two things:

  1. Changes the permissions at /etc/dbus-1/system.d/bluetooth.conf
    I crudely changed the default permission to allow. A more elgant solution is probably possible.

    <policy context="default"> <allow send_destination="org.bluez"/>
    </policy>

2. A timing bug fixed by running this:

  pactl unload-module module-bluetooth-discover
  pactl load-module module-bluetooth-discover

YMMV

Ronenz
  • 111
  • 1
  • 1
    Do you have any more information about the timing bug? I'd like to contribute a fix. Just doing 2 alone worked for me! – 0xcaff Dec 10 '19 at 20:51
0

On my Raspberry Pi 2 running Debian stretch armv7, I had to install bluez-utils from https://packages.debian.org/wheezy/all/bluez-utils/download as apt-get install did not find such a packet.

Chetan Bhargava
  • 1,262
  • 3
  • 15
  • 29