Bluetooth headset battery level linux

How to get the battery info of a bluetooth device?

I’ve searched a lot and didn’t find the proper solution for the problem I’m facing. I wonder if is there a way to see the battery level of a headset connected via bluetooth. I’ve checked the output of bluetoothctl already and it shows me the following information:

[EDIFIER W800BT]# info Device 04:FE:A1:E9:70:DE (public) Name: EDIFIER W800BT Alias: EDIFIER W800BT Class: 0x00240404 Icon: audio-card Paired: yes Trusted: yes Blocked: no Connected: yes LegacyPairing: no UUID: Headset (00001108-0000-1000-8000-00805f9b34fb) UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) UUID: Handsfree (0000111e-0000-1000-8000-00805f9b34fb) [EDIFIER W800BT]# show Controller 74:40:BB:FE:F3:7C (public) Name: kennet Alias: kennet Class: 0x001c010c Powered: yes Discoverable: yes Pairable: yes UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb) UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) UUID: OBEX File Transfer (00001106-0000-1000-8000-00805f9b34fb) UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb) UUID: OBEX Object Push (00001105-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) UUID: IrMC Sync (00001104-0000-1000-8000-00805f9b34fb) UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb) UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) UUID: Vendor specific (00005005-0000-1000-8000-0002ee000001) UUID: Message Notification Se.. (00001133-0000-1000-8000-00805f9b34fb) UUID: Phonebook Access Server (0000112f-0000-1000-8000-00805f9b34fb) UUID: Message Access Server (00001132-0000-1000-8000-00805f9b34fb) UUID: Headset (00001108-0000-1000-8000-00805f9b34fb) Modalias: usb:v1D6Bp0246d0530 Discovering: no 
➜ ~ hcitool dev Devices: hci0 74:40:BB:FE:F3:7C 
➜ ~ ls -l /sys/class/bluetooth/hci0/power/ total 0 -rw-r--r-- 1 root root 4096 dez 27 19:11 async -rw-r--r-- 1 root root 4096 dez 27 19:11 autosuspend_delay_ms -rw-r--r-- 1 root root 4096 dez 27 19:11 control -r--r--r-- 1 root root 4096 dez 27 19:11 runtime_active_kids -r--r--r-- 1 root root 4096 dez 27 19:11 runtime_active_time -r--r--r-- 1 root root 4096 dez 27 19:11 runtime_enabled -r--r--r-- 1 root root 4096 dez 27 19:11 runtime_status -r--r--r-- 1 root root 4096 dez 27 19:11 runtime_suspended_time -r--r--r-- 1 root root 4096 dez 27 19:11 runtime_usage 

Источник

Arch Linux

I want to get the battery status from my Bluetooth headset.
It seems it does not support the GATT-Profile, but my android phone shows the battery status (LinageOS and Stock 8.1).

Читайте также:  Bluetooth колонка anker soundcore flare

Its a: «Marshall Monitor Bluetooth» witch is advertised with «Bluetooth v4.0 aptX».

I connected it using «A2DP» and it plays the music without any problems:

using bluetoothctl (Version 5.49).

[bluetooth]# connect 00:5A:5A:A6:61:87 Attempting to connect to 00:5A:5A:A6:61:87 [CHG] Device 00:5A:5A:A6:61:87 Connected: yes Connection successful [CHG] Device 00:5A:5A:A6:61:87 ServicesResolved: yes

If GATT is found there should be more output from the Device (says: https://docs.ubuntu.com/core/en/stacks/ … t-services ).
But this is all i got.

[MONITOR BLUETOOTH]# info Device 00:5A:5A:A6:61:87 (public) Name: MONITOR BLUETOOTH Alias: MONITOR BLUETOOTH Class: 0x00240404 Icon: audio-card Paired: yes Trusted: yes Blocked: no Connected: yes LegacyPairing: no UUID: Headset (00001108-0000-1000-8000-00805f9b34fb) 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)

I assume the UUID’s are services/features of the device. But there is no «Battery Service».
I read that there are some proprietary ways to submit the battery status, but when android it get’s it should be possible for me as well, or?

I’am tring on gathering more information’s about these services.
With D-Feet I find some interfaces of the device, but now I’am stuck and don’t know what i can do next.

Here a Screenshot of D-Feet: https://ibb.co/mzcKPH


So any ideas are appreciated

#2 2018-08-11 07:58:06

Re: Bluetooth Headset Battery Status

I’ve just looked into this way too much and while you probably don’t care at this point and I don’t have a firm answer yet, let me tell you what I’ve found out in case anyone else wants to take a look.

I’m guessing Android is using the hands free profile to get battery information. According to Wikipedia the Hands free protocol supports sending battery information and there is a spec sheet that seems to confirm it (https://www.bluetooth.org/docman/handle … _id=292287). I’m still very unclear about a bunch of how bluetooth works, but I’m going to be continuing to pursue this a bit and so maybe I’ll be able to update with more information.

#3 2018-08-11 14:44:36

ewaller Administrator From: Pasadena, CA Registered: 2009-07-13 Posts: 19,356

Re: Bluetooth Headset Battery Status

You may look into Wireshark. It now handles Bluetooth traffic and has a nice protocol analyzer to allow you to see what are being transmitted and received.

Читайте также:  Bluetooth led light app

Nothing is too wonderful to be true, if it be consistent with the laws of nature — Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. — Alan Turing

How to Ask Questions the Smart Way

#4 2018-08-13 05:34:48

Re: Bluetooth Headset Battery Status

As promised I did some more searching. Actually a lot more searching.

I’ve found 4 ways to get battery levels only one of which works on my headphones.

* GATT
* Hands Free AG
* A/V Remote Control Target
* And the one that worked: Headset AG with apple specific command

The search started with finding that the Hands Free Profile can report battery info. To find out if my device supported it I had to write a python script with Bluez’s d-bus integration. to get my headphones connect so I could log the info. I went through implementing a lot of the connection procedure before I realized that my device didn’t support the relevant feature.

The A/V Remote Control Target should also in theory support devices reporting battery level, but I don’t think my device supports it. I didn’t go into much detail to confirm though.

The headset profile was pure luck though. I was looking at Wireshark and happened to see

. I’d missed it before because it was only sent when first connecting, but a bit after the initial negotiation. The Bluetooth headset profile doesn’t support battery reporting, but it looks like Apple has their own command for iphones. It seems that in recent version Android supports it too. If you want to interact with it through code though you may have problems since PulseAudio implements their own support for this profile. I have to confess now that I’m not actually on Arch at the moment, so I’m not sure what the config for the Arch version looks like, but for me I had to compile from source with the

--disable-bluez5-native-headset

set. This means there won’t be any support for pulse audio hooking into the volume control on the device. I don’t really care, but you might.

Читайте также:  Автовоспроизведение при подключении блютуз

If anyone else wants any info about this I’d be happy to share, but I suspect the interest isn’t probably all that great.

I think you can find the same info that I did without too much Googling given the above.

Источник

Проверьте состояние батареи наушников Bluetooth в Linux

Возможно ли получить состояние батареи наушников Bluetooth, подключенных к Linux, Android показывает это, поэтому мне было интересно, если это было возможно??

6 ответов

Я не уверен насчет состояния в Ubuntu, но в Arch Linux в настоящее время вам не нужно писать собственные сценарии для получения информации о батарее Bluetooth.

Пакет bluez имеет экспериментальную поддержку запроса данных о батарее Bluetooth-гарнитуры. Просто включите экспериментальные функции, отредактировав

Затем вам просто нужно перезапустить службу Bluetooth, используя

systemctl restart bluetooth 

Повторно подключитесь к устройству и

теперь также должен показывать состояние батареи. например

Device 28:11:A5:47:6C:6E (public) Name: Cloud Walker Alias: Cloud Walker Class: 0x00240418 Icon: audio-headphones Paired: yes . Battery Percentage: 0x3c (60) 

Решение с использованием upower, предложенное danjjl, теперь также должно работать.

И теперь процент уровня заряда батареи также должен отображаться в диалоговом окне настроек Gnome Power.

Я написал простой скрипт на Python, который выполняет эту работу. Он использует AT-команды для связи с устройством через RFCOMM и печатает уровень заряда батареи, если устройство поддерживается.

(Для запуска скрипта вам понадобится Python 3.6.0 или новее)

Это может работать не со всеми bluetooth-гарнитурами, но на странице «Проблемы» я предложил несколько обходных решений, которые могут помочь.

В Ubuntu вы можете просто перейти в settings->power чтобы увидеть состояние батареи системы и подключенных устройств.

Да, я знаю, что это Bluetooth-мышь Microsoft в системе Linux. но, эй, Microsoft теперь новая крутая компания;)

upower может использоваться с терминала для составления списка устройств питания, прослушивания событий устройства и запроса истории и статистики.

Если ваше устройство указано upower -e Вы можете запустить upower —dump чтобы узнать уровень заряда батареи вашего устройства.

$ upower --dump . Device: /org/freedesktop/UPower/devices/mouse_dev_C1_FC_26_13_A9_58 native-path: /org/bluez/hci0/dev_C1_FC_26_13_A9_58 model: MX Anywhere 2S serial: C1:FC:26:13:A9:58 power supply: no updated: Wed 31 Dec 1969 06:00:00 PM CST (1550719462 seconds ago) has history: yes has statistics: no mouse present: yes rechargeable: no state: unknown warning-level: none percentage: 50% icon-name: 'battery-missing-symbolic' . 

Источник

Оцените статью
Adblock
detector