I created a flutter demo app for BLE connection and communication.
I'm try listen the data from characteristic value. But doing the await characteristic.setNotifyValue(true);
will cause an error.
The code bellow is the whole operation from discovering services and read characteristic.
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;
});
});
});
});
And I encounter this error:
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)
All characteristic uuid from my BLE device have the error above.
Your answer/s will be much appreciated, thank you!
Copyright Notice:Content Author:「jason.juntong」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68031279/flutter-blue-set-notification-error-could-not-locate-cccd-descriptor-for-charac