Bluetooth headphones are connected, but audio goes to speakers

I have a problem on my system where bluetooth headphones doesn’t work properly. They connect to bluetooth, but audio sometimes works and sometimes doesn’t. Checked with two different headphones.

Here is some trace from journalctl:

Nov 25 21:35:23 nixos pulseaudio[3511]: Could not find org.bluez.BatteryProviderManager1.RegisterBatteryProvider(), is bluetoothd started with experimental features enabled (-E flag)?
Nov 25 21:35:23 nixos bluetoothd[954]: src/profile.c:register_profile() :1.100 tried to register 0000111f-0000-1000-8000-00805f9b34fb which is already registered
Nov 25 21:35:23 nixos pulseaudio[3511]: org.bluez.ProfileManager1.RegisterProfile() failed: org.bluez.Error.NotPermitted: UUID already registered
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSink/sbc
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSource/sbc
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Nov 25 21:35:23 nixos bluetoothd[954]: Endpoint registered: sender=:1.100 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Nov 25 21:37:30 nixos dbus-daemon[955]: [system] Rejected send message, 0 matched rules; type=“method_return”, sender=“:1.51” (uid=1000 pid=1628 comm=“/nix/store/mi9na996l6g5vdmn7chz3yrnqj10wdvq-wirepl” label=“kernel”) interface=“(unset)” member=“(unset)” error name=“(unset)” requested_reply=“0” destination=“:1.2” (uid=0 pid=954 comm=“/nix/store/78p8l8z8kbamr9pf2ksj2p78j7a0a10z-bluez-” label=“kernel”)
Nov 25 21:38:12 nixos dbus-daemon[955]: [system] Rejected send message, 0 matched rules; type=“method_return”, sender=“:1.51” (uid=1000 pid=1628 comm=“/nix/store/mi9na996l6g5vdmn7chz3yrnqj10wdvq-wirepl” label=“kernel”) interface=“(unset)” member=“(unset)” error name=“(unset)” requested_reply=“0” destination=“:1.2” (uid=0 pid=954 comm=“/nix/store/78p8l8z8kbamr9pf2ksj2p78j7a0a10z-bluez-” label=“kernel”)

I’d appreciate any help.

Hey welcome to NixOS!

Bluetooth can be a bit finicky sometimes. Several ideas come to my mind: it appears you are not using pipewire on your system. I personally use it and it has been without problems. Maybe that improves something.

It is not totally clear to me what “audio sometimes works and sometimes doesn’t” really means.

A quick search for the error org.bluez.Error.NotPermitted: UUID already registered gave me something related to Samsung Galaxy Buds. Are you using these?

I mean sometimes audio works through headphones when I connect them. But not always. Reboot might help, but also not a guarantee.

I’ve tried to switch to pipewire instead of pulseaudio. The problem wasn’t solved immediately after nixos-rebuild switch, but it works after a reboot. I’ll post if I catch this problem again. Thanks!

Let’s hope it works. As I said, BT can be delicate :sweat_smile:

Glad a reboot seemed to have worked. Nevertheless, what’s your config look like? Here’s mine:

  hardware.bluetooth = {
    enable = true;
    powerOnBoot = true;
    settings = {
      General = {
        Name = "Computer";
        ControllerMode = "dual";
        FastConnectable = "true";
        Experimental = "true";
      };
      Policy = { AutoEnable = "true"; };
      LE = { EnableAdvMonInterleaveScan = "true"; };
    };
  };

and I’ve really never had much of an issue. I only recently switched over to pipewire FWIW. Granted, some headphones behave certain ways that are less than desirable.

Yeah, this is just bluetooth things. My headsets (used about 4 or 5 different ones over the years) fail to connect properly about 1/3 of the time, with pipewire and pulse alike.

Typically this appears to be because my phone, computer and switch end up fighting over who the headset connects to. My headset can clearly only handle being connected to at most two devices at a time, but my PC seems to typically connect last and still think the headset is “connected” despite not actively accepting any audio from it. Hell, even if only two devices are connected it’s finnicky about which it considers currently playing sound - even if my phone is muted notifications often steal audio focus.

Bluetooth is a mess.

My strategy for resolving this is to first disconnect my headset from all other devices, then open blueman on my PC, right click the device to disconnect, wait for it to disconnect, and then right click to connect it again. This gives nice GUI feedback about what the system is actually doing, and most of the time results in a proper connection. I don’t even trust double clicks because it’s so finnicky.

It’s also possible that your system just defaults to the wrong output device, do you use pavucontrol to set it to the right output?

Recently, I’ve also been playing with disabling HFP, which has improved matters somewhat, as now at least it always connects to a2dp if it connects at all: https://github.com/TLATER/dotfiles/blob/ad5eb8c91eab5f050c4e9b5af1c31c7ae8c8b969/nixos-config/default.nix#L207

I have no problem so far with pipewire.

My previous config was quite minimal

hardware.bluetooth.enable = true;
sound.enable = true;
hardware.pulseaudio.enable = true;
hardware.pulseaudio.extraConfig = "
load-module module-switch-on-connect
";

Now I use

security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};

as in the docs PipeWire - NixOS Wiki

1 Like

I’ve recently started getting a very similar problem since switch from 23.05 to 23.11

i have bluetooth headphones - they worked perfectly fine with 23.05
but since the switch - bluetooth connects fine, but audio output sometimes appears, sometimes not, sometimes it connects as no-hand-speaker thing and sounds like ass in mono.

only sleep-wake or reboot changes things.

i see no errors in journalctl, just sometimes pulseaudio reports adding new device, sometimes not.

my whole sound-related config is just

sound.enable = true;
hardware.pulseaudio.enable = true;

should I just abandon pulseaudio and try switching to pipewire as @dandanua did? I would save that as last option, since there is clearly some recent bug, as it was working perfectly before 23.11

should I just abandon pulseaudio and try switching to pipewire as @dandanua did? I would save that as last option, since there is clearly some recent bug, as it was working perfectly before 23.11

Why not try switching to pipewire? The switch should be seamless mostly. (I hope at least)

I’ve tried that now, and overall it seems that everything is working.
However it does not feel quite right to just sweep that bug under the rug and pretend it’s not there, at least not if the bug is on nixpkgs side

For me it almost always feels right to sweep a bug under the rug. At least in software. :slight_smile:

Jokes aside, I feel there are bugs that merit more attention than others. And I am not sure if in this case you can find out where the bug comes from in a reasonable amount of time. Might be pulseaudio, might be nixpkgs, might be an issue between your bluetooth device and pulseaudio.

If you think you can figure that out fairly quickly, it might be worth it. I personally would just take the solution and move on happily with pipewire.

I don’t have much knowledge about pulseaudio or how it talks to bluetoothd, so I cannot tell if this is a big thing or not.
If someone with knowledge of those things can look at it and say something like “hey, that’s obvious, this thing is not set up correctly, we just haven’t noticed before”, or if this affects every laptop with bluetooth - then such bug should probably be fixed.
But if it’s more like “I have no idea - it’s something to do with your combination of strange hardware” - then sweeping under the rug is understandable.

Yes my lack of knowledge is also what keeps me from looking deeper into this. I did have trouble with certain bluetooth earbuds (Xiaomi) in the past, and I settled for Samsung GalaxyBuds2 for now. They work fine for me in video calls and for listening to music.

Trying to debug the issues with the Xiaomi earbuds was not fun and didn’t really get me anywhere. So that was my experience with problems related to bluetooth paring or audio profiles and such things.

But maybe at some point someone else might come along and dig it out again. :smiley: