首页 > 解决方案 > flutter_blue set_notification_error,找不到特征的 CCCD 描述符

问题描述

我为 BLE 连接和通信创建了一个颤振演示应用程序。

我正在尝试从特征值中收听数据。但是这样做await characteristic.setNotifyValue(true);会导致错误。

下面的代码是从发现服务和读取特征的整个操作。

discoverServices() async {
List<BluetoothService> services = await discoveredDevice.discoverServices();
services.forEach((service) {
    service.characteristics.forEach((characteristic) async {

        // Read characteristic
        var value = await characteristic.read();
        debugPrint("Read value: $value");

        // Read descriptor
        var descriptors = characteristic.descriptors;
        for(BluetoothDescriptor d in descriptors) {
          List<int> descriptorValue = await d.read();
          debugPrint("Descriptor value: $descriptorValue");
        }

        await characteristic.setNotifyValue(true);
        debugPrint('Is characteristic notifying: ${characteristic.isNotifying}');
        characteristic.value.listen((characteristicValue) {
          debugPrint('Characteristic value: $characteristicValue');
          setState(() {
            listStream = characteristic.value;
          });
        });
    });
});

我遇到了这个错误:

E/flutter (28172): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(set_notification_error, could not locate CCCD descriptor for characteristic: 00002a00-0000-1000-8000-00805f9b34fb, null, null)

我的 BLE 设备中的所有特征 uuid 都有上述错误。

非常感谢您的回答,谢谢!

标签: androidflutterbluetoothbluetooth-lowenergy

解决方案


推荐阅读