bluetooth-battery-monitor
bluetooth-battery-monitor copied to clipboard
Open source Bluetooth battery monitor for Windows
trafficstars
Bluetooth Battery Monitor
Open source Bluetooth battery monitor for Windows
Enumerating Bluetooth devices and services
I'm not using UWP, only classic C/C++ API (check out misc directory for more C++ examples).
API calls:
SetupDiGetClassDevs/SetupDiEnumDeviceInfofor getting a list of all bluetooth devices.SetupDiGetDeviceRegistryProperty/SPDRP_HARDWAREIDfor filtering by device address.BluetoothGATTGetServices/BluetoothGATTGetCharacteristicsfor BLE properties.SetupDiGetDeviceProperty/DEVPKEY_DeviceContainer_IsConnectedfor connection status.
UUIDs:
{e0cbf06c-cd8b-4647-bb8a-263b43f0f974}(Bluetooth Device) forSetupDiGetClassDevs.{00001800-0000-1000-8000-00805F9B34FB}(Generic Attribute) for Appearance (0x2A01).{0000180F-0000-1000-8000-00805F9B34FB}(Battery Service) for Battery Level (0x2A19).{0000180A-0000-1000-8000-00805F9B34FB}(Device Information) for Manufacturer (0x2A29).
Problems and workarounds:
- The program supports only BLE reports for now. Obtaining battery status is easy for BLE,
but HID and HFP devices use their own approach (see HID Usage Tables "Battery Strength" and
HFPGetBatteryLevelaccordingly). HFP devices also expose HID interface, probably it's all doable with HID API or a system-wide dll hook. Will implement later. BLUETOOTH_GATT_FLAG_FORCE_READ_FROM_DEVICE(0x00000004) timeouts on disconnected devices, check their status first.{00001800-0000-1000-8000-00805F9B34FB}(Generic Attribute) is read only, don't useGENERIC_WRITEinCreateFile.