Check battery level of connected bluetooth device on linux

后端 未结 9 1757
盖世英雄少女心
盖世英雄少女心 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:35

    You don't see Battery Level in the list of GATT characteristics since Bluez v5.48 because this specific GATT characteristic was moved into DBUS org.bluez.Battery1 interface.

    From the command line:

    1. Connect to your target BLE device with bluetoothctl
    2. And then request DBUS by running: dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_ org.freedesktop.DBus.Properties.Get string:"org.bluez.Battery1" string:"Percentage"

    In my case with my BLE peripheral with the following MAC address C3:41:A6:C8:93:42:

    $ dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_C3_41_A6_C8_93_42 org.freedesktop.DBus.Properties.Get string:"org.bluez.Battery1" string:"Percentage
       variant       byte 94
    

    Note: You could potentially scan and connect to your device using Bluez DBUS API.

提交回复
热议问题