espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.41k stars 7.37k forks source link

BLE Advertising whitelist scanFilter not working on ESP32-C6 #9404

Closed JTerminator closed 6 months ago

JTerminator commented 6 months ago

Board

ESP32-6 Dev Module

Device Description

plain ESP32-C6-DevKitM-1

Version

other

IDE Name

Arduino IDE

Operating System

Windows 11

Flash frequency

80Mhz

PSRAM enabled

yes

Upload speed

921600

Description

This code first starts without a scanFilter, and any device can connect (for example with nRF Connect App). After the first connect the address of the peer device is added to the whitelist and advertising is restarted after setScanFilter(true, true). But no device can find the ESP in a new scan and it cannot reconnect. The expected behaviour would be, that the previously connected device can find and connect to the ESP.

I currently only have the ESP32-C6, so I cannot test it on a different ESP32(if somebody else could, it would be greatly appreciated). I read that the C6 has a maximum whitelist length of 15 instead of the 12 other ESPs have. Though when I use the esp_ble_gap_get_whitelist_size(uint16_t *length) I get a length of 12 on the first connect. And when I change the code to leave the scanFilters off, after the second connect, I get a whitelist length of 11.

Sketch

/*
    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleWrite.cpp
    Ported to Arduino ESP32 by Evandro Copercini
*/

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLEAddress.h>

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define ID_UUID "63595b5a-0447-472d-9bfe-b445b01ec253"
#define SERVICE_UUID        "5f321fb2-a94e-4aa6-9a75-af1f3e841446"
#define CHARACTERISTIC_UUID "00001111-0000-1000-8000-00805f9b34fb"

BLEAdvertising *pAdvertising;

union ArrayToInteger {
  uint8_t array[4];
  uint32_t integer;
};

class LayZSecurity : public BLESecurityCallbacks {

    uint32_t onPassKeyRequest(){
        ESP_LOGI(LOG_TAG, "PassKeyRequest");
        return 123456;
    }
    void onPassKeyNotify(uint32_t pass_key){
        ESP_LOGI(LOG_TAG, "The passkey Notify number:%d", pass_key);
    }
    bool onConfirmPIN(uint32_t pass_key){
        ESP_LOGI(LOG_TAG, "The passkey YES/NO number:%d", pass_key);
        vTaskDelay(5000);
        return true;
    }
    bool onSecurityRequest(){
        ESP_LOGI(LOG_TAG, "SecurityRequest");
        return true;
    }

    void onAuthenticationComplete(esp_ble_auth_cmpl_t cmpl){
    esp_ble_gap_clear_whitelist();                    //Adding Adress to Whitelist
    BLEAddress address = BLEAddress(cmpl.bd_addr);
    BLEDevice::whiteListAdd(address);
        ESP_LOGI(LOG_TAG, "Starting BLE work!");

    pAdvertising->setScanFilter(true, true);          //Enableing scanFilter and start advertising again
    BLEDevice::startAdvertising();
    }
};

class MyCallbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
      uint32_t value = *reinterpret_cast<uint32_t*>(pCharacteristic->getData());

        Serial.println("*********");
        Serial.print("New value: ");
          Serial.println(value);
        Serial.println("*********");
    }
};

void setup() {
  Serial.begin(115200);

  pinMode(2,OUTPUT);
  digitalWrite(2, HIGH);
  pinMode(9,INPUT_PULLUP);

  Serial.println("1- Download and install an BLE scanner app in your phone");
  Serial.println("2- Scan for BLE devices in the app");
  Serial.println("3- Connect to MyESP32");
  Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something");
  Serial.println("5- See the magic =)");

  BLEDevice::init("Test Device");
  BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
  BLEDevice::setSecurityCallbacks(new LayZSecurity());
  //BLEDevice::setCustomGapHandler(my_gap_event_handler);

  BLEServer *pServer = BLEDevice::createServer();

  BLEService *pService = pServer->createService(SERVICE_UUID);

  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setCallbacks(new MyCallbacks());

  uint32_t value = 1;
  pCharacteristic->setValue(value);
  pService->start();

  pAdvertising = pServer->getAdvertising();
  pAdvertising->addServiceUUID(ID_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  pAdvertising->setScanFilter(false, false);
  pAdvertising->start();

  BLESecurity *pSecurity = new BLESecurity();
    pSecurity->setKeySize();
    pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND);
    pSecurity->setCapability(ESP_IO_CAP_IO);
    pSecurity->setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);

  Serial.begin(115200);
}

void loop() {
  // if(digitalRead(9)==LOW){
  //   pAdvertising->setScanFilter(false, false);
  //   BLEDevice::startAdvertising();
  //   delay(10000);
  // }
  // pAdvertising->setScanFilter(true, true);
  // BLEDevice::startAdvertising();
  delay(100);
}

Debug Message

ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x4086c410,len:0xc24
load:0x4086e610,len:0x2708
load:0x40875728,len:0x594
entry 0x4086c410
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32-C6
  Package           : 1
  Revision          : 0
  Cores             : 1
  Frequency         : 160 MHz
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : No
  BT Low Energy     : Yes
  IEEE 802.15.4     : Yes
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   433420 B ( 423.3 KB)
  Free Bytes        :   399424 B ( 390.1 KB)
  Allocated Bytes   :    27652 B (  27.0 KB)
  Minimum Free Bytes:   399424 B ( 390.1 KB)
  Largest Free Block:   376820 B ( 368.0 KB)
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         :  4194304 B (4 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 40 MHz
  Bus Mode          : QIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
             spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
           coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Mar 22 2024 14:02:21
  Compile Host OS   : windows
  ESP-IDF Version   : v5.1.2-185-g3662303f31-dirty
  Arduino Version   : 3.0.0
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32C6_DEV
  Arduino Variant   : esp32c6
  Arduino FQBN      : esp32:esp32:esp32c6:UploadSpeed=921600,CDCOnBoot=default,CPUFreq=160,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=debug,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
============ Before Setup End ============
1- Download and install an BLE scanner app in your phone
2- Scan for BLE devices in the app
3- Connect to MyESP32
4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something
5- See the magic =)
controller lib commit: [77d09ce]
[   859][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_REG_EVT
[   870][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_CREATE_EVT
[   881][D][BLEService.cpp:226] addCharacteristic(): Adding characteristic: uuid=00001111-0000-1000-8000-00805f9b34fb to service: UUID: 5f321fb2-a94e-4aa6-9a75-af1f3e841446, handle: 0x0028
[   899][D][BLECharacteristic.cpp:91] executeCreate(): Registering characteristic (esp_ble_gatts_add_char): uuid: 00001111-0000-1000-8000-00805f9b34fb, service: UUID: 5f321fb2-a94e-4aa6-9a75-af1f3e841446, handle: 0x0028
[   918][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_ADD_CHAR_EVT
[   930][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_START_EVT
[   941][I][BLEDevice.cpp:580] getAdvertising(): create advertising
[   947][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[   953][D][BLEAdvertising.cpp:237] start(): - advertising service: 63595b5a-0447-472d-9bfe-b445b01ec253
[   963][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[   969][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 0]
[   977][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[   983][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 1]
[   992][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[   998][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 6]
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   433420 B ( 423.3 KB)
Free Bytes        :   327432 B ( 319.8 KB)
  Allocated Bytes   :    92228 B (  90.1 KB)
  Minimum Free Bytes:   326780 B ( 319.1 KB)
  Largest Free Block:   311284 B ( 304.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
     2 : GPIO
     9 : GPIO
    16 : UART_TX[0]
    17 : UART_RX[0]
============ After Setup End =============
[ 20027][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_CONNECT_EVT
[ 20253][I][BLEDevice.cpp:256] gapEventHandler(): ESP_GAP_BLE_AUTH_CMPL_EVT
[ 20260][I][BLEWriteSecure.ino:48] onAuthenticationComplete(): Starting BLE work!
[ 20267][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20273][D][BLEAdvertising.cpp:237] start(): - advertising service: 63595b5a-0447-472d-9bfe-b445b01ec253
[ 20282][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20288][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 8]
[ 20300][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20306][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 27]
[ 20313][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20319][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 27]
[ 20327][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20333][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 0]
[ 20340][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20346][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 1]
[ 20353][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20359][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 6]
[ 20836][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 20842][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 20]
[ 21285][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 21291][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 20]

Debug Message (Level Verbose)

ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x4086c410,len:0xc24
load:0x4086e610,len:0x2708
load:0x40875728,len:0x594
entry 0x4086c410
[   270][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x420106a6
[   281][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x4201066a
[   293][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x4201062e
[   304][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x420105f2
[   315][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x420106a6
[   327][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x4201066a
[   338][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x4201062e
[   349][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x420105f2
[   370][V][esp32-hal-periman.c:154] perimanSetPinBus(): Pin 17 successfully set to type UART_RX (2) with bus 0x40811364
[   381][V][esp32-hal-periman.c:154] perimanSetPinBus(): Pin 16 successfully set to type UART_TX (3) with bus 0x40811364
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32-C6
  Package           : 1
  Revision          : 0
  Cores             : 1
  Frequency         : 160 MHz
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : No
  BT Low Energy     : Yes
  IEEE 802.15.4     : Yes
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   433420 B ( 423.3 KB)
  Free Bytes        :   399424 B ( 390.1 KB)
  Allocated Bytes   :    27652 B (  27.0 KB)
  Minimum Free Bytes:   399284 B ( 389.9 KB)
  Largest Free Block:   376820 B ( 368.0 KB)
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         :  4194304 B (4 MB)
  Block Size        :    65536 B (  64.0 KB)
Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 40 MHz
  Bus Mode          : QIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
             spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
           coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Mar 22 2024 14:06:00
  Compile Host OS   : windows
  ESP-IDF Version   : v5.1.2-185-g3662303f31-dirty
  Arduino Version   : 3.0.0
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32C6_DEV
  Arduino Variant   : esp32c6
  Arduino FQBN      : esp32:esp32:esp32c6:UploadSpeed=921600,CDCOnBoot=default,CPUFreq=160,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=verbose,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
============ Before Setup End ============
[   703][V][esp32-hal-uart.c:409] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(17) txPin(16)
[   712][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x4200dfb0
[   723][V][esp32-hal-periman.c:154] perimanSetPinBus(): Pin 2 successfully set to type GPIO (1) with bus 0x3
[   733][V][esp32-hal-periman.c:229] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x4200dfb0
[   744][V][esp32-hal-periman.c:154] perimanSetPinBus(): Pin 9 successfully set to type GPIO (1) with bus 0xa
1- Download and install an BLE scanner app in your phone
2- Scan for BLE devices in the app
3- Connect to MyESP32
4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something
5- See the magic =)
controller lib commit: [77d09ce]
[  1026][V][BLEDevice.cpp:79] createServer(): >> createServer
[  1032][V][BLEServer.cpp:293] registerApp(): >> registerApp - 0
[  1038][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: RegisterAppEvt (0x4082e570), owner: <N/A> for registerApp
[  1049][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: RegisterAppEvt (0x4082e570), owner: registerApp
[  1059][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_REG_EVT
[  1069][V][BLEUtils.cpp:1528] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_REG_EVT
[  1077][V][BLEUtils.cpp:1670] dumpGattServerEvent(): [status: ESP_GATT_OK, app_id: 0]
[  1085][V][BLEServer.cpp:145] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_REG_EVT
[  1094][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: RegisterAppEvt (0x4082e570), owner: registerApp
[  1104][V][BLEServer.cpp:283] handleGATTServerEvent(): << handleGATTServerEvent
[  1111][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: RegisterAppEvt (0x4082e570), owner: <N/A> for registerApp
[  1122][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: RegisterAppEvt (0x4082e570), owner: <N/A>
[  1133][V][BLEServer.cpp:297] registerApp(): << registerApp
[  1138][V][BLEDevice.cpp:86] createServer(): << createServer
[  1144][V][BLEServer.cpp:69] createService(): >> createService - 5f321fb2-a94e-4aa6-9a75-af1f3e841446
[  1153][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x40828a6c), owner: <N/A> for createService
[  1163][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x40828a6c), owner: createService
[  1173][V][BLEService.cpp:63] executeCreate(): >> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: 5f321fb2-a94e-4aa6-9a75-af1f3e841446
[  1188][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x4082e7e8), owner: <N/A> for executeCreate
[  1198][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x4082e7e8), owner: executeCreate
[  1208][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_CREATE_EVT
[  1219][V][BLEUtils.cpp:1528] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_CREATE_EVT
[  1227][V][BLEUtils.cpp:1593] dumpGattServerEvent(): [status: ESP_GATT_OK, service_handle: 40 0x28, service_id: [uuid: 5f321fb2-a94e-4aa6-9a75-af1f3e841446, inst_id: 0]]
[  1242][V][BLEServer.cpp:145] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CREATE_EVT
[  1252][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: CreateEvt (0x40828a6c), owner: createService
[  1261][V][BLEService.cpp:197] setHandle(): >> setHandle - Handle=0x28, service UUID=5f321fb2-a94e-4aa6-9a75-af1f3e841446)
[  1272][V][BLEService.cpp:203] setHandle(): << setHandle
[  1277][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: CreateEvt (0x4082e7e8), owner: executeCreate
[  1287][V][BLEServer.cpp:283] handleGATTServerEvent(): << handleGATTServerEvent
[  1294][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: CreateEvt (0x4082e7e8), owner: <N/A> for executeCreate
[  1305][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: CreateEvt (0x4082e7e8), owner: <N/A>
[  1315][V][BLEService.cpp:79] executeCreate(): << executeCreate
[  1321][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: CreateEvt (0x40828a6c), owner: <N/A> for createService
[  1332][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: CreateEvt (0x40828a6c), owner: <N/A>
[  1342][V][BLEServer.cpp:85] createService(): << createService
[  1348][V][BLEService.cpp:225] addCharacteristic(): >> addCharacteristic()
[  1354][D][BLEService.cpp:226] addCharacteristic(): Adding characteristic: uuid=00001111-0000-1000-8000-00805f9b34fb to service: UUID: 5f321fb2-a94e-4aa6-9a75-af1f3e841446, handle: 0x0028
[  1371][V][BLEService.cpp:240] addCharacteristic(): << addCharacteristic()
[  1378][V][BLECharacteristic.cpp:586] setCallbacks(): >> setCallbacks: 0x4082ef2c
[  1385][V][BLECharacteristic.cpp:592] setCallbacks(): << setCallbacks
[  1392][V][BLECharacteristic.cpp:662] setValue(): >> setValue: length=4, data=01000000, characteristic UUID=00001111-0000-1000-8000-00805f9b34fb
[  1405][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: SetValue (0x4082f7d8), owner: <N/A> for <Unknown>
[  1415][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: SetValue (0x4082f7d8), owner: <Unknown>
[  1424][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: SetValue (0x4082f7d8), owner: <Unknown>
[  1433][V][BLECharacteristic.cpp:671] setValue(): << setValue
[  1439][V][BLEService.cpp:137] start(): >> start(): Starting service (esp_ble_gatts_start_service): UUID: 5f321fb2-a94e-4aa6-9a75-af1f3e841446, handle: 0x0028
[  1453][V][BLECharacteristic.cpp:82] executeCreate(): >> executeCreate()
[  1459][D][BLECharacteristic.cpp:91] executeCreate(): Registering characteristic (esp_ble_gatts_add_char): uuid: 00001111-0000-1000-8000-00805f9b34fb, service: UUID: 5f321fb2-a94e-4aa6-9a75-af1f3e841446, handle: 0x0028
[  1479][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x4082eca8), owner: <N/A> for executeCreate
[  1489][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x4082eca8), owner: executeCreate
[  1499][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_ADD_CHAR_EVT
[  1510][V][BLEUtils.cpp:1528] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_ADD_CHAR_EVT
[  1518][V][BLEUtils.cpp:1545] dumpGattServerEvent(): [status: ESP_GATT_OK, attr_handle: 42 0x2a, service_handle: 40 0x28, char_uuid: 00001111-0000-1000-8000-00805f9b34fb]
[  1534][V][BLEServer.cpp:145] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_EVT
[  1543][V][BLECharacteristic.cpp:607] setHandle(): >> setHandle: handle=0x2a, characteristic uuid=00001111-0000-1000-8000-00805f9b34fb
[  1555][V][BLECharacteristic.cpp:609] setHandle(): << setHandle
[  1561][V][BLECharacteristic.cpp:208] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_EVT
[  1571][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: CreateEvt (0x4082eca8), owner: executeCreate
[  1580][V][BLECharacteristic.cpp:468] handleGATTServerEvent(): << handleGATTServerEvent
[  1588][V][BLEServer.cpp:283] handleGATTServerEvent(): << handleGATTServerEvent
[  1595][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: CreateEvt (0x4082eca8), owner: <N/A> for executeCreate
[  1607][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: CreateEvt (0x4082eca8), owner: <N/A>
[  1616][V][BLECharacteristic.cpp:119] executeCreate(): << executeCreate
[  1623][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: StartEvt (0x4082eba0), owner: <N/A> for start
[  1633][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: StartEvt (0x4082eba0), owner: start
[  1642][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_START_EVT
[  1653][V][BLEUtils.cpp:1528] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_START_EVT
[  1661][V][BLEUtils.cpp:1683] dumpGattServerEvent(): [status: ESP_GATT_OK, service_handle: 0x28]
[  1670][V][BLEServer.cpp:145] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_START_EVT
[  1679][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: StartEvt (0x4082eba0), owner: start
[  1688][V][BLECharacteristic.cpp:208] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_START_EVT
[  1697][V][BLECharacteristic.cpp:468] handleGATTServerEvent(): << handleGATTServerEvent
[  1705][V][BLEServer.cpp:283] handleGATTServerEvent(): << handleGATTServerEvent
[  1712][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: StartEvt (0x4082eba0), owner: <N/A> for start
[  1723][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: StartEvt (0x4082eba0), owner: <N/A>
[  1732][V][BLEService.cpp:162] start(): << start()
[  1737][I][BLEDevice.cpp:580] getAdvertising(): create advertising
[  1743][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[  1749][V][BLEAdvertising.cpp:162] setScanFilter(): >> setScanFilter: scanRequestWhitelistOnly: 0, connectWhitelistOnly: 0
[  1760][V][BLEAdvertising.cpp:165] setScanFilter(): << setScanFilter
[  1766][V][BLEAdvertising.cpp:225] start(): >> start: customAdvData: 0, customScanResponseData: 0
[  1775][D][BLEAdvertising.cpp:237] start(): - advertising service: 63595b5a-0447-472d-9bfe-b445b01ec253
[  1785][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
[  1795][V][BLEUtils.cpp:1054] dumpGapEvent(): [status: 0]
[  1800][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[  1806][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 0]
[  1814][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
[  1824][V][BLEUtils.cpp:1204] dumpGapEvent(): [status: 0]
[  1829][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[  1835][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 1]
[  1844][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_START_COMPLETE_EVT
[  1853][V][BLEUtils.cpp:1072] dumpGapEvent(): [status: 0]
[  1859][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[  1865][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 6]
[  1872][V][BLEAdvertising.cpp:290] start(): << start
[  1878][V][esp32-hal-uart.c:409] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(-1) txPin(-1)
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   433420 B ( 423.3 KB)
  Free Bytes        :   327432 B ( 319.8 KB)
  Allocated Bytes   :    92228 B (  90.1 KB)
  Minimum Free Bytes:   326780 B ( 319.1 KB)
  Largest Free Block:   311284 B ( 304.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
     2 : GPIO
     9 : GPIO
    16 : UART_TX[0]
    17 : UART_RX[0]
============ After Setup End =============
[ 10645][D][BLEDevice.cpp:103] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_CONNECT_EVT
[ 10656][V][BLEUtils.cpp:1528] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_CONNECT_EVT
[ 10665][V][BLEUtils.cpp:1586] dumpGattServerEvent(): [conn_id: 0, remote_bda: xx:xx:xx:xx:xx:xx]
[ 10673][V][BLEServer.cpp:145] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CONNECT_EVT
[ 10683][V][BLECharacteristic.cpp:208] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CONNECT_EVT
[ 10693][V][BLECharacteristic.cpp:468] handleGATTServerEvent(): << handleGATTServerEvent
[ 10701][V][BLEServer.cpp:283] handleGATTServerEvent(): << handleGATTServerEvent
[ 10871][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_AUTH_CMPL_EVT
[ 10880][V][BLEUtils.cpp:1096] dumpGapEvent(): [bd_addr: xx:xx:xx:xx:xx:xx, key_present: 0, key: ***, key_type: 0, success: 1, fail_reason: 0, addr_type: ***, dev_type: ESP_BT_DEVICE_TYPE_BLE]
[ 10897][I][BLEDevice.cpp:256] gapEventHandler(): ESP_GAP_BLE_AUTH_CMPL_EVT
[ 10904][V][BLEDevice.cpp:504] whiteListAdd(): >> whiteListAdd: xx:xx:xx:xx:xx:xx
[ 10911][V][BLEDevice.cpp:513] whiteListAdd(): << whiteListAdd
[ 10917][I][BLEWriteSecure.ino:48] onAuthenticationComplete(): Starting BLE work!
[ 10924][V][BLEAdvertising.cpp:162] setScanFilter(): >> setScanFilter: scanRequestWhitelistOnly: 1, connectWhitelistOnly: 1
[ 10935][V][BLEAdvertising.cpp:180] setScanFilter(): << setScanFilter
[ 10941][V][BLEDevice.cpp:587] startAdvertising(): >> startAdvertising
[ 10947][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 10953][V][BLEAdvertising.cpp:225] start(): >> start: customAdvData: 0, customScanResponseData: 0
[ 10962][D][BLEAdvertising.cpp:237] start(): - advertising service: 63595b5a-0447-472d-9bfe-b445b01ec253
[ 10971][V][BLEAdvertising.cpp:290] start(): << start
[ 10976][V][BLEDevice.cpp:589] startAdvertising(): << startAdvertising
[ 10983][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 10988][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 8]
[ 11000][V][BLEUtils.cpp:1816] gapEventToString(): gapEventToString: Unknown event type 27 0x1b
[ 11000][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: Unknown event type
[ 11017][V][BLEUtils.cpp:1262] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[ 11024][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11030][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 27]
[ 11037][V][BLEUtils.cpp:1816] gapEventToString(): gapEventToString: Unknown event type 27 0x1b
[ 11037][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: Unknown event type
[ 11054][V][BLEUtils.cpp:1262] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[ 11061][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11067][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 27]
[ 11075][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
[ 11084][V][BLEUtils.cpp:1054] dumpGapEvent(): [status: 0]
[ 11090][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11095][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 0]
[ 11103][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
[ 11113][V][BLEUtils.cpp:1204] dumpGapEvent(): [status: 0]
[ 11118][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11124][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 1]
[ 11131][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_START_COMPLETE_EVT
[ 11140][V][BLEUtils.cpp:1072] dumpGapEvent(): [status: 0]
[ 11146][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11151][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 6]
[ 11455][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT
[ 11464][V][BLEUtils.cpp:1243] dumpGapEvent(): [status: 0, bd_addr: xx:xx:xx:xx:xx:xx, min_int: 0, max_int: 0, latency: 0, conn_int: 6, timeout: 500]
[ 11477][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11483][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 20]
[ 11754][V][BLEUtils.cpp:1047] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT
[ 11763][V][BLEUtils.cpp:1243] dumpGapEvent(): [status: 0, bd_addr: xx:xx:xx:xx:xx:xx, min_int: 0, max_int: 0, latency: 0, conn_int: 36, timeout: 500]
[ 11776][D][BLEDevice.cpp:582] getAdvertising(): get advertising
[ 11782][D][BLEAdvertising.cpp:544] handleGAPEvent(): handleGAPEvent [event no: 20]

Other Steps to Reproduce

Upload to ESP -> Connect with nRF Connect -> Disconnect -> Scan

I have checked existing issues, online documentation and the Troubleshooting Guide

JTerminator commented 6 months ago

After reading some more this seems to be a problem with the esp-idf or ESP32 hardware and RPA devices.

JTerminator commented 6 months ago

I also found this So I will have to use a workaround as the whitelist does not work with Android devices.

This issue can be closed.