and because I can run UWP async methods on Unity, I created a Task running on the background, reading the battery level every xxx minutes…
var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.Battery)); var service = await GattDeviceService.FromIdAsync(devices[0].Id); var clickerCharacteristic = service.GetCharacteristics(GattCharacteristicUuids.BatteryLevel)[0]; var BatteryLevel = await clickerCharacteristic.ReadValueAsync(); byte levelData = Windows.Storage.Streams.DataReader.FromBuffer(BatteryLevel.Value).ReadByte(); UpdateClickerBattery((double)levelData);
I also enabled the Capability on the Manifest:
And always get the same value [ 71 ] .
I tryed to charge the clicker, a still give 71 % of battery…
I also already checked that the service is the “Clicker” service, because if I print the devices[0].Name it will return “Clicker”…
According to the doc’s you need to get the updates from the bluetooth device.
You might want to try this example:
C#
async void Initialize()
{
var batteryServices = await Windows.Devices.Enumeration
.DeviceInformation.FindAllAsync(GattDeviceService
.GetDeviceSelectorFromUuid(GattServiceUuids.Battery),
null);
if (batteryServices.Count > 0)
{
// Use the first Battery service on the system
GattDeviceService batteryService = await GattDeviceService
.FromIdAsync(batteryServices[0].Id);
// Use the first Characteristic of that Service
GattCharacteristic batteryLevelCharacteristic =
batteryService.GetCharacteristics(
GattCharacteristicUuids.BatteryLevel)[0];