Sitelet https://github.com/dotintent/FlutterBleLib/issues/601
Skip to content

startPeripheralScan not working as expected #601

Description

@dajacmatt

Hi,

I'm not totally sure if this is a ble_lib issue or a blemulator issue. I have two simulated peripherals, one with a service SERVICE_STATUS and one without. When I try to use bleManager.startPeripheralScan(uuids: [SERVICE_STATUS]) it returns both peripherals rather than just one. However, if I manually check each scan result's advertisementData then I get the desired results. I'm not super familiar with Dart/Flutter so there could just be some other dumb mistake in the relevant code:

Stream<ScanResult> timeoutScan( {int sec = 5}) {
    Future.delayed(Duration(seconds:sec), () {
      print("++++++ delayed scan stopping");
      bleManager.stopPeripheralScan();
    } );

    return bleManager.startPeripheralScan(uuids: [SERVICE_STATUS]); //this parameter makes no difference to the results
  }

...

Future<void> updateScan({timeout = 5}) async {
  Peripheral p;
  foundDevices.clear();

  if (!scanInProgress)
  {
    scanInProgress = true;
    await timeoutScan(sec: timeout).listen((scanResult) async {
      p = scanResult.peripheral;
      if (!foundDevices.contains(p) && !connectedDevices.contains(p) && scanResult.advertisementData.serviceUuids.contains(SERVICE_STATUS)) {
        foundDevices.addPeripheral(p);
      }

       ...

    }).asFuture();
    scanInProgress = false;
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions