2

A Bluetooth connection with a fresh flashed Raspberry Pi OS should work out of the box, at least with a Media audio profile. I can pair the smartphone and the RasPi but I cannot connect using bluetoothctl. I use the Raspberry Pi OS (32-bit) with desktop, based on version Buster on a Raspberry Pi 4B. First I make the smartphone in its bluetooth settings visible for other devices. Then I do:

rpi ~$ bluetoothctl
Agent registered

[bluetooth]# scan on
Discovery started
[NEW] Device 14:A3:64:06:9F:DB Ingo (Galaxy S5)

[bluetooth]# scan off
[CHG] Controller DC:A6:32:7F:38:48 Discovering: no
Discovery stopped

[bluetooth]# pair 14:A3:64:06:9F:DB
Attempting to pair with 14:A3:64:06:9F:DB
[CHG] Device 14:A3:64:06:9F:DB Connected: yes
Request confirmation
[agent] Confirm passkey 880257 (yes/no): yes
[CHG] Device 14:A3:64:06:9F:DB Modalias: bluetooth:v0075p0100d0200
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 0000112d-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 14:A3:64:06:9F:DB ServicesResolved: yes
[CHG] Device 14:A3:64:06:9F:DB Paired: yes
Pairing successful
[CHG] Device 14:A3:64:06:9F:DB ServicesResolved: no
[CHG] Device 14:A3:64:06:9F:DB Connected: no

[bluetooth]# connect 14:A3:64:06:9F:DB
Attempting to connect to 14:A3:64:06:9F:DB
Failed to connect: org.bluez.Error.Failed

Why do I get this error message? What have I to do to connect successfully?

1 Answer 1

3

The problem is that there is no Audio Sink defined. Check with

rpi ~$ bluetoothctl show
Controller DC:A6:32:7F:38:48 (public)
        Name: raspberrypi
        Alias: raspberrypi
        Class: 0x00480000
        Powered: yes
        Discoverable: no
        Pairable: yes
        UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
        UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v1D6Bp0246d0532
        Discovering: no
rpi ~$

As you can see, you will find an Audio Source but no Audio Sink, that is needed to provide a service to output audio. Out of the box RaspiOS uses alsa for audio services and with bluetooth bluealsa is needed:

rpi $ bluealsa --help
Usage:
  bluealsa [OPTION]...

Options:
  -h, --help            print this help and exit
  -V, --version         print version and exit
  -B, --dbus=NAME       D-Bus service name suffix
  -S, --syslog          send output to syslog
  -i, --device=hciX     HCI device to use
  -p, --profile=NAME    enable BT profile
  --a2dp-force-mono     force monophonic sound
  --a2dp-force-audio-cd force 44.1 kHz sampling
  --a2dp-keep-alive=SEC keep A2DP transport alive
  --a2dp-volume         control volume natively

Available BT profiles:
  - a2dp-source Advanced Audio Source (SBC)
  - a2dp-sink   Advanced Audio Sink (SBC)
  - hfp-hf      Hands-Free (v1.7)
  - hfp-ag      Hands-Free Audio Gateway (v1.7)
  - hsp-hs      Headset (v1.2)
  - hsp-ag      Headset Audio Gateway (v1.2)

By default only output profiles are enabled, which includes A2DP Source and
HSP/HFP Audio Gateways. If one wants to enable other set of profiles, it is
required to explicitly specify all of them using `-p NAME` options.

Please note the comment at the end. To have an audio sink enabled we have to use at least option p a2db-sink but also others. It doesn't hurt to enable all available profiles:

bluealsa -p a2dp-source -p a2dp-sink -p hfp-hf -p hfp-ag -p hsp-hs -p hsp-ag

bluealsa is started with a service:

rpi ~$ systemctl status bluealsa.service
● bluealsa.service - BluezALSA proxy
   Loaded: loaded (/lib/systemd/system/bluealsa.service; static; vendor preset: enabled)
   Active: active (running) since Sun 2020-09-27 11:50:29 BST; 2h 44min ago
 Main PID: 739 (bluealsa)
    Tasks: 3 (limit: 4915)
   CGroup: /system.slice/bluealsa.service
           └─739 /usr/bin/bluealsa

Sep 27 11:50:29 raspberrypi systemd[1]: Started BluezALSA proxy.

Here you can see in the CGroup that 739 /usr/bin/bluealsa is started without the additional option, so we have to modify it. I prefer to use a drop-in file with:

rpi ~$ sudo systemctl edit bluealsa.service

In the empty editor insert these statements, save them and quit the editor.

[Service]
# Empty ExecStart to disable the old one
ExecStart=
ExecStart=/usr/bin/bluealsa -p a2dp-source -p a2dp-sink -p hfp-hf -p hfp-ag -p hsp-hs -p hsp-ag

Check the runtime property:

rpi ~$ systemctl show --property=ExecStart bluealsa
ExecStart={ path=/usr/bin/bluealsa ; argv[]=/usr/bin/bluealsa -p a2dp-source -p a2dp-sink -p hfp-hf -p hfp-ag -p hsp-hs -p hsp-ag ; ignore_errors=no ; start_time=[Sun 2020-09-27 15:23:05 BST] ; stop_time=[n/a] ; pid=728 ; code=(null) ; status=0/0 }

You can also list the complete service with systemctl cat bluealsa.service.

Now reboot. You must unpair the smartphone in its bluetooth settings and on the RasPi:

rpi ~$ bluetoothctl
Agent registered

[bluetooth]# paired-devices
Device 14:A3:64:06:9F:DB Ingo (Galaxy S5)

[bluetooth]# remove 14:A3:64:06:9F:DB
[DEL] Device 14:A3:64:06:9F:DB Ingo (Galaxy S5)
Device has been removed

Now pair it again. Then you should be able to connect the smartphone. To simplify things I recommend to trust the device before pairing!

[bluetooth]# scan on
--- snip ---
[bluetooth]# scan off
--- snip ---
[bluetooth]# devices
Device 14:A3:64:06:9F:DB Ingo (Galaxy S5)

[bluetooth]# trust 14:A3:64:06:9F:DB
[CHG] Device 14:A3:64:06:9F:DB Trusted: yes
Changing 14:A3:64:06:9F:DB trust succeeded

[bluetooth]# pair 14:A3:64:06:9F:DB
--- snip ---
Pairing successful
[CHG] Device 14:A3:64:06:9F:DB ServicesResolved: no
[CHG] Device 14:A3:64:06:9F:DB Connected: no

[bluetooth]# connect 14:A3:64:06:9F:DB
Attempting to connect to 14:A3:64:06:9F:DB
[CHG] Device 14:A3:64:06:9F:DB Connected: yes
Connection successful
[CHG] Device 14:A3:64:06:9F:DB ServicesResolved: yes
[Ingo (Galaxy S5)]

References:
(1) Ubuntu - pairing
{2] Pairing Agents in BlueZ stack

6
  • There's a broken link in your first reference: "Ubuntu - pairing"
    – Seamus
    Mar 13, 2021 at 6:42
  • I don't pretend to understand Bluetooth but current Raspberry Pi OS has UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) - probably the "new-raspberry-pi-os-release-december-2020" 4th Dec 2020
    – Milliways
    Mar 13, 2021 at 10:12
  • @Seamus I have no problem to get to the side by clicking the link.
    – Ingo
    Jun 20, 2021 at 21:53
  • Ja - works for me as well now. So - where in the world have you been, my friend?
    – Seamus
    Jun 20, 2021 at 22:16
  • @Seamus Do you missed me :-) ? Yes, I'm busy with reengineering old classic UPnP library github.com/pupnp/pupnp to make it re-entrant, object oriented, unit tested and to support IPv6. It isn't done in a month. I have changed the focus a bit.
    – Ingo
    Jun 21, 2021 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.