1

Good day! Cant get battery percentage in percent. Ive successfully connected to GATT services, thed did this:

public override void OnServicesDiscovered(BluetoothGatt Gatt, [GeneratedEnum] GattStatus Status)
        {
            base.OnServicesDiscovered(Gatt, Status);

            if (Status == GattStatus.Success)
            {
                 if(Service.Uuid.Equals(UUID.FromString("0000180f-0000-1000-8000-00805f9b34fb")))
                    {
                        BluetoothGattCharacteristic characteristic = Service.GetCharacteristic(UUID.FromString("00002a19-0000-1000-8000-00805f9b34fb"));
                        if(characteristic!=null)
                        {
                            Gatt.ReadCharacteristic(characteristic);
                        }

                    }
                }
            }
            else
            {
                MainActivity.AppendLog("onServicesDiscovered received: " + Status);
            }
        }

Then, on Read

    public override void OnCharacteristicRead(BluetoothGatt Gatt, BluetoothGattCharacteristic Characteristic, [GeneratedEnum] GattStatus Status)
    {
        base.OnCharacteristicRead(Gatt, Characteristic, Status);

        var batteryData = Characteristic.GetValue();
    }

I got only 77 and this is not a battery percentage (0-64). Device always send this number, I tried to charge device and wait for low level battery, but got always this. Thanks for a help.

Alexander Man
  • 63
  • 1
  • 5
  • Your code looks correct, so maybe the device is reporting this incorrectly? I would try using a ready app (e.g. nRF Connect) to read the battery value. This way you know if the problem is with your code or with the device itself. – Youssif Saeed Nov 24 '20 at 07:38

0 Answers0