Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read battery status bluetooth headset linux

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?

like image 591
Lakindu Akash Avatar asked Jan 13 '19 09:01

Lakindu Akash


People also ask

How do I check the battery percentage on my Bluetooth headset?

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.

How do I check the battery level of a connected device?

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.

Is there a way to check Bluetooth battery status on Ubuntu?

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.

How to get the battery level of a Bluetooth headset?

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.

How to check battery status using Linux command line?

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.

Is there a way to check battery life on Bluetooth mouse?

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 ;)


1 Answers

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.

like image 138
LHLaurini Avatar answered Sep 27 '22 23:09

LHLaurini