Open Matrix-Zhang opened 3 years ago
I have the same problem and it would be cool to get some advice on good design. I also have a problem when I do disconnect that 50% of the times I can not connect anymore and I get a PlatformError. The examples are not really helpful with a normal setup.
Hi!
We have a bug with some of the streams. I've made a bad, uninformed decision making the streams asynchronous, which causes the cancel function to be asynchronous as well (it returns immediately without awaiting the proper clean up). This needs to be fixed, while maintaining potential back compatibility (possible optional argument asBroadcast
defaulting to true), but sadly I have we don't have free processing power right now.
@ride4sun can you paste the platform error? Is it possible that you're destroying the client? What platform are you testing on?
Could you guys add some thoughts as to what would be a good, simple example to this issue https://github.com/Polidea/FlutterBleLib/issues/443 ?
This what I am seeing very often. A fast fix for that would be very appreciated because this renders our app almost not useable. PlatformException(2, null, {"errorCode":2,"attErrorCode":null,"androidErrorCode":null})
This is the Callstack
StandardMethodCodec.decodeEnvelope (message_codecs.dart:572)
MethodChannel._invokeMethod (platform_channel.dart:161)
<asynchronous gap>
MethodChannel.invokeMethod (platform_channel.dart:334)
CharacteristicsMixin.writeCharacteristicForIdentifier (characteristics_mixin.dart:82)
InternalBleManager.writeCharacteristicForIdentifier (internal_ble_manager.dart:233)
Characteristic.write (characteristic.dart:78)
BLELibBloc.init.<anonymous closure>.<anonymous closure> (flutter_ble_lib_bloc.dart:58)
_AsyncAwaitCompleter.start (async_patch.dart:55)
BLELibBloc.init.<anonymous closure>.<anonymous closure> (flutter_ble_lib_bloc.dart:52)
_rootRunUnary (zone.dart:1198)
_rootRunUnary (zone.dart:1)
_CustomZone.runUnary (zone.dart:1100)
_CustomZone.runUnaryGuarded (zone.dart:1005)
_BufferingStreamSubscription._sendData (stream_impl.dart:357)
_DelayedData.perform (stream_impl.dart:611)
_StreamImplEvents.handleNext (stream_impl.dart:730)
_PendingEvents.schedule.<anonymous closure> (stream_impl.dart:687)
_rootRun (zone.dart:1182)
_rootRun (zone.dart:1)
_CustomZone.run (zone.dart:1093)
_CustomZone.runGuarded (zone.dart:997)
_CustomZone.bindCallbackGuarded.<anonymous closure> (zone.dart:1037)
_rootRun (zone.dart:1190)
_rootRun (zone.dart:1)
_CustomZone.run (zone.dart:1093)
_CustomZone.runGuarded (zone.dart:997)
_CustomZone.bindCallbackGuarded.<anonymous closure> (zone.dart:1037)
_microtaskLoop (schedule_microtask.dart:41)
_startMicrotaskLoop (schedule_microtask.dart:50)
_startMicrotaskLoop (schedule_microtask.dart:1)
@mikolak were you able to get a fix for this? If not, is there any 'good enough' catch alls that will allow it to at least not throw an exception?
I can help, if needed. But I'll need some understanding of the bug and what it affects.
I am still see the defect and desperately waiting for a fix. Did the info I provided help?
On Mon, Mar 1, 2021, 18:05 Adrian Lemus notifications@github.com wrote:
I can help, if needed. But I'll need some understanding of the bug and what it affects.
ā You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Polidea/FlutterBleLib/issues/520#issuecomment-788518546, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3BZ23ZO7BRQOFXPMBKXWDTBRBXDANCNFSM4QRKRSTA .
Hi!
The proper fix is to make data streams single subscription, which will make cancel()
awaitable. On a broadcast stream the cancel is immediately finished, even if the underlying cleanup is still in progress. This is a breaking change and to avoid breaking it there should be an option for the user to choose which stream they get and default it to true, ie. adding a book asBroadcast = true
parameter to all functions that need it. I can think of scanning for peripherals and monitoring functions.
This does not address the issue @ride4sun has, I have no idea why an uncaught Dart exception would make a peripheral not able to connect. Code 2 is operation cancelled and it can happen to all async operation that do not have the pair stopX
. This is business as usual. You should probably add catchError/onError to your calls and handle any BleErrors.
I won't have as much time for the library right now as Polidea has been sold and can no longer maintain the libraries. I'll try to keep maintaining this, but I'll have a limited time. Transition is possibly in progress.
@mikolak thanks for all of your help/work. It's a shame this package might not be getting maintained anymore.
Stay tuned, it should be fine and maintained. š
@mikolak Is there any news on this. Can not wait to have this work better.
@ride4sun I moved over to https://github.com/PhilipsHue/flutter_reactive_ble.
This current package worked well but there were too many gotchas that I didn't know how to handle well enough. This other package seems pretty plug-and-play and I haven't really had any issues so far with it.
Related to #487
my code, often have exception