Finding a device using scanWithFIlter

Simple question: I would like to use scanWithFIlter() to find a specific device. I would like to use the address as a filter. so, how to I create the filter? I am currently using this code:

String address = “C9D8320B20C9”;
filter.address(address);
Vector BleScanResult> results = BLE.scanWithFilter(filter);

but this is returning no results. Any help would be appreciated, thanks

Can you try this

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());

When you scan for a device without filter you can check the BleAddressType of the found devices and use that info to then define the filter accordingly.

1 Like

Awesome thank you this works!!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.