Bluetooth_Headset_Battery_Level icon indicating copy to clipboard operation
Bluetooth_Headset_Battery_Level copied to clipboard

Device or resource busy

Open hkpanchani opened this issue 2 years ago • 16 comments

Not working on ubuntu 20.04 with pipewire configuration.


$ bluetooth_battery E4:41:22:AB:AD:D1
Traceback (most recent call last):
  File "<string>", line 3, in connect
_bluetooth.error: (16, 'Device or resource busy')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.local/bin/bluetooth_battery", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.8/site-packages/bluetooth_battery/bluetooth_battery.py", line 163, in main
    print("Battery level for {} is {}".format(device, str(query)))
  File "/home/user/.local/lib/python3.8/site-packages/bluetooth_battery/bluetooth_battery.py", line 93, in __str__
    return "{:.0%}".format(self._perform_query() / 100)
  File "/home/user/.local/lib/python3.8/site-packages/bluetooth_battery/bluetooth_battery.py", line 101, in _perform_query
    sock.connect(self._bt_settings)
  File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: [Errno 16] Device or resource busy

And without pipewire I cant use mic from bluetooth headset so cant switch back.

hkpanchani avatar Mar 15 '22 06:03 hkpanchani

I have the same issue, please someone help us?

Seif-apprentus avatar Apr 18 '22 15:04 Seif-apprentus

I have the same issue, please someone help us?

manishwg avatar May 13 '22 10:05 manishwg

I have the same issue on Arch Linux with kernel version 5.15.41-1-lts

thienandangthanh avatar May 25 '22 02:05 thienandangthanh

I have same issue too

alexandremsouza1 avatar Jul 28 '22 12:07 alexandremsouza1

Me too (on Fedora 36 with Pipewire).

mirenradia avatar Aug 12 '22 08:08 mirenradia

Python 3.10.4 Ubuntu 22.04.1 File "./Bluetooth_Headset_Battery_Level/bluetooth_battery.py", line 101, in _perform_query sock.connect(self._bt_settings) File "", line 5, in connect bluetooth.btcommon.BluetoothError: [Errno 16] Device or resource busy

But it worked on Ubuntu 20.04 earlier.

Plaque-fcc avatar Aug 13 '22 00:08 Plaque-fcc

Did you try disconnecting the device before running the script?

Sorry for the late response. I'm currently super busy with work.

TheWeirdDev avatar Aug 13 '22 04:08 TheWeirdDev

Did you try disconnecting the device before running the script?

Sorry for the late response. I'm currently super busy with work.

I changed the version of setuptools as a workaround from #83. Then I installed the version of pybluez as a workaround from #78. And only then the script started to work, finally.

Plaque-fcc avatar Aug 15 '22 21:08 Plaque-fcc

For anyone else having this issue (which for me showed up after upgrading from debian bullseye to bookworm), I've found a workaround:

Before reading battery level, disconnect from the device using bluetoothctl, then reconnect after. I've wrapped this in a shell script for ease of use.

It's annoying that I can no longer read battery level during an active connection, but it's better than nothing!

jpollack avatar Sep 28 '22 22:09 jpollack

That's literally in the 'Readme' that no one reads 🤦‍♂️

TheWeirdDev avatar Sep 29 '22 03:09 TheWeirdDev

I used the toggle button in settings to disconnect the device and connected it again. But, no matter what I do, I get this error again. :(

Even used the " bluetoothctl " command as suggested above.

Using Ubuntu 22.04. Thanks

meetdilip avatar Sep 29 '22 06:09 meetdilip

Fedora 36, after I disconnect "Jabra Evolve 65" it gets few lines of code further but still:

Traceback (most recent call last):
  File "/tmp/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 166, in <module>
    main()
  File "/tmp/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 163, in main
    print("Battery level for {} is {}".format(device, str(query)))
  File "/tmp/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 93, in __str__
    return "{:.0%}".format(self._perform_query() / 100)
  File "/tmp/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 105, in _perform_query
    sock.send(b"+BRSF: 1024")
  File "/tmp/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 66, in send
    return super().send(b"\r\n" + data + b"\r\n")
  File "<string>", line 5, in send
bluetooth.btcommon.BluetoothError: [Errno 14] Bad address

jankratochvil avatar Oct 18 '22 10:10 jankratochvil

I had the same issue. It was resolved for me by following this advice, or rather the way it's done here. I.e.:

  • Create folder /etc/systemd/system/bluetooth.service.d/ if not already existent
  • Edit file /etc/systemd/system/bluetooth.service.d/override.conf to be:
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd --experimental
  • Load the new config with: sudo systemctl daemon-reload
  • Restart bluetooth with: sudo systemctl restart bluetooth
  • Restart/reconnect bluetooth headphones

Now bluetooth_battery tool works again for me (or rather, I still have to run it twice or thrice sometimes to get an output, but at least i can somehow get the battery status of my headphones eventually).

Garbaz avatar Nov 22 '22 10:11 Garbaz

I had the same issue. It was resolved for me by following this advice, or rather the way it's done here. I.e.:

* Create folder `/etc/systemd/system/bluetooth.service.d/` if not already existent

* Edit file `/etc/systemd/system/bluetooth.service.d/override.conf` to be:
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd --experimental
* Load the new config with: `sudo systemctl daemon-reload`

* Restart bluetooth with: `sudo systemctl restart bluetooth`

* Restart/reconnect bluetooth headphones

Now bluetooth_battery tool works again for me (or rather, I still have to run it twice or thrice sometimes to get an output, but at least i can somehow get the battery status of my headphones eventually).

Tried this, no luck :(

meetdilip avatar Jan 05 '23 09:01 meetdilip

@meetdilip Enabling experimental features in BlueZ allows PulseAudio 16.0 and PipeWire 0.3.34 to report battery status for the device back to it, on recent versions. It does so based on the most common AT commands similar to this script, hence you won't need / should not use this script at all anymore (and BlueZ will itself propagate battery information if a battery GATT or similar is available).

(You will need "some" utility that reads out the battery status from BlueZ and/or UPower[^1] over DBus, though. For i3blocks I've made my own: https://github.com/MarijnS95/i3blocks-contrib/blob/master/bluetooth-battery/bluetooth-battery, and other WMs may display extra battery icons for devices listed by UPower)

[^1]: For completeness: UPower picks up and propagates reported battery levels for Bluetooth devices when exposed by BlueZ over DBus


@TheWeirdDev perhaps it is time to start pointing users towards this in the README, as it effectively deprecates this script and perhaps even conflicts with it?

See the relevant changelog items in PulseAudio 16.0: https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/16.0/#bluetoothdevicebatterylevelreportingadded https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/16.0/#bluetoothbatterylevelreportingviabluezrequiresenablingexperimentalsfeaturesinbluez

And for PipeWire I'm unsure if it landed 0.3.34 or 0.3.24 already.

MarijnS95 avatar Jan 10 '23 21:01 MarijnS95

I had the same issue. It was resolved for me by following this advice, or rather the way it's done here. I.e.:

* Create folder `/etc/systemd/system/bluetooth.service.d/` if not already existent

* Edit file `/etc/systemd/system/bluetooth.service.d/override.conf` to be:
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd --experimental
* Load the new config with: `sudo systemctl daemon-reload`

* Restart bluetooth with: `sudo systemctl restart bluetooth`

* Restart/reconnect bluetooth headphones

Now bluetooth_battery tool works again for me (or rather, I still have to run it twice or thrice sometimes to get an output, but at least i can somehow get the battery status of my headphones eventually).

Thanks a lot @Garbaz ! I've been looking for this for soo long... This not only solved the issue with this python script not being able to connect to some devices, but also added the missing bluetooth devices to the "Power" tab in GNOME Settings. Cheers!

zheltikov avatar Jul 25 '23 15:07 zheltikov