h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
672 stars 138 forks source link

BLE Server, when Whitelist is active device cannot be seen or connected to #554

Open sanastasiou opened 1 year ago

sanastasiou commented 1 year ago

Hi @h2zero and thanks for this amazing lib. I have the following code:

    void BluetoothController::addBondedDevicesToWhitelist()
    {
        const auto numberOfBondedDevices = NimBLEDevice::getNumBonds();
        for(auto i = 0U; i < numberOfBondedDevices; ++i)
        {
            std::cout << "Adding bonded ble client with address:  " << NimBLEDevice::getBondedAddress(i) << " to whitelist." << std::endl;
            NimBLEDevice::whiteListAdd(NimBLEDevice::getBondedAddress(i));
            std::cout << "Number of whitelisted devices: " << NimBLEDevice::getWhiteListCount() << std::endl;
        }
    }

Adding bonded ble client with address:  70704663222491 to whitelist.

This happens during initialization. You can assume I already have a bonded device. So that works fine.

Now, after that initialization, I want to restrict my server that it only is scanable and can be connected from whitelisted devices:

            fPAdvertisingData->stop();
            fPAdvertisingData->setScanFilter(true,true);
            fPAdvertisingData->start();

After this called my device is visible but does not get a scan reply and cannot be connected from my bonded client.

Deactivating either the 1st or 2nd flag gives the correct results. So I am a bit confused now as to why this does not work, given that the bonded address and whitelisted address are one and the same, and also the same as the address of my client when it tries to connect.

I can provide with more debug info if necessary.

h2zero commented 1 month ago

Sorry @sanastasiou, no idea why this wouldn't work. Are you still having this issue?