Closed mk-dev-1 closed 2 years ago
Should anyone stumble upon this, the issue can easily be remedied by adding a simple await Future.delayed(const Duration(milliseconds: 200));
in the right place. Close.
Should anyone stumble upon this, the issue can easily be remedied by adding a simple
await Future.delayed(const Duration(milliseconds: 200));
in the right place. Close.
where is right place?
@wsmzdyss - Here is an example:
await _characteristicSubscription?.cancel();
await Future.delayed(const Duration(milliseconds: 200)); // <---- Add this here
_characteristicSubscription = ble
.subscribeToCharacteristic(
QualifiedCharacteristic(
characteristicId: _bluetoothCharacteristicId,
serviceId: _bluetoothServiceId,
deviceId: id,
),
)
@mk-dev-1 Thanks, I tried it but it didn't solve the problem
Describe the bug Connecting and subscribing to a characteristic only works once. After disconnecting & reconnecting to the same device either causes no error (and no reads) or the following error.
This error does not happen with the example app, but it does happen with this simple sample app I put together (below).
To Reproduce Steps to reproduce the behavior:
CODE TO REPRODUCE
```dart import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:health_flutter/services/bluetooth_manager.dart'; class BluetoothScreen extends StatefulWidget { const BluetoothScreen({Key? key}) : super(key: key); @override StateExpected behavior Connecting, subscribing, disconnecting should work correctly everytime.
Smartphone / tablet
Peripheral device
Additional context The device (Beurer BM57) re-transmits the records it's got stored every time and they can be perfectly received with the code from the sample app that comes with the plugin, however not with the sample code that I added. I tried adding delays, changed the order of calling
.cancel()
, etc. but I sitll can't get consistent reads. I am hoping it is something very simple that I am doing wrong, but I just can't seem to figure out what it is. I am hoping for your guidance.Thank you very much for your support.