Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device or resource busy #77

Open
hkpanchani opened this issue Mar 15, 2022 · 16 comments
Open

Device or resource busy #77

hkpanchani opened this issue Mar 15, 2022 · 16 comments

Comments

@hkpanchani
Copy link

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.

@Seif-apprentus
Copy link

I have the same issue, please someone help us?

1 similar comment
@manishwg
Copy link

I have the same issue, please someone help us?

@thienandangthanh
Copy link

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

@alexandremsouza1
Copy link

I have same issue too

@mirenradia
Copy link

Me too (on Fedora 36 with Pipewire).

@Plaque-fcc
Copy link

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.

@TheWeirdDev
Copy link
Owner

Did you try disconnecting the device before running the script?

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

@Plaque-fcc
Copy link

Plaque-fcc commented Aug 15, 2022

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.

@jpollack
Copy link

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!

@TheWeirdDev
Copy link
Owner

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

@meetdilip
Copy link

meetdilip commented Sep 29, 2022

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

@jankratochvil
Copy link

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

@Garbaz
Copy link

Garbaz commented Nov 22, 2022

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).

@meetdilip
Copy link

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 :(

@MarijnS95
Copy link

@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 UPower1 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)


@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.

Footnotes

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

@zheltikov
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests