TheWeirdDev / Bluetooth_Headset_Battery_Level

A python script to get battery level from Bluetooth headsets
GNU General Public License v3.0
766 stars 80 forks source link

bluetooth.btcommon.BluetoothError: [Errno 16] Device or resource busy #92

Closed da-the-dev closed 1 year ago

da-the-dev commented 1 year ago

I've cloned the repo and ran the script, but it crashes with this error

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/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 166, in <module>
    main()
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 163, in main
    print("Battery level for {} is {}".format(device, str(query)))
                                                      ^^^^^^^^^^
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 93, in __str__
    return "{:.0%}".format(self._perform_query() / 100)
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./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

What is this error and how to resolve it?

TheWeirdDev commented 1 year ago

Disconnect your device, then run the script.

da-the-dev commented 1 year ago

Ok, I did disconnect the device and just have it nearby, now when I run the script I get this

Traceback (most recent call last):
  File "<string>", line 3, in send
_bluetooth.error: (14, 'Bad address')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 166, in <module>
    main()
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 163, in main
    print("Battery level for {} is {}".format(device, str(query)))
                                                      ^^^^^^^^^^
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 93, in __str__
    return "{:.0%}".format(self._perform_query() / 100)
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/sv-cheats-1/Git-installed apps/Bluetooth_Headset_Battery_Level/./bluetooth_battery.py", line 105, in _perform_query
    sock.send(b"+BRSF: 1024")
  File "/home/sv-cheats-1/Git-installed apps/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

I took the MAC address from Blueman. I'm trying to read the battery level of my Airpods Pro 2, if that helps.

TheWeirdDev commented 1 year ago

This code does not support AirPods or any headphones with a custom/proprietary protocol. You can check out other projects that are written specifically for AirPods:

https://github.com/faglo/AirStatus https://github.com/delphiki/gnome-airpods-battery-status https://github.com/SpriteOvO/AirPodsDesktop