Emad Feiz
Emad Feiz

Reputation: 1575

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.

Upvotes: 3

Views: 2488

Answers (1)

Emad Feiz
Emad Feiz

Reputation: 1575

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.

Upvotes: 2

Related Questions