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

Connection refused when in use for a while #51

Open sb-child opened 3 years ago

sb-child commented 3 years ago

Hi. When my earphone connect to my laptop just now, the script works fine. But use earphone for a while, run the script will return an error. And the earphone is still can be used.

Connected

$ bluetooth_battery 41:42:AB:1E:24:01
Battery level for 41:42:AB:1E:24:01 is 60%

listen to music for a while

$ bluetooth_battery 41:42:AB:1E:24:01
41:42:AB:1E:24:01 is offline [Errno 111] Connection refused

the Bluetooth info

$ bluetoothctl info                                                              
Device 41:42:AB:1E:24:01 (public)
        Name: i12
        Alias: i12
        Class: 0x00240418
        Icon: audio-card
        Paired: yes
        Trusted: yes
        Blocked: no
        Connected: yes
        LegacyPairing: no
        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)
Gavinok commented 3 years ago

Been having the same issue I just have it disconnect from my headphones then run this script. Not perfect but it works until we get something better.

munir131 commented 3 years ago

@Gavinok disconnect didn't work for me on Manjaro

nexhub commented 3 years ago

I've got the same problem and the workaround is working. Reconnect resolves the problem. I'd suspect that it's is related to the underlying bluetooth software/driver stack. Battery level querying works in Android even after hours of being connected. This kind of rules out that it's a bug of the headphones.

My bluez version is 5.53-0ubuntu3. Would be interesting if there's anyone not encountering this problem with v5.53. I'm using a Thinkpad T480s which ships with Intel bluetooth hardware: intel/ibt-12-16.sfi(found in dmesg). @sb-child @Gavinok whats your bluez version and bluetooth driver?

I've also found a couple of these messages in my dmesg output, but I'm not sure if they are related to the problem as it is working now after a reconnect. I will try to verify later. [ 6986.966798] Bluetooth: hci0: SCO packet for unknown connection handle 0

% bluetoothctl info   
Device 02:02:00:80:51:73 (public)
    Name: TAOTRONICS SoundElite 72
    Alias: TAOTRONICS SoundElite 72
    Class: 0x00240418
    Icon: audio-card
    Paired: yes
    Trusted: yes
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
    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: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    Modalias: bluetooth:v000ApFFFFdFFFF
    RSSI: -35
    TxPower: 4
[CHG] Device 76:97:AD:96:2E:57 RSSI: -75