Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

[SOLVED] RPi4 Bluetooth woes

Sun May 09, 2021 12:31 pm

Greetings all Pi gurus!

For multiple reasons I am trying to switch my day-to-day computing over to using an 8GB Pi4 (tiny footprint & absolute silence are either hard to find or exceedingly expensive in an x86 format!), so I have thrown a fairly large chunk of money into a really nice Pi setup (Nanosound ONE case with DAC+, M2 case upgrade & drive), not least of which is a nice 60% mechanical bluetooth keyboard and accompanying mouse.

And there is where everything goes wrong.

I have spent three days fighting bluetooth on my Pi and gotten nowhere.

Tried multiple OS's (Raspberry Pi OS, Q4OS, Sparky and Ubuntu), the only one of which bluetooth seems to work on is the latest (21.04) version of Ubuntu Desktop, the one OS I tried that I really don't want to use (too big & heavy plus prior bad Ubuntu experiences).

I now have an install of Raspberry Pi OS that is almost perfect...except the bluetooth! Sometimes it works, sometimes it doesn't. And when it does it'll only be for that one session, rebooting kills everything and then it won't come alive again.

Currently, running:

Code: Select all

sudo service status bluetooth.service

will tell me

Code: Select all

bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-05-09 12:45:13 BST; 17min ago
     Docs: man:bluetoothd(8)
 Main PID: 610 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/bluetooth.service
           \u2514\u2500610 /usr/lib/bluetooth/bluetoothd

May 09 12:45:13 MiPi systemd[1]: Starting Bluetooth service...
May 09 12:45:13 MiPi bluetoothd[610]: Bluetooth daemon 5.50
May 09 12:45:13 MiPi systemd[1]: Started Bluetooth service.
May 09 12:45:13 MiPi bluetoothd[610]: Starting SDP server
May 09 12:45:13 MiPi bluetoothd[610]: Bluetooth management interface 1.18 initialized
May 09 12:45:13 MiPi bluetoothd[610]: Sap driver initialization failed.
May 09 12:45:13 MiPi bluetoothd[610]: sap-server: Operation not permitted (1)
May 09 12:45:14 MiPi bluetoothd[610]: Failed to set privacy: Rejected (0x0b)
May 09 12:45:14 MiPi bluetoothd[610]: Failed to set device class: Not Powered (0x0f)
and I am clueless as to why the driver which, according to the three previous devices I have connected in the bluetooth applet, did work at one point...suddenly on reboot...doesn't.

I am fully updated on all fronts and have purged/reinstalled bluez, bluez-firmware, bluez-tools and pi-bluetooth.

Sorry for the extremely long winded post, but after three days of frustration with something that I thought should "just work"™ I'm...flustered.

Hoping someone can shed some light!

Thanks in advance
Last edited by Demonitron on Mon May 17, 2021 10:40 pm, edited 2 times in total.

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RiPi4 Bluetooth woes

Sun May 09, 2021 2:30 pm

Update:

After yet more searching I have found out the "SAP" (SIM Access Profile) driver has something to do with SIM cards and isn't required in this instance and have disabled it.

Status now reads:

Code: Select all

bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-05-09 15:26:42 BST; 20s ago
     Docs: man:bluetoothd(8)
 Main PID: 593 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/bluetooth.service
           \u2514\u2500593 /usr/lib/bluetooth/bluetoothd --noplugin=sap

May 09 15:26:42 MiPi systemd[1]: Starting Bluetooth service...
May 09 15:26:42 MiPi bluetoothd[593]: Bluetooth daemon 5.50
May 09 15:26:42 MiPi systemd[1]: Started Bluetooth service.
May 09 15:26:42 MiPi bluetoothd[593]: Starting SDP server
May 09 15:26:42 MiPi bluetoothd[593]: Excluding (cli) sap
May 09 15:26:42 MiPi bluetoothd[593]: Bluetooth management interface 1.18 initialized
May 09 15:26:42 MiPi bluetoothd[593]: Failed to set privacy: Rejected (0x0b)
May 09 15:26:42 MiPi bluetoothd[593]: Failed to set device class: Not Powered (0x0f)
on a fresh boot.

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RiPi4 Bluetooth woes

Sun May 09, 2021 8:45 pm

Update No2

It seems that no one knows how to fix this.

There are a whole ton of reports to this problem online and not one single solution can be found.

Steps tried, and failed, so far:
  • Setting "--noplugin=sap" in /etc/systemd/system/bluetooth.target.wants/bluetooth.service - Does stop the SAP driver errors, nothing else
  • Adding firmware as detailed here.
  • Setting privacy off and controller mode to le in /etc/bluetooth/main.conf
  • Adding a 2 second delay to /lib/systemd/system/bthelper@.service - Allowed the bluetooth service to start without error but still won't pair
Running through the pairing procedure using bluetoothctl I am able to scan and find all bluetooth devices in range (on a fresh boot), upon attempt to add anything I get the pairing authorization request which I agree to and then get told the device is not connected. The same thing happens using the blueman applet. Scanning is fine, attempting to add is fine, I get a prompt to accept or deny the pairing, I accept and then it fails to pair.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 1:23 pm

This problem is being looked at/for.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 2:04 pm

If you have a spare card (or don't mind overwriting your current image) and some time, try installing the March release from here: https://downloads.raspberrypi.org/raspi ... 021-03-25/

After installation, perform the usual set-up but skip the software update. With this configuration I can pair keyboards and headsets.

If that works for you, try the following:

Code: Select all

$ sudo apt-mark hold lxplug-bluetooth
$ sudo apt update
$ sudo apt full-upgrade
$ sudo reboot
This configuration also works for me, but removing the hold on the lxplug-bluetooth package ("sudo apt-mark unhold lxplug-bluetooth") and running the upgrade again breaks it for me, suggesting that the damage is done by the change from version 0.19 to 0.21 of the plugin.

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 3:05 pm

Many thanks for looking into the problem, I really do appreciate it!

Sadly a clean install of the March release, with no updates, yields the same problem for me.

Bluetooth, in both the GUI applet and bluemanctl, will scan and detect devices just fine but pairing always fails with the device connecting then immediately after disconnecting.

sudo systemctl status bluetooth.service showing:

Code: Select all

bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-03-04 23:11:26 GMT; 2 months 5 days ago
     Docs: man:bluetoothd(8)
 Main PID: 572 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/bluetooth.service
           └─572 /usr/lib/bluetooth/bluetoothd

Mar 04 23:11:24 raspberrypi systemd[1]: Starting Bluetooth service...
Mar 04 23:11:26 raspberrypi bluetoothd[572]: Bluetooth daemon 5.50
Mar 04 23:11:26 raspberrypi systemd[1]: Started Bluetooth service.
Mar 04 23:11:26 raspberrypi bluetoothd[572]: Starting SDP server
Mar 04 23:11:27 raspberrypi bluetoothd[572]: Bluetooth management interface 1.18 initialized
Mar 04 23:11:27 raspberrypi bluetoothd[572]: Sap driver initialization failed.
Mar 04 23:11:27 raspberrypi bluetoothd[572]: sap-server: Operation not permitted (1)
Mar 04 23:11:27 raspberrypi bluetoothd[572]: Failed to set privacy: Rejected (0x0b)
Mar 04 23:11:47 raspberrypi bluetoothd[572]: Endpoint registered: sender=:1.26 path=/MediaEndpoint/A2DPSource
Mar 04 23:11:47 raspberrypi bluetoothd[572]: Endpoint registered: sender=:1.26 path=/MediaEndpoint/A2DPSink
I had hopes that it was due to an update (best case scenario!) but then the problem also exists on Q4OS with no lxplug-bluetooth present at all.

Back to the drawing board...

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 3:47 pm

To confirm that we are looking at the same problem, please remove any paired devices then:
1. in one window run "sudo btmon -w cap.bts" (you'll see tracing messages on the console even though it writes the raw packets to the bts file), and
2. attempt to pair the device using the GUI.

After this fails, use Ctrl-C to stop the capture and upload cap.bts somewhere it can be downloaded (DropBox, Google Drive, etc.).

mpma
Posts: 2
Joined: Mon May 10, 2021 3:47 pm

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 3:54 pm

I would just like to bump this thread.
I bought my RiPi4 last week and have been unable to pair and connect my Xbox One controller, which mulitple articles and guides on the internet says works like a charm!

My latest attempt was to try and skip the onboard bluetooth alltogether and get myself a bluetooth-adapter-dongle and use that instead since the onboard one doesn't appear to be working.

I tried disabling the onboard bluetooth by following this article: https://di-marco.net/blog/it/2020-04-18 ... pberry_pi/

When doing this, and just attempting to pair the controller via bluetoothctl I can sometimes get it to pair, but when trying to connect it just keeps spamming my terminal with connecting on, and connecting off all the time.

There really, really REALLY needs to be a sticky thread about this, and If it's being worked on as someone posted on this thread earlier I would like to know how that work is going?

Sorry for my tone, but It's so effin' frustrating when you do your initial research, before even buying the equipment and everything is "just supposed to work". Then you watch countless youtube clips of people getting it to work. But when you follow their instructions to the letter it simply doesn't work.

Please, if anyone has gotten their bluetooth to work on the RiPi4-boards, in anyway, please let me know

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 6:19 pm

Thank you again.

I've done two separate cap files, one for attempting to connect the keyboard (no authorisation request) and one for the mouse (authorisation requested and approved). I did separate attempts of both the GUI and CLI methods, just to try & cover all bases. Curiously the GUI attempt with the mouse didn't ask for authorisation but the CLI version did.

All files can be found here.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 8:06 pm

@mpma This topic is barely a day old - what makes you think it needs bumping?

@Demonitron Thanks.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 8:48 pm

Could you try the captures again with a fully updated image?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 8:53 pm

You can also try to "fix" the problem manually running the following commands:

Code: Select all

sudo hciconfig hci0 down; sudo systemctl restart bluetooth

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RiPi4 Bluetooth woes

Mon May 10, 2021 9:00 pm

While I wait for the Pi to run the full update, I tried the hciconfig trick.

Mouse failed connection immediately, authorisation error.

Keyboard paired...kind of. It said it couldn't connect and I should try to connect manually. Clicking on the bluetooth applet I did indeed see my keyboard & had the option to connect to it. On doing so? Connection failure, input/output error.

::EDIT::
I have uploaded the new files to Google Drive.

calanor
Posts: 37
Joined: Wed Feb 24, 2016 1:30 pm

Re: RiPi4 Bluetooth woes

Tue May 11, 2021 4:06 pm

I had similar problems with an X857 case with an X862 m2 ssd board. (https://wiki.geekworm.com/X862_V2.0). I solved using a wifi+bluetooth usb dongle rather than the built in on the pi 4.
In my case, the problem was due to the operational vibration of the SSD that interfered with the internal wifi / bluetooth chip.

I don't know if the Nanosound ONE case gives the same wifi and bluetooth blocking problems due to metal box or m2 board.

Try again with the pi out of the Nanosound case and without m2 ssd.

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RiPi4 Bluetooth woes

Tue May 11, 2021 4:20 pm

Calanor, those are some good points.

Unfortunately, I should have already mentioned, I'm not actually using the M2 during this initial setup phase at all, the idea was to get a good, clean install on the MicroSD card then dd it over to the M2, that way if anything went majorly wrong on the M2 I would have a static, clean backup to fall back to.

Sadly, we haven't progressed past the setup phase yet.

I don't believe the Nanosound/Argon ONE is blocking any signals, WiFi comes through strongly and bluetooth scans & detects very well, it's just the last hurdle of pairing that fails.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RPi4 Bluetooth woes

Wed May 12, 2021 11:54 am

This issue is at least partially understood now. There's a system script (bthelper) that detects boards with unprogrammed BDADDRs (Bluetooth addresses) and sets them to an auto-generated address. This feature was added to cope with the case that the kernel's Bluetooth firmware loader is being used instead of the external hciattach utility.

bthelper used to look for an address in one of the known good ranges, and force an address change if one wasn't found. This broke when a third OUI (24-bit MAC address range) was added (due to the number of Pis sold) because the script doesn't recognise the new range, forcing a new address even though one isn't needed. All of this would be unfortunate but benign except that there is a timing problem between the address change and bluetoothd starting, causing it to not recognise connections which leads to the connect/disconnect cycle.

An updated version of bthelper was written in advance of the switch to the new OUI and published in our pi-bluetooth repo, but it wasn't incorporated into the pi-bluetooth apt package, hence the issue you are seeing now.

You can install the new version of the script like this:

Code: Select all

$ wget https://raw.githubusercontent.com/RPi-Distro/pi-bluetooth/master/usr/bin/bthelper
$ sudo cp bthelper /usr/bin
This leaves the outstanding issue of how to handle any old, unprogrammed devices - that investigation is still ongoing.

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RPi4 Bluetooth woes

Wed May 12, 2021 4:32 pm

Good gravy! It works!

At least in my preliminary testing.

Scanned, paired & remained after several reboots.

Even stays paired and active with auto login disabled.

One quick tap on the keyboard or mouse & it connects again & works perfectly.

@PhillE, thank you!

I know it's not 100% solved yet but hot damn if this isn't a monstrous step forward!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RPi4 Bluetooth woes

Thu May 13, 2021 3:11 pm

I think I have a set of working scripts for all cases but one - old devices without a programmed Bluetooth address on which the kernel is configured to download the BT firmware ("dtparam=krnbt").

If you want to try the new scripts, download the tar archive from here: https://drive.google.com/file/d/1ZydE20 ... sp=sharing
Install it with:

Code: Select all

$ sudo tar --no-same-owner --keep-directory-symlink -zxvf btfix_20210513.tgz -C /

jcrisp
Posts: 5
Joined: Thu May 13, 2021 3:14 pm

Re: RPi4 Bluetooth woes

Thu May 13, 2021 11:16 pm

PhilE

With btfix_20210513 I am able to pair and connect to my jambox speaker but volume has a red X and will not play sound.

Not sure why this happens with rPi4 B v1.4 but not rPi4 B v1.1 with same SD card?

Thanks though, seems like part of the problem is solved...

jcrisp
Posts: 5
Joined: Thu May 13, 2021 3:14 pm

Re: RPi4 Bluetooth woes

Fri May 14, 2021 6:53 pm

from jcrisp

pi@rPi4:~ $ sudo bluetoothctl
Agent registered
[bluetooth]# pair 00:21:3c:7b:2a:d0
Attempting to pair with 00:21:3C:7B:2A:D0
[CHG] Device 00:21:3C:7B:2A:D0 Connected: yes
[CHG] Device 00:21:3C:7B:2A:D0 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 00:21:3C:7B:2A:D0 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 00:21:3C:7B:2A:D0 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:21:3C:7B:2A:D0 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:21:3C:7B:2A:D0 ServicesResolved: yes
[CHG] Device 00:21:3C:7B:2A:D0 Paired: yes
Pairing successful
[CHG] Device 00:21:3C:7B:2A:D0 ServicesResolved: no
[CHG] Device 00:21:3C:7B:2A:D0 Connected: no
[bluetooth]# connect 00:21:3c:7b:2a:d0
Attempting to connect to 00:21:3c:7b:2a:d0
Failed to connect: org.bluez.Error.Failed

Demonitron
Posts: 12
Joined: Sun May 09, 2021 12:48 am

Re: RPi4 Bluetooth woes

Fri May 14, 2021 7:29 pm

Unfortunately, we've taken a small step backwards today.

Setting up Q4OS (sorry, but Raspberry Pi OS just isn't for me) and getting

Code: Select all

 
 bluetoothd[580]: input-hog profile accept failed for CF:00:B6:C0:89:5D
 bluetoothd[580]:Battery Level: notifications not enabled Encryption required before read/write
in the systemctl status for bluetooth after I have tried, and failed, to pair my mouse.

Keyboard still pairs fine, however.

Mouse will say it's paired but never work.

So close! And yet. So far.

User avatar
craigevil
Posts: 209
Joined: Wed Jan 27, 2021 5:22 am
Location: OZ

Re: RPi4 Bluetooth woes

Fri May 14, 2021 7:48 pm

BT is working on my PI400.
Whatever the recent updates were , it just started working.
My brand new Amazon Echo Buds even reconnect when I reboot or logout and log in.

Code: Select all

System:    Kernel: 5.10.35-v8+ aarch64 bits: 64 compiler: N/A Desktop: LXDE 0.10.1 info: lxpanel, plank wm: Openbox 3.6.1 
           vt: 7 dm: LightDM 1.26.0 Distro: Raspberry Pi OS base: Debian GNU/Linux 11 (bullseye) 
Machine:   Type: ARM Device System: Raspberry Pi 400 Rev 1.0 details: BCM2835 rev: c03130 serial: <filter> 
CPU:       Info: Quad Core model: N/A variant: cortex-a72 bits: 64 type: MCP arch: ARMv8 rev: 3 bogomips: 432 
           Speed: 2000 MHz max: 2000 MHz Core speeds (MHz): 1: 2000 2: 2000 3: 2000 4: 2000 
           Features: asimd cpuid crc32 evtstrm fp 

Audio:     Device-1: bcm2835-audio driver: bcm2835_audio bus-ID: N/A chip-ID: brcm:bcm2835_audio class-ID: bcm2835_audio 
           Device-2: bcm2711-hdmi0 driver: N/A bus-ID: N/A chip-ID: brcm:soc class-ID: hdmi 
           Device-3: bcm2711-hdmi1 driver: N/A bus-ID: N/A chip-ID: brcm:soc class-ID: hdmi 
           Sound Server-1: ALSA v: k5.10.35-v8+ running: yes 
           Sound Server-2: PulseAudio v: 14.2 running: yes 

Bluetooth: Device-1: pl011 driver: uart_pl011 bus-ID: N/A chip-ID: arm:fe201000 class-ID: serial 
           Report: hciconfig ID: hci0 rfk-id: 1 state: up address: <filter> bt-v: 3.0 lmp-v: 5.0 sub-v: 6606 hci-v: 5.0 
           rev: 36 
Raspberry PI 400 Raspberry Pi OS (Unstable) Kernel: 5.10.17-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RPi4 Bluetooth woes

Fri May 14, 2021 8:05 pm

@jcrisp and @craigevil, what do "ifconfig eth0" and "hcitool dev" report on your Pis?

@Demonitron I don't know anything about Q4OS - does it use our pi-bluetooth package?

jcrisp
Posts: 5
Joined: Thu May 13, 2021 3:14 pm

Re: RPi4 Bluetooth woes

Fri May 14, 2021 8:18 pm

pi@rPi4:~ $ ifconfig eth0
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether e4:5f:01:0f:06:06 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

pi@rPi4:~ $ hcitool dev
Devices:
hci0 B8:27:EB:31:B4:2D
pi@rPi4:~ $

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3888
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: RPi4 Bluetooth woes

Fri May 14, 2021 8:29 pm

I think you haven't applied my patch: viewtopic.php?p=1864498#p1864498

Return to “Troubleshooting”