You can open a new issue for discussion or check the existing ones for more information. Please consider that this script doesn't guarantee to support every bluetooth device. If that didn't work, disconnect your device first, and then try again. Try port numbers 1 to 30 to find the one that works for your device. You can set the port number manually by adding a dot at the end of mac address, like this: 00:00:00:00:00:00.3 To query the battery of all connected devices. So you can use bluetooth_battery.py $(bluetoothctl info | awk '/^Device/ ') This shows devices that are actually connected. The 1st and 3rd would be relevant here, as those are headsets. $ bluetoothctl devicesĭevice E8:AB:FA:XX:XX:XX iTeknic IK-BH002 Here is one, this command is in the bluez package, and the given argument gets a list of all devices it knows about, even if not currently available. There are a variety of utilities that can find the MAC address of your bluetooth device. There is also a GNOME extension for integrating this program with GNOME desktop environment: except BatteryQueryError as e : # Handle device is unsupported. You can then from bluetooth_battery import BatteryStateQuerier, BatteryQueryError, BluetoothError # only for error handlingĪnd query the Battery State as follows: # Autodetects SPP port query = BatteryStateQuerier ( "11:22:33:44:55:66" ) # or with given port query = BatteryStateQuerier ( "11:22:33:44:55:66", "4" ) result = int ( query ) # returns integer between 0 and 100 # or result = str ( query ) # returns "0%"."100%"Īs errors can occur in a wireless system, you probably want to handle them: try : query = BatteryStateQuerier ( "11:22:33:44:55:66" ) # Can raise BluetoothError when autodetecting port str ( query ) # Can raise BluetoothError when device is down or port is wrong # Can raise BatteryQueryError when the device is unsupported except BluetoothError as e : # Handle device is offline. To use this as a library, simply install it using pip or AUR (see above) or require it in your Pipfile. You can install this library using yay -S bluetooth-headset-battery-level-git You must have AUR access enabled on your Arch or Manjaro machine. Once the build is complete you can use the below command to run the program: docker run -rm -ti -privileged -net =host bluetooth_battery_level "BT_MAC_ADDRESS" Then run: cd Bluetooth_Headset_Battery_Levelĭocker build -t bluetooth_battery_level. You must have docker installed on your system.Ĭlone the repository using git clone command. Make sure you have python-pybluez or python3-pybluez or python3-bluez installed on your system. Option 2: Download this repository cd Bluetooth_Headset_Battery_Level The dependency pybluez should be installed automatically, but if not, you may need to install it manually You can input addresses for as many devices as you want separated by space. Then, install with pip: pip3 install bluetooth_battery If you are using OpenSUSE, you will need to install bluez, bluez-devel, python3-devel, python3-pybluez Please ensure you have the BlueZ and python libraries and header files if you are using Ubuntu/Debian based distros: sudo apt install libbluetooth-dev python3-dev ▶️ How to run There are four options: Option 1: Install from PyPI You need python 3.6 or newer to run the script. This is a python script to fetch the battery charge level of some Bluetooth headsets.
0 Comments
Leave a Reply. |