From 5919d117d4b830067a8a1c60137cf55bd1159145 Mon Sep 17 00:00:00 2001 From: Jens Hauke Date: Wed, 23 Sep 2020 16:58:01 +0200 Subject: [PATCH] Fix for missed scan response data (BLEScan). This is a fix for missing scan responses after a first successfull scan. While running the BLE_scan.ino sketch with wantDuplicates=false, i got only one result with correct advertising and scan response length (31,26): pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), false); pBLEScan->start(scanTime, false); ... [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 31 + 26, addr type: 1 All following calls to start() just returned the advertising data without scan response data: pBLEScan->start(scanTime, false); [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 31 + 0, addr type: 1 With "wantDuplicates=true" i got: pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true); pBLEScan->start(scanTime, false); [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 31 + 26, addr type: 1 [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 31 + 26, addr type: 1 [W][BLEScan.cpp:73] handleGAPEvent(): ESP_GAP_SEARCH_INQ_CMPL_EVT Devices found: 1 Scan done! pBLEScan->start(scanTime, false); [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 31 + 0, addr type: 1 [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 0 + 26, addr type: 1 [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 31 + 0, addr type: 1 [W][BLEScan.cpp:109] handleGAPEvent(): bytes length: 0 + 26, addr type: 1 Explicitly initializing m_scan_params.scan_duplicate of BLEScan solves this issue (In my case the un-initialized value was m_scan_params.scan_duplicate == 1073599044). --- libraries/BLE/src/BLEScan.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/BLE/src/BLEScan.cpp b/libraries/BLE/src/BLEScan.cpp index cb28dd395a7..3b2eb43960b 100644 --- a/libraries/BLE/src/BLEScan.cpp +++ b/libraries/BLE/src/BLEScan.cpp @@ -22,9 +22,11 @@ * Constructor */ BLEScan::BLEScan() { + memset(&m_scan_params, 0, sizeof(m_scan_params)); // Initialize all params m_scan_params.scan_type = BLE_SCAN_TYPE_PASSIVE; // Default is a passive scan. m_scan_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC; m_scan_params.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL; + m_scan_params.scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE; m_pAdvertisedDeviceCallbacks = nullptr; m_stopped = true; m_wantDuplicates = false;