Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to subscribe to notification characteristic in bluetooth low energy

In my UWP application, I want to connect to a Bluetooth low energy peripheral device and subscribe to its notification characteristic. this is the application Connect method:

private async Task Connect(string id)
{
    var device = await BluetoothLEDevice.FromIdAsync(id);
    var gattService = (await device.GetGattServicesForUuidAsync(Guid.Parse("00002600-005d-0012-00ef-00000000717f"))).Services.FirstOrDefault();
    if (gattService != null)
    {
        var notificationCharacteristic = (await gattService.GetCharacteristicsForUuidAsync(Guid.Parse("00009e76-0c4d-0db6-08b6-000000020445"))).Characteristics.FirstOrDefault();
        if (notificationCharacteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Notify))
        {
            try
            {
                var result = await notificationCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
            }
            catch (Exception ex)
            {

            }
        }
    }
}

The problem is when I try to write to the notification characteristic, the WriteClientCharacteristicConfigurationDescriptorAsync method raise an exception:

The attribute cannot be written. (Exception from HRESULT: 0x80650003)

I test this scenario using android application and I can write notification characteristic without any problem. I want to know what the problem in UWP?

Update: I change the UUID of notification characteristic descriptor from the peripheral device and see that the problem was solved.

like image 528
Emad Feiz Avatar asked Dec 08 '25 17:12

Emad Feiz


1 Answers

I found the problem, after some test I change the UUID of notification characteristic descriptor from the peripheral device and see that the problem was solved.

like image 136
Emad Feiz Avatar answered Dec 10 '25 11:12

Emad Feiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!