GithubHelp home page GithubHelp logo

theweirddev / bluetooth_headset_battery_level Goto Github PK

View Code? Open in Web Editor NEW
756.0 15.0 82.0 122 KB

A python script to get battery level from Bluetooth headsets

License: GNU General Public License v3.0

Python 95.79% Dockerfile 4.21%
bluetooth bluetooth-headsets bluetooth-devices battery-level battery-percentage battery headset linux socket python at-command bluetooth-socket bluetooth-speaker bluez headphones bluetooth-headphones python-script pybluez

bluetooth_headset_battery_level's Introduction

๐Ÿ”‹๐ŸŽง Bluetooth Headset Battery Level

This is a python script to fetch the battery charge level of some Bluetooth headsets.

You need python 3.6 or newer to run the script.

Table of Contents

โ–ถ๏ธ How to run

There are four options:

Option 1: Install from PyPI

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

If you are using OpenSUSE, you will need to install bluez, bluez-devel, python3-devel, python3-pybluez

Then, install with pip:

pip3 install bluetooth_battery

bluetooth_battery BT_MAC_ADDRESS_1 ...

You can input addresses for as many devices as you want separated by space.

the dependency pybluez should be installed automatically, but if not, you may need to install it manually


Option 2: Download this repository

cd Bluetooth_Headset_Battery_Level
chmod +x bluetooth_battery.py

./bluetooth_battery.py BT_MAC_ADDRESS_1 ...

make sure you have python-pybluez or python3-pybluez or python3-bluez installed on your system.


Option 3: Docker

You must have docker installed on your system. Clone the repository using git clone command. Then run:

cd Bluetooth_Headset_Battery_Level
docker build -t bluetooth_battery_level .

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"

Option 4: AUR

You must have AUR access enabled on your Arch or Manjaro machine. You can install this library using

yay -S python-bluetooth-battery

the dependency pybluez should be installed automatically, but if not, you may need to install it manually
This can be done with pip3 install git+https://github.com/pybluez/pybluez@master.


Library usage

To use this as a library, simply install it using pip or AUR (see above) or require it in your Pipfile.
You can then

from bluetooth_battery import BatteryStateQuerier, BatteryQueryError, BluetoothError
                                                   # only for error handling

and 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%"
# or
result = query.query()  # returns a dictonary, e.g. {'overall': 100, 'left': 100, 'right': 100, 'case': 87}

As 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
    ...
except BatteryQueryError as e:
    # Handle device is unsupported
    ...

GNOME Extension

There is also a GNOME extension for integrating this program with GNOME desktop environment: https://extensions.gnome.org/extension/3991/bluetooth-battery/

Budgie Applet

There is also a Budgie extension for integrating this program with Budgie desktop environment: https://github.com/GaLaXy102/budgie-bluetooth-battery-applet

Finding MAC address

There are a variety of utilities that can find the MAC address of your bluetooth device. 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.

$ bluetoothctl devices
Device E8:AB:FA:XX:XX:XX iTeknic IK-BH002
Device D0:77:14:XX:XX:XX Barak's Moto X4
Device E8:AB:FA:XX:XX:XX iTeknic IK-BH002

The 1st and 3rd would be relevant here, as those are headsets.

This shows devices that are actually connected.

$ bluetoothctl info
Device E8:AB:FA:XX:XX:XX (public)
	Name: iTeknic IK-BH002
	...

So you can use

bluetooth_battery.py $(bluetoothctl info | awk '/^Device/ {print $2}')

to query the battery of all connected devices.

It didn't work?

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

Try port numbers 1 to 30 to find the one that works for your device. (wait a few seconds between each try)

If that didn't work, disconnect your device first, and then try again.

Still doesn't work?

Please consider that this script doesn't guarantee to support every bluetooth device.

You can open a new issue for discussion or check the existing ones for more information.

Tested on

  • ArchLinux (5.6.14)
  • Manjaro (5.14.10)
  • NixOS 20.09 (20.09.2386.ae1b121d9a6)
  • Debian GNU/Linux (bullseye 5.9)
  • Ubuntu/Linux (Focal Fossa 20.04.1)
  • openSUSE (Leap 15.3)

๐Ÿค Thanks

Special thanks to:

@clst: For spreading the word!

@bhepple: For his research on fixing the important bug

@balsoft: For thinking outside the box (finding my big mistake)

@martin-beran: For making it easy to set the port number

@Bobo1239: For adding support for Samsung galaxy buds

@keystroke3: For adding multiple device support to the script

@jadia: For docker container support

@cheriimoya: For refactoring the code and providing NixOS packages

@MichalW: For making the GNOME shell extension

@GaLaXy102: For re-writing the code, making it cleaner and usable as a library

@drinkcat: For adding support for Nearby/FastPair protocol

โค๏ธ And everyone else that pointed out the issues or helped me with writing the code or testing it.

๐Ÿ“œ License

This project is a free software licensed under GPL-3.0 or newer. For more information see LICENSE

bluetooth_headset_battery_level's People

Contributors

archwand avatar atleta avatar barak avatar bobo1239 avatar delaosa avatar drinkcat avatar galaxy102 avatar icewind1991 avatar ikoga avatar jadia avatar keystroke3 avatar martin-beran avatar sesse avatar steam3d avatar theweirddev avatar tomhutter avatar wtong98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluetooth_headset_battery_level's Issues

Container does seems not to work

As I had no success via PIP I thought, letยดs try a container as there are the libs guranteed.

I created the container and faced no issue during building but I can not run it not as user nor as root.
I always get the following error (regardles if root or user):

podman run --rm -ti --privileged --net=host bluetooth_battery_level 88:D0:39:BB:4A:76

[2] Error loading Python lib '/tmp/_MEIx6iKbm/libpython3.9.so.1.0': dlopen: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /tmp/_MEIx6iKbm/libpython3.9.so.1.0)

as_user.log
as_root.log

[Feature request] UPower integration?

Would be nice to have this as a daemon that could report battery level to UPower (so that it could in turn be picked up be the DE and shown in the local battery reporting applet)

Sony WH-1000XM4

With the Sony WH-1000XM4, the script seems to get stuck in the while loop.

while get_at_command(sock, sock.recv(128), device):

I don't see any error messages until I manually force quit it. My assumption is that the WH-1000XM4 might either require other values to be sent first or there is another variable to be read.

I will try to debug it further and in case I'll find out more will post it here.

disconnected/connected messsages

Every time the script is run, the headset is connected and then disconnected - and this model (Audeara A-10) - tells you so via the cans! It's a bit disconcerting when listening to music and it prevents the use of the script in a monitor eg "check every 30s and pop up a warning when <10%"

@ChaosCreator mentioned this in #33 I think, but I thought I'd raise this as a separate issue.

I thought I'd try and remove some of the bluetooth dialog and see if affected the outcome, hoping that it would eliminate the annoying 'connected/disconnected' messages. This was the minimal dialog that works for me:

R: b'AT+BRSF=959\r'
S: b'+BRSF: 1024'
S: b'OK'
R: b'AT+CIND=?\r'
S: b'OK'
R: b'AT+CIND?\r'
S: b'OK'
R: b'AT+CMER=3, 0, 0, 1\r'
S: b'OK'
R: b'AT+BIND=2\r'
S: b'OK'
R: b'AT+BIND=?\r'
S: b'OK'
R: b'AT+BIND?\r'
S: b'OK'
R: b'AT+VGS=10\r'
S: b'OK'
R: b'AT+BTRH?\r'
S: b'OK'
R: b'AT+XAPL=0000-0000-0100,7\r'
S: b'OK'
R: b'AT+IPHONEACCEV=2,1,7,2,0\r'
Battery level for F0:23:B9:50:CA:54 is 80%

... but it doesn't remove the connection messages!

close socket

What is the proper way to close the socket, in case I want to use it twice?:

s = socket.socket(socket.AF_BLUETOOTH,
            socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)

Inconsistent values

I am trying to turn the script to a Polybar module so that I can have the battery information there. I have been successful in getting the values, and have made a few changes so that it shows an icon instead of just the level. Problem is, the values are not consistent. When I run this, it keeps flipping between two values e.g. 70 and 80%. I do not fully understand how the script works, so a little elaboration may help me understand.

SyntaxError: invalid syntax

File "./bl_battery.py", line 42
    print(f"Battery level for {device} is {blevel}%")
                                                   ^
SyntaxError: invalid syntax

My syntax is ./bl_battery.py 00:00:00:00:00:00

Gnome 40

Would be good if u create version for gnome 40. Is there any plans?

Problem with Device is Offline error

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

s.recv(128) gets stuck (line 81)

Hi,
I have been wanting something like this for a long time, so thank you for making this.

I have a Jabra 65e bluetooth headset. It shows the battery level when I connect to my phone. When I run this script however, for every port other than 3, I get an Errno 111 Connection refused.

However, when I run it with port 3, the script gets stuck. Specifically, the s.recv(128) function does not return in the while loop on line 81.

I don't know anything about low level network interfaces, so can you help me figure out what might be going wrong?

Thanks a lot!

Reversing Mpow flame S

I have an MPow flame 2 and a flame S now. The S shows battery level in android. How can figure out the commands needed to make it work? Script always returns connection refused or device busy on all ports.

White LED when powered up is gone now

Well, this is more a support issue but I don't know where to ask.

I had to disconnect my JBL bluetooth earbuds to get battery level like said in issue #58

But now, when the device is powered up but not connected the white LED is gone. You can see it flashing very dimly, when the device is disconnected but it is off after that.

The white LED is laso off (not visible) when you power up the device after that.

How can I get it back on when the deivce is powered up but not connected.

The LED is blue when connected.

Moreover, now, when you power it up, it automatically connect to the last bluetooth device it was connected to, instead of waiting a connection, whit the white LED on.

Device becomes unresponsive when switching bluetooth profile

I'm trying to create a script that checks the battery status at regular intervals. My headphone also has a mic so I have to switch Bluetooth profile from A2DP to HSP/HFP since A2DP doesn't allow mic and speaker to work simultaneously. Since the release of Pulseaudio v. 11.0 this profile switching can be performed automatically. (I've followed this guide to do so. It works.)
But if the script runs while I'm on HSP/HFP profile the headphones become unresponsive. I have to restart the headphone to get them working. Any workarounds?

Sony WH-1000XM3 Connection refused on first connect

When running the script for the first time after connecting the headset, it fails with an OSError:

$ ./bluetooth_battery.py 38:18:4C:XX:XX:XX
38:18:4C:XX:XX:XX is offline (111, 'Connection refused')

The headset is properly connected and my laptop is transmitting sound, no problems there.
If i run the script again it works as intended, also for any subsequent executions of the program...
I don't know much about bluetooth at this point, but my guess would be that the socket is somehow not properly connecting (just a random guess).

Misleading documentation: port number can be outside of 1-9 range

As stated in the readme:

Try port numbers 1 to 9 to find the one that works for your device. (wait a few seconds between each try)

However, my WH-1000XM3 works when I specify port number 10 (and doesn't work for any port in 1-9 range). CC @chaoscreater BTW, try disconnecting, reconnecting and then running ./bluetooth_battery <MAC>.10 . I suspect this may also be true for other headsets.

Bluetooth Device offline

OS: Lubuntu with latest updates
Bluetooth device: iHome speaker

When I run your script it gives the following output:

$lucas:~$ ./bl_battery.py FC:58:FA:EA:74:FC
FC:58:FA:EA:74:FC is offline

However the device is certainly online, I'm playing music from it now. Here it is on here:
Blueman Wiz

Any ideas why this is happening?

Connection Refused [Ubuntu 19.10] [JBL T450BT]

I've been getting this traceback while running:

adil@adil-GL552JX:~/Bluetooth_Headset_Battery_Level$ ./bl_battery.py 30:C0:1B:E9:55:DB
Traceback (most recent call last):
  File "./bl_battery.py", line 62, in <module>
    main()
  File "./bl_battery.py", line 56, in main
    s.connect((BT_ADDRESS, 4))
ConnectionRefusedError: [Errno 111] Connection refused
adil@adil-GL552JX:~/Bluetooth_Headset_Battery_Level$ sudo ./bl_battery.py 30:C0:1B:E9:55:DB
[sudo] password for adil: 
Traceback (most recent call last):
  File "./bl_battery.py", line 62, in <module>
    main()
  File "./bl_battery.py", line 56, in main
    s.connect((BT_ADDRESS, 4))
ConnectionRefusedError: [Errno 111] Connection refused

Tried with and without sudo.

Collect known devices and their respective settings

Awesome script!

However, it's quite cumbersome to set up for use with multiple devices, each of which may need a different port, or may need some other hacks (like #23). Perhaps it would be a good idea to collect a list of such known devices and their settings somewhere, and then use that list to figure out what to do? The obvious place to put it would be here, in this repo.

apple air pods

cant seem to get info for apple air pods
just hangs. following errors

root@ArchMan ~ # bluetooth_battery.py 14:88:E6:B5:47:2E.7
Traceback (most recent call last):
File "/root/.bin/bluetooth_battery.py", line 119, in
main()
File "/root/.bin/bluetooth_battery.py", line 111, in main
while get_at_command(sock, sock.recv(128), device):
File "", line 3, in recv

System reports syntax error

Installed using pip method.

$ bluetooth_battery 00:00:00:00:00:00
Traceback (most recent call last):
  File "/home/kelvin/.local/bin/bluetooth_battery", line 9, in <module>
    load_entry_point('bluetooth-battery==1.2.0', 'console_scripts', 'bluetooth_battery')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/kelvin/.local/lib/python3.5/site-packages/bluetooth_battery/bluetooth_battery.py", line 59
    print(f"Battery level for {device} is {blevel}%")
                                                   ^
SyntaxError: invalid syntax

Windows compilation

I tried to install on Windows using pip install bluetooth-battery. But I get a "Microsoft Visual C++ 14.0 or greater is required" error. Before I go to the trouble of installing MSVC to install this tiny package, has anyone here successfully compiled this under Windows, and if so what steps do I need to take to do it? (And is it possible to get a pre-compiled version?)

ModuleNotFoundError bluetooth

On ubuntu 20.04

python3 bluetooth_battery.py 
Traceback (most recent call last):
  File "bluetooth_battery.py", line 12, in <module>
    import bluetooth
ModuleNotFoundError: No module named 'bluetooth'

Script needs to disconnect the device first

Great project, thanks for your work.

That being said, the script seems to have an issue that it requires you to disconnect from the Bluetooth device first, then connect through it by launching your using ./bluetooth_battery.py <MAC ID>. Is there a way to automate this process, so that it does not require you to manually disconnect first?

Thanks.

Connection refused for BLE_ATH-M50xBT

bluetooth_battery 00:0A:45:0B:5C:5C
00:0A:45:0B:5C:5C is offline [Errno 111] Connection refused

Then i tried this:

bluetooth_battery 00:0A:45:0B:5C:5C.1
00:0A:45:0B:5C:5C is offline [Errno 16] Device or resource busy

Before that, I went into bluetoothctl to get the correct address

[BLE_ATH-M50xBT]# info
Device 00:0A:45:0B:5C:5C (public)
	Name: BLE_ATH-M50xBT
	Alias: BLE_ATH-M50xBT
	Class: 0x00240418
	Icon: audio-card
	Paired: yes
	Trusted: yes
	Blocked: no
	Connected: yes
	LegacyPairing: no

Compatible with Mac OS X?

@TheWeirdDev Does this library work on Mac? I'm getting "module 'socket' has no attribute 'AF_BLUETOOTH'"

It seems like there's no easy way to install python with bluetooth support on mac os x or install libbluetooth-dev. Any help would be much appreciated!

Instead of percentage the word "down" is present

I get the word "down" instead of percentage, I know that is something I have done/not done, but would you know right off?

I installed using Option 1 on your git page. (https://github.com/TheWeirdDev/Bluetooth_Headset_Battery_Level/tree/bbfa282e4e231f3b74eb7d59a151bdb37bdb4c4d)

OS: Ubuntu 20.10 x86_64
Host: N141CU
Kernel: Linux 5.8.0-44-generic
Uptime: 10m
Packages: 2479 (dpkg), 9 (snap)
Shell: /bin/bash 5.0.17
Resolution: 1920x1080 @ 59.93Hz
DE: GNOME 3.38.2
WM: Mutter
WM Theme: Adwaita
Theme: Yaru-dark
Icons: ubuntu-mono-dark
Terminal: gnome-terminal
CPU: Intel i7-10510U (8) @ 4.900GHz [52.0ยฐC]
GPU: Intel UHD Graphics
Memory: 2.46GiB / 15.33GiB (16%)

Issue installing

I've got this working on an old Win10 machine and that's all good. But on a new Win10 machine (same Win10 build 1909) with the same Python version (3.7.2), I can't seem to get this to run.

When running this:
bluetooth_battery cc:98:8b:56:8c:ad

I get this:

PS C:\Users\Ricky\pybluez-0.23> bluetooth_battery cc:98:8b:56:8c:ad                                                                                           Traceback (most recent call last):
  File "c:\users\ricky\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\ricky\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Ricky\AppData\Local\Programs\Python\Python37-32\Scripts\bluetooth_battery.exe\__main__.py", line 4, in <module>
  File "c:\users\ricky\appdata\local\programs\python\python37-32\lib\site-packages\bluetooth_battery\bluetooth_battery.py", line 12, in <module>
    import bluetooth
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "c:\users\ricky\appdata\local\programs\python\python37-32\lib\site-packages\pybluez-0.23-py3.7-win32.egg\bluetooth\__init__.py", line 39, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "c:\users\ricky\appdata\local\programs\python\python37-32\lib\site-packages\pybluez-0.23-py3.7-win32.egg\bluetooth\msbt.py", line 4, in <module>
AttributeError: module 'bluetooth._msbt' has no attribute 'initwinsock'

At first, I thought maybe it's to do with Pybluez. So I've tried installing v0.23 as well as v0.3. Both Pybluez versions installed fine and I was able to install bluetooth_battery OK as well. But whenever I run it, I get the same error message regardless of which Pybluez version I'm using.

Problem

Not working Ubuntu 20.04 LTS Kernel 5.4.0

AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

I'm on linux OpenSUSE Tumbleweed 20200516.
When I run your script I get:

Traceback (most recent call last):
  File "./bl_battery.py", line 89, in <module>
    main()
  File "./bl_battery.py", line 79, in main
    with socket.socket(socket.AF_BLUETOOTH,
AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

Any hint?
Thank you in advance
Cris

AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

When i tried to execute script, i got this message.

    s = socket.socket(socket.AF_BLUETOOTH,
AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

you know any solution for this?

i believe is some about my system config, but i can't find anything about this, i can isolate the problem using:

$ python -c "import socket; socket.AF_BLUETOOTH"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'

Thhank's for project, is really useful

Script freeze without result. [realme Buds Q]

Hello,
Success install it under Ubuntu 20.04, using realme Buds Q. However, after run the scripts its freeze without result until stop it manually. Its feedback with below error.

^CTraceback (most recent call last):
File "./bluetooth_battery", line 8, in
sys.exit(main())
File "/home/user/.local/lib/python3.8/site-packages/bluetooth_battery/bluetooth_battery.py", line 81, in main
while getATCommand(s, s.recv(128), device):
File "", line 3, in recv
KeyboardInterrupt

Hopefully can help me to solve it.

Thanks

Add python3 as requirement

Add to Readme.md that it requires python3. If you call the script with python first, it will force to use the version you specify, overriding python env. If you call the script directly will use env.

./bluetooth_battery.py -> Reads #!/usr/bin/env
python* bluetooth_battery.py -> Uses the specified version overriding #!/usr/bin/env

Failed to build PyBluez

I'm not a programmer and know nothing about Python. Could someone please take a look at this message and let me know what I'm missing? I'm using Python 3.7.2 and I ran pip3 install bluetooth_battery and I got this message:

Successfully built bluetooth-battery
Failed to build PyBluez
DEPRECATION: Could not build wheels for PyBluez which do not use PEP 517. pip will fall back to legacy 'setup.py install' for these. pip 21.0 will remove support for this functionality. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
Installing collected packages: PyBluez, bluetooth-battery
    Running setup.py install for PyBluez ... error
...
...
...

Protocol not supported error when BT_RFCOMM is in the kernel config

$ bluetooth_battery AC:12:2F:0B:3D:84
Couldn't find the RFCOMM port number
Traceback (most recent call last):
File "/home/devsk/.local/bin/bluetooth_battery", line 33, in
sys.exit(load_entry_point('bluetooth-battery==1.2.0', 'console_scripts', 'bluetooth_battery')())
File "/home/devsk/.local/lib/python3.7/site-packages/bluetooth_battery/bluetooth_battery.py", line 90, in main
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
File "/home/devsk/.local/lib/python3.7/site-packages/bluetooth/bluez.py", line 165, in init
_sock = _bt.btsocket (proto)
_bluetooth.error: (93, 'Protocol not supported')

$ zgrep RFCOMM /proc/config.gz
CONFIG_BT_RFCOMM=y
CONFIG_BT_RFCOMM_TTY=y

Running Gentoo Linux with kernel 5.10.2

$ bluetoothctl devices
Device AC:12:2F:0B:3D:84 Soundcore Life Q30

Cannot able to install it in Ubuntu 20.01

I tried to install it in my system which has ubuntu 20.01. But I got error as below.

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-Jio3Nv/bluetooth-battery/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Jio3Nv/bluetooth-battery/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-THeq9Q
         cwd: /tmp/pip-install-Jio3Nv/bluetooth-battery/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-Jio3Nv/bluetooth-battery/setup.py", line 6, in <module>
        with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
    TypeError: 'encoding' is an invalid keyword argument for this function
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Connected sound every time I run the app

First, like others, I was unable to successfully execute the command, but...
Selection_053
when I disconnected my headphones and reconnect them again, the software is enable to check the battery level.
Now, every time I ask for the battery level I hear "connected" in my headphones.
Is it normal?
I want to do a script to alert me when the battery is under 50%, but if the "connected" sound is present I can't do it.

unclear exception on usage attempt

when I try to use this project as an cli tool, I get the following exception:
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

python 3.10, archlinux

Connection refused when in use for a while

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.