FlutterBleLib icon indicating copy to clipboard operation
FlutterBleLib copied to clipboard

Issue with error propagation in `startPeripheralScan()` (no results and no errors if error was instant in native)

Open VinciShark opened this issue 5 years ago • 6 comments

......

  • start scan
  • successfully get scan result
  • shut down Bluetooth Adapter manualy
  • open Bluetooth Adapter using await BleManager.enable();
  • NO MATTER whether I use await BleManager.stopPeripheralScan();
  • start scan again
  • no result

VinciShark avatar Aug 25 '20 10:08 VinciShark

2020-08-25 18:10:21.304 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: createClient
2020-08-25 18:10:21.591 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: setLogLevel
2020-08-25 18:10:21.593 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: stopDeviceScan
2020-08-25 18:10:21.603 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: getState
2020-08-25 18:10:29.347 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: getState
2020-08-25 18:10:30.491 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: startDeviceScan
2020-08-25 18:10:37.169 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: stopDeviceScan
2020-08-25 18:10:37.325 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: stopDeviceScan
2020-08-25 18:10:37.327 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: getState
2020-08-25 18:10:40.156 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: getState
2020-08-25 18:10:40.163 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: enableRadio
2020-08-25 18:10:43.778 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: startDeviceScan
2020-08-25 18:10:43.790 20225-20225/com.racehf.app D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: stopDeviceScan

VinciShark avatar Aug 25 '20 10:08 VinciShark

after I cancel the no result scan, and start scan again, everything OK. but no use adding BleManager.stopPeripheralScan(); after BleManager.enable();

VinciShark avatar Aug 25 '20 10:08 VinciShark

@mikolak Would you please helping me understand this, thanks

VinciShark avatar Aug 25 '20 10:08 VinciShark

There's a race between starting scan and emitting the first error. If the error has occurred on start of the scan, it's possible that the subscription (and the subsequent creation of event channel in the native layer) will be done after the first error has been emitted (it just hit void listener, so is not propagated). We've tried to fix this already, but it seems we need a different solution for this.

For now I think the best workaround would be to add a timeout condition that would trigger cancelling of the scan if no results have been found in a few seconds.

mikolak avatar Aug 25 '20 10:08 mikolak

Thanks for your workaround advice.

Another question, is this issue, or are the most part of issues under this repo exist in exactly this repo(FlutterBleLib), or AndroidBleLib? I am considering if I have time and ability to be part of this repo's contributor.

VinciShark avatar Aug 25 '20 13:08 VinciShark

Do you mean MultiPlatformBleAdapter or RxAndroidBle by AndroidBleLib? Issues concerning this library are mostly here, some might show up on MultiPlatformBleAdapter or be duplicated in react-native-ble-plx (as it now uses the same backend, MultiPlatformBleAdapter).

mikolak avatar Aug 25 '20 16:08 mikolak