TheWeirdDev / Bluetooth_Headset_Battery_Level

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

Problem with Device is Offline error #58

Open mhkarimi1383 opened 3 years ago

mhkarimi1383 commented 3 years ago

When I want to get my headphone battery I Get this error <Device MAC> is offline [Errno 16] Device or resource busy

And please update gnome extension for gnome 40

rds8rds commented 3 years ago

When I want to get my headphone battery I Get this error <Device MAC> is offline [Errno 16] Device or resource busy

And please update gnome extension for gnome 40

Does it work on the older gnome desktop, like 3.38. I faced the same error.

barak commented 3 years ago

Used to work for me as well, now I get this.

$ bluetoothctl info
Device E8:AB:FA:27:9F:49 (public)
    Name: iTeknic IK-BH002
    Alias: Black Noise-Cancelling (iTeknic IK-BH002)
    Class: 0x00240418
    Icon: audio-card
    Paired: yes
    Trusted: yes
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
    UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    Modalias: bluetooth:v000ApFFFFdFFFF

$ ~/src/git/Bluetooth_Headset_Battery_Level/bluetooth_battery.py E8:AB:FA:27:9F:49
E8:AB:FA:27:9F:49 is offline [Errno 111] Connection refused
mhkarimi1383 commented 3 years ago

I think it's not compatible with some devices mine is Anker Sound buds lite

mhkarimi1383 commented 3 years ago

Used to work for me as well, now I get this.

$ bluetoothctl info
Device E8:AB:FA:27:9F:49 (public)
  Name: iTeknic IK-BH002
  Alias: Black Noise-Cancelling (iTeknic IK-BH002)
  Class: 0x00240418
  Icon: audio-card
  Paired: yes
  Trusted: yes
  Blocked: no
  Connected: yes
  LegacyPairing: no
  UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
  UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
  UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
  UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
  UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
  UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
  UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
  Modalias: bluetooth:v000ApFFFFdFFFF

$ ~/src/git/Bluetooth_Headset_Battery_Level/bluetooth_battery.py E8:AB:FA:27:9F:49
E8:AB:FA:27:9F:49 is offline [Errno 111] Connection refused

same here

Kronodile commented 3 years ago

Hi, try connecting to a different port. For example bluetooth_battery.py E8:AB:FA:27:9F:49.1 Try manually changing the numbers from 1 to 30 after period (.)

barak commented 3 years ago

@Kronodile That didn't help for me, but bluetoothctl disconnect E8:AB:FA:27:9F:49 followed by bluetooth_battery.py E8:AB:FA:27:9F:49 both got the battery level and reconnected it. And then it worked, and battery queries also worked.

jrvgr commented 2 years ago

@Kronodile That didn't help for me, but bluetoothctl disconnect E8:AB:FA:27:9F:49 followed by bluetooth_battery.py E8:AB:FA:27:9F:49 both got the battery level and reconnected it. And then it worked, and battery queries also worked.

i also have this issue

dark-dryu commented 2 years ago

@Kronodile That didn't help for me, but bluetoothctl disconnect E8:AB:FA:27:9F:49 followed by bluetooth_battery.py E8:AB:FA:27:9F:49 both got the battery level and reconnected it. And then it worked, and battery queries also worked.

i also have this issue

same here, but the battery queries did not work afterwards

lakinduakash commented 2 years ago

@Kronodile That didn't help for me, but bluetoothctl disconnect E8:AB:FA:27:9F:49 followed by bluetooth_battery.py E8:AB:FA:27:9F:49 both got the battery level and reconnected it. And then it worked, and battery queries also worked.

This is what worked for me

VanillaBase1lb commented 2 years ago

@Kronodile That didn't help for me, but bluetoothctl disconnect E8:AB:FA:27:9F:49 followed by bluetooth_battery.py E8:AB:FA:27:9F:49 both got the battery level and reconnected it. And then it worked, and battery queries also worked.

i also have this issue

This worked for me too

VoidPhantom commented 2 years ago

I am observing the same problem after upgrading to Ubuntu 21.10. To be clear, the Gnome extension that uses this script — and, therefore, presumably, the script itself — used to work just fine with Ubuntu 21.04 up until I upgraded to Ubuntu 21.10.

Now, if I connect my Bluetooth headphones and run the script, it gives the following error:

[REDACTED] is offline [Errno 16] Device or resource busy

If I try manually specifying ports from 1 to 30, it gives the same error with port 4, and with any other port is gives the following error:

[REDACTED] is offline [Errno 111] Connection refused

If I disconnect the headphones and run the script, then it suddenly works! But, unlike reported by others above, this does not fix the issue for me. If I run the script while the headphones are disconnected, it successfully returns a charge level, and the headphones say, “Bluetooth disconnected,” and remain disconnected. It seems that the script briefly connects to the headphones, requests the charge level, and then disconnects. If I then reconnect the headphones, the script still gives the same error while the headphones are connected.

Interestingly, this problem appears to be somewhat intermittent: while testing again in order to write this comment, for a brief moment the script actually managed to work correctly and report the battery charge level while the headphones were connected! I wasn’t able to reproduce this, though; the scenario I described above is still the only thing that happens reliably.

adi-g15 commented 2 years ago

I also faced the problem, for some devices (my headphone atleast), it fails to establish a connection, I wrote this script to do the same, just disconnect for a moment, check battery, then connect back again (if you don't want to, edit it to add some, say a flag):

#!/usr/bin/python
import re
import sys
import os
from bluetooth_battery.bluetooth_battery import main
if __name__ == '__main__':
    os.system("bluetoothctl disconnect "+ sys.argv[1])
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    main()
    os.system("bluetoothctl connect "+ sys.argv[1])

And save it as 'bluetooth_battery' in ~/.local/bin... done :D

im-n1 commented 2 years ago

Exactly the same issue.

image

The thing is you dont wanna disconnect from the headphones as you are listening to a music.