在Linux上检查连接的蓝牙设备的电池电量 [英] Check battery level of connected bluetooth device on linux

查看:727
本文介绍了在Linux上检查连接的蓝牙设备的电池电量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查连接的蓝牙设备的电池电量?该设备在Android上显示电池电量,因此我假设该设备支持基于GATT的电池服务.但是,通过在bluetoothctl中输入"menu gatt",然后用"list-attributes [dev]"列出设备的GATT属性,则什么都没有显示.

How can I check the battery level of a connected bluetooth device? The device shows the battery level on Android so I'm assuming the device supports the GATT-based Battery Service. However, by entering "menu gatt" in bluetoothctl and then listing the GATT attributes of the device with "list-attributes [dev]", nothing shows up.

A 类似的问题发布到了SO ,但是OP似乎找到了对我不起作用的解决方案.当我在bluetoothctl中运行"info [dev]"时,看不到电池服务的UUID.

A similar question was posted to SO but the OP seems to have found a solution that doesn't work for me. When I run "info [dev]" in bluetoothctl I don't see the UUID for Battery Service.

我希望能在命令行上运行并且与发行版无关的解决方案.

I would prefer a solution that runs on the command line and is distro-agnostic.

请让我知道是否应该在超级用户上发布此问题.

Please let me know if this question should be posted on SuperUser instead.

推荐答案

这次聚会可能有点晚了,但对我来说,这个Python项目运行良好:

This might be a bit late to the party but for me this Python project has worked fine:

https://github.com/TheWeirdDev/Bluetooth_Headset_Battery_Level

我只需要将我的无名X5耳机的第57行的端口更改为3.如果挂起或连接被拒绝"错误,请尝试其他端口.

I only had to change the port in line 57 to 3 for my no-name X5 headset. If it hangs or errors with "connection refused" try a different port.

Python程序通过RFCOMM使用AT命令,并且在Pulseaudio使用A2DP接收器(重新连接矿井)时可以正常工作.需要Python 3,因为2没有BT串行套接字. Windows可能会因为缺少bluez而无法正常工作.它基本上与此处的Pulseaudio黑客具有相同的作用: https://stackoverflow.com/a/56390625/920122

The Python program uses AT commands via RFCOMM and should work while Pulseaudio is using the A2DP sink (mine reconnects). Python 3 is needed as 2 doesn't have BT-Serial sockets. Windows will probably not work as it lacks bluez. It basically does the same thing as the Pulseaudio hack here: https://stackoverflow.com/a/56390625/920122

如果要在交换命令时查看它们,请尝试我的调试叉: https://github. com/clst/Bluetooth_Headset_Battery_Level

If you want to look at the commands as they are exchanged, try my debug fork: https://github.com/clst/Bluetooth_Headset_Battery_Level

这篇关于在Linux上检查连接的蓝牙设备的电池电量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆