Check battery level of connected bluetooth device on linux

后端 未结 9 1759
盖世英雄少女心
盖世英雄少女心 2021-01-30 02:09

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 Serv

相关标签:
9条回答
  • 2021-01-30 02:59

    By default Bluez 'hides' the Battery Service UUID. This is because there is a 'battery plugin' loaded at startup of bluetoothd.

    If you don't want the battery plugin to be activated and make the Battery Service UUID visible again to bluetoothctl or any other application, then change the startup command for bluetoothd to be like this: 'bluetoothd -P battery'. That will make sure the battery plugin is not loaded. On a Raspberry Pi the bluetooth.service is located in /lib/systemd/system/bluetooth.service so you need to make the change in that file.

    0 讨论(0)
  • 2021-01-30 03:02

    Here is a way to get battery level via pulseaudio logs with some hack. My bluetooth headset uses proprietary Apple HFP AT commands, HFP/A2DP protocols are handled by pulseaudio directly. It seems the only way to get those values is through pulse.

    0 讨论(0)
  • 2021-01-30 03:02

    As said by @OlivierM above, the UUID is filtered by bluetoothd. You could undo that and export the UUID just as any other service characteristics by removing the following from the export_service() function in src/gatt-client.c

    if (gatt_db_service_get_claimed(attr))
         return;
    
    0 讨论(0)
提交回复
热议问题