I use Bluetooth headset that use Bluetooth version 4.1. When I connect with android it shows the battery status. But with Linux (Ubuntu 18.04) I cannot get battery status. I tried with bluetoothctl
, looking file in /sys/class/power_supply
as in other questions, But they didn't help me.
askubuntu.com/questions/53880/is-there-any-way-to-check-the-battery-percentage-of-apple-wireless-peripherals
stackoverflow.com/questions/49078659/check-battery-level-of-connected-bluetooth-device-on-linux
My bluetooth device don't use GATT profile. It uses A2DP sink for streaming audio.
I looked Bluez documentation. They all said is do with GATT profile and get the attributes.
Is there a way to read battery status even with pragmatically in Linux properly? How does android device get the battery status? Is it a weakness of Linux Bluetooth stack?
Android 8.1 Devices All you need to do is pair and connect a Bluetooth device to your phone. Once you've done that, open the Settings app and go to Connect Devices. Tap Bluetooth (not the switch next to it). You will see a complete list of all connected devices and their battery level with some exceptions.
Tap on the Hamburger icon from the top-left corner of the screen then tap on Settings. 4. Tap on Notifications to adjust the settings. In the notification section, enable the option 'Shows notifications' to display the battery life of your Bluetooth device.
I am not sure about the state under Ubuntu, but under Arch Linux you do not need to write your own scripts to get bluetooth battery information nowadays. The bluez package has experimental support for querying bluetooth headset battery data. Simply enable experimental features under should now also show the battery status.
The bluez package has experimental support for querying bluetooth headset battery data. Simply enable experimental features under should now also show the battery status. The solution using upower as given by danjjl should also work now. I have developed a GUI application to get the battery level of a bluetooth headset.
Follow the methods mentioned below to check battery status using the Linux command line. Check Battery Status with “upower” CommandThe command produces output The upower command-line tool helps extract information related to the power source (batteries). It provides an interface to list down all the power sources of your PC or laptop.
It might not work with all bluetooth headsets but I've provided a couple of workarounds in the 'Issues' page that might help. In ubuntu you can go simply to settings->power to see the battery status of system and connected devices. Yes, I know it's a Microsoft Bluetooth mouse on a Linux System ... but hey, Microsoft is the new cool company now ;)
Since this pull request by Dmitry Sharshakov, PipeWire has support for reporting battery status (with devices that use Apple HFP AT commands). It uses bluez's Battery Provider API, which is still experimental and is only available if bluetoothd
is started with the -E
flag.
On Arch Linux, it should be enough to run
cp /usr/lib/systemd/system/bluetooth.service /etc/systemd/system/
sed -i -r 's/ExecStart=.+/& -E/' /etc/systemd/system/bluetooth.service
systemctl daemon-reload
systemctl restart bluetooth
And the headset battery level should appear. To get the battery level programatically, you can then use UPower's DBus API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With