简体   繁体   中英

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.

我发现了问题,经过一些测试,我从外围设备更改了通知特征描述符的UUID,看到问题解决了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM