读取蓝牙耳机电池状态linux

问题描述 投票:0回答:2

我使用的蓝牙耳机采用蓝牙4.1版本。当我连接 Android 时,它会显示电池状态。但在 Linux (Ubuntu 18.04) 中我无法获取电池状态。我尝试使用

bluetoothctl
,像其他问题一样在
/sys/class/power_supply
中查找文件,但他们没有帮助我。

askubuntu.com/questions/53880/有什么方法可以检查苹果无线外设的电池百分比

stackoverflow.com/questions/49078659/check-battery-level-of-connected-bluetooth-device-on-linux

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

我查看了 Bluez 文档。他们都说是使用 GATT 配置文件并获取属性。

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

linux bluetooth android-bluetooth bluez
2个回答
9
投票

自从 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。


0
投票
只需启用蓝牙(bluez)实验模式即可完成。

启用实验模式的步骤:

注意

记得在 sudo 或 doas 或 root 模式下编辑文件。

  • 在文本编辑器中打开

    /etc/bluetooth/main.conf

  • 转到写入的行

    # Experimental = false

    
    

  • 将该行更改为

    Experimental = true

    ,并记住删除该行的 
    #
     符号,使其成为命令而不是注释。

  • 然后运行此命令

    sudo systemctl restart bluetooth
    
    
你就完成了。享受吧:)

© www.soinside.com 2019 - 2024. All rights reserved.