【问题标题】:Read battery status bluetooth headset linux读取电池状态蓝牙耳机linux
【发布时间】:2019-06-07 14:41:55
【问题描述】:

我使用使用蓝牙 4.1 版的蓝牙耳机。当我连接安卓时,它会显示电池状态。但是使用 Linux (Ubuntu 18.04) 我无法获得电池状态。我尝试使用bluetoothctl,在/sys/class/power_supply 中查找文件,就像其他问题一样,但他们没有帮助我。

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

我的蓝牙设备不使用 GATT 配置文件。它使用 A2DP 接收器来传输音频。

我查看了 Bluez 文档。他们都说是做 GATT profile 并获取属性。

有没有办法在 Linux 中正确地读取电池状态? android设备如何获取电池状态?是不是 Linux 蓝牙栈的弱点?

【问题讨论】:

  • 您的设备很可能正在使用电池电量的自定义属性。您可以尝试以下操作并发布输出:- 运行“bluetoothctl”,然后运行“menu gatt”,然后运行“list attributes [dev]”并将 [dev] 替换为耳机的蓝牙地址。
  • @YoussifSaeed 当我输入 menu gattlist-attributes [device-mac] 时,它什么也不打印。
  • @mimix2 也许在这里看看我的答案:stackoverflow.com/a/55008142/6267288。目前尚不清楚 Bluez DBUS org.bluez.Battery1 是否特定于 GATT。快速查看代码,它看起来与 GATT 相关,但我可能错了。
  • @LakinduAkash 你需要先connect [device-mac]menu gatt

标签: linux bluetooth android-bluetooth bluez


【解决方案1】:

this pull request by Dmitry Sharshakov 起,PipeWire 支持报告电池状态(使用 Apple HFP AT 命令的设备)。它使用 bluez 的 Battery Provider API,该 API 仍处于试验阶段,仅当 bluetoothd-E 标志启动时可用。

在 Arch Linux 上运行应该足够了

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

应该会显示耳机电池电量。要以编程方式获取电池电量,您可以使用 UPower 的 DBus API。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-30
    • 2019-03-30
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    相关资源
    最近更新 更多