Failed to subscribe to notification characteristic in bluetooth low energy

3

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.

c#
bluetooth
uwp
bluetooth-lowenergy
asked on Stack Overflow Feb 25, 2018 by Emad Feiz • edited Feb 26, 2018 by Emad Feiz

1 Answer

1

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.

answered on Stack Overflow Feb 27, 2018 by Emad Feiz

User contributions licensed under CC BY-SA 3.0