Skip to content
Advertisement

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement