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

Couldn't find the RFCOMM port number. Perhaps the device is offline? #82

Open poopman97 opened 2 years ago

poopman97 commented 2 years ago

When I do the command I get this error

bluetooth_battery 43:00:00:00:00:68  1 ✘  5s  Traceback (most recent call last): File "/usr/local/bin/bluetooth_battery", line 33, in <module> sys.exit(load_entry_point('bluetooth-battery==1.3.2', 'console_scripts', 'bluetooth_battery')()) File "/usr/lib/python3.10/site-packages/bluetooth_battery/bluetooth_battery.py", line 162, in main query = BatteryStateQuerier(*device.split(".")) File "/usr/lib/python3.10/site-packages/bluetooth_battery/bluetooth_battery.py", line 81, in __init__ self._bt_settings = bluetooth_mac, int(bluetooth_port or RFCOMMSocket.find_rfcomm_port(bluetooth_mac)) File "/usr/lib/python3.10/site-packages/bluetooth_battery/bluetooth_battery.py", line 60, in find_rfcomm_port raise bluetooth.BluetoothError("Couldn't find the RFCOMM port number. Perhaps the device is offline?") bluetooth.btcommon.BluetoothError: Couldn't find the RFCOMM port number. Perhaps the device is offline?

Tbh I don't know what to say more, hope this can get fixed!

TheWeirdDev commented 2 years ago

What Bluetooth device do you have? Did you try the workarounds mentioned in the readme?

ishmeet1995 commented 2 years ago

Getting same error, @TheWeirdDev I am using Bluetooth Headset

Command - bluetooth_battery B4:0E:DE:95:7C:9C

Response - Traceback (most recent call last): File "/home/ishmeet1995/anaconda3/bin/bluetooth_battery", line 8, in <module> sys.exit(main()) File "/home/ishmeet1995/anaconda3/lib/python3.9/site-packages/bluetooth_battery/bluetooth_battery.py", line 162, in main query = BatteryStateQuerier(*device.split(".")) File "/home/ishmeet1995/anaconda3/lib/python3.9/site-packages/bluetooth_battery/bluetooth_battery.py", line 81, in __init__ self._bt_settings = bluetooth_mac, int(bluetooth_port or RFCOMMSocket.find_rfcomm_port(bluetooth_mac)) File "/home/ishmeet1995/anaconda3/lib/python3.9/site-packages/bluetooth_battery/bluetooth_battery.py", line 60, in find_rfcomm_port raise bluetooth.BluetoothError("Couldn't find the RFCOMM port number. Perhaps the device is offline?") bluetooth.btcommon.BluetoothError: Couldn't find the RFCOMM port number. Perhaps the device is offline?

Kr3shnik commented 2 years ago

it also happened to me. Im not entierly sure if this repo supports HCI bluetooth devices (another connection method similar to rfcomm). To check you can run hcitool dev. Note that this command doesnt always work.

You can also use udevadm monitor and during this command dissconnect and reconnect the device.

In my case it was: /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:256

AkechiShiro commented 1 year ago

@TheWeirdDev I'm running on this issue using a bluetooth keyboard Keychron K7, can you please help me, understand what I can do to fix either the script or find the out the battery level ?

AkechiShiro commented 1 year ago

Here is what I found out by using hcitool :

Requesting information ...
    BD Address:  DC:2C:26:3A:64:00
    OUI Company: Iton Technology Limited (DC-2C-26)
    Device Name: Keychron K7
    LMP Version: 5.1 (0xa) LMP Subversion: 0x2304
    Manufacturer: Cypress Semiconductor (305)
    Features page 0: 0xbf 0x06 0x86 0x78 0x18 0x1e 0x59 0x87
        <3-slot packets> <5-slot packets> <encryption> <slot offset> 
        <timing accuracy> <role switch> <sniff mode> <RSSI> 
        <channel quality> <paging scheme> <power control> 
        <broadcast encrypt> <enhanced iscan> <interlaced iscan> 
        <interlaced pscan> <inquiry with RSSI> <AFH cap. perip.> 
        <AFH cls. perip.> <sniff subrating> <pause encryption> 
        <AFH cap. central> <AFH cls. central> <extended inquiry> 
        <simple pairing> <encapsulated PDU> <non-flush flag> <LSTO> 
        <inquiry TX power> <EPC> <extended features> 
    Features page 1: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
AkechiShiro commented 1 year ago

Okay so I confirmed the battery level can be reported : image