android - 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 都有上述错误。
非常感谢您的回答,谢谢!
解决方案
推荐阅读
- android - 未知来源的空指针异常 (Ud.f)
- reactjs - 反应 | Ant Design - 使用远程数据搜索的 Select 组件中的默认值
- python - 生成带有条件的列表产品
- docusignapi - Docusign - HTTP/1.1://docusignapp2.herokuapp.com?op=webhook :: 错误 - 无效的 URI:URI 方案无效
- go - Golang GCP 存储客户端内存泄漏
- shell - 在 Unix 中杀死存储在文本文件中的进程 ID
- php - 根据另一个选择更改选择选项
- c# - 如何使用 C# 在 WindowsForm 中播放 HLS-(Http Live Streaming)?
- asp.net - ASP.net Core 3.1 Razor 页面分页控件不适用于 dapper 数据集
- python - 如果任何行值在另一个数据框中,则从数据框中删除一行,数据框有多个列