Scan Multiple MAC IDs using Scan with filter

BleScanResult scanResult;
BleAddress addr("C9:D8:32:0B:20:C9", BleAddressType::RANDOM_STATIC);
if (BLE.scanWithFilter(BleScanFilter().address(addr), &scanResult, 1))
  Serial.printlnf("found device %s", (const char*)scanResult.advertisingData().deviceName());

This code scans single MAC ID perfectly. What is the best way to scan multiple MAC addresses using scan with filter. Kindly suggest

You would use an address vector to store multiple addresses and then pass that vector to scanWithFilter()
see here

Alternatively you could make use of the fact that BleScanFilter.address() returns a reference to its owning object and do this

    BleScanFilter addressFilter;
    addressFilter
      .address(BleAddress("C9:D8:32:0B:20:C9", BleAddressType::RANDOM_STATIC))
      .address(BleAddress("C9:D8:32:0B:20:CA", BleAddressType::RANDOM_STATIC))
      .address(BleAddress("C9:D8:32:0B:20:CB", BleAddressType::RANDOM_STATIC))
      .address(BleAddress("C9:D8:32:0B:20:CC", BleAddressType::RANDOM_STATIC))
      ;
1 Like

can I have one sample to uses addresses(). I am not familiar with vectors

Something along this line

    Vector<BleAddress> addressVector 
      { BleAddress("C9:D8:32:0B:20:CD", BleAddressType::RANDOM_STATIC)
      , BleAddress("C9:D8:32:0B:20:CE", BleAddressType::RANDOM_STATIC)
      , BleAddress("C9:D8:32:0B:20:CF", BleAddressType::RANDOM_STATIC)
      };
    BleScanFilter addressFilter;
    addressFilter.addresses(addressVector);
1 Like

Thanks a lot

1 Like