Whitelisting and/or setScanFilter of BLE server not working

Tumbelo
Posts: 1
Joined: Fri Jan 15, 2021 12:01 pm

Whitelisting and/or setScanFilter of BLE server not working

Postby Tumbelo » Fri Jan 15, 2021 12:24 pm

Hi there,

I'm having simple BLE server and trying to allow connections only from whitelisted devices, but without success.

All actions are done in setup like this:

Code: Select all

void setup() {
  Serial.begin(115200);
  Serial.println("Starting...");

  BLEDevice::init("Test dev");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setValue("Hello World!");
  pService->start();
  
  // Try to whitelist
  BLEAddress adrr = BLEAddress("a0:28:ed:8d:dc:f3");
  BLEDevice::whiteListAdd(adrr);
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->setScanFilter(false, true); // Allow connection only for devices on white list
  
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  BLEDevice::startAdvertising();
  Serial.println("Ready!");
}
When I execute code in Nano32, created BLE server is visible for scans, but it doesn't allow connection from whitelisted device (or any other device). Everything works, if I change to

Code: Select all

Advertising->setScanFilter(false, false);
But of course connections from all devices are accepted.

Could someone explain what I'm doing wrong?

Thanks in advance!

Who is online

Users browsing this forum: No registered users and 25 guests