dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
530 stars 194 forks source link

characteristic.monitor().listen error while writeCharacteristic WithoutResponse as. my device is Notifiable #608

Open philos3 opened 2 years ago

philos3 commented 2 years ago

characteristic.monitor().listen throw an exception

my device is writewithoutresponse and is notifible ────────────────────────────────────────────────────────── flutter: dataCharacteristic: flutter: uuid: XXXXXXXXXXX(as example) flutter: isReadable: false flutter: isWritableWithoutResponse: true flutter: isWritableWithResponse: false flutter: isIndicatable: false flutter: isNotifiable: true ──────────────────────────────────────────────────────────

as i set true to peripheral.writeCharacteristic( , , , true, ), there is no error on Android but ios got an error while writeCharacteristic if i set false to peripheral.writeCharacteristic( , , , false, ), both android and ios got an error while monitor what is the correct way to monitor and writeCharacteristic?

here is the error message #####################

Unhandled error happened: Connection error has occured: - subscription called from:

characteristic.monitor().listen onError =====error:BleError (Error code: 201, ATT error code: null, iOS error code: null, Android error code: null, reason: Unknown error., internal message: null, device ID: CECAF6DD-73C5-B04C-EDE0-20B401AEF08B, service UUID: null, characteristic UUID: null, descriptor UUID: null)

here is my code ######################################## streamSubscription = characteristic.monitor().listen((readValue) { ///.... },onError: (error) { LogUtil.e("characteristic.monitor().listen onError =====error:${error.toString()}===============================",tag: getClassName()); catchCharacteristicError(error, null); } );

peripheral .writeCharacteristic( YsBleUuids.uuidService, YsBleUuids.clientCharacteristicWithNotifyAndWrite, Uint8List.fromList(value), false,///while my dataCharacteristic. isWritableWithoutResponse: true. so withResponse is false // transactionId:transactionId )

######################################## (base) philos:flutter_beauty zby0520$ flutter doctor -v [✓] Flutter (Channel stable, 2.2.3, on macOS 11.3 20E232 darwin-x64, locale zh-Hans-CN) • Flutter version 2.2.3 at /Users/zby0520/flutter/flutter • Framework revision f4abaa0735 (5 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/zby0520/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • ANDROID_SDK_ROOT = /Users/zby0520/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.4, Build version 12D4e • CocoaPods version 1.10.1

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.1.3) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (2 available) • XXXXX (mobile) • XXXXXX• ios • iOS 14.4 • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114

• No issues found!

sh3rlock97 commented 2 years ago

Hi

Were you able to fix your error? I'm also getting a 201-Error when listening to a Characteristic:

if (characteristic.isNotifiable) {
    print("Notifiable: ${characteristic.uuid}");
    characteristic.monitor().listen(
        (event) {
          print("listend and heared ${event}");
        },
        onError: (e) => print("Error monitoring disconnect $e"),
        onDone: () {
          print("Disconnect!");
          peripheral.disconnectOrCancelConnection();
        },
        cancelOnError: true);
  }