From 9285a9b31f317d3a12b518af943022e0b3fb93b6 Mon Sep 17 00:00:00 2001 From: h2zero Date: Sat, 4 Jun 2022 14:24:30 -0600 Subject: [PATCH] Don't call scan result callback if it was already called. --- src/NimBLEScan.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/NimBLEScan.cpp b/src/NimBLEScan.cpp index eb87df8..378f66b 100644 --- a/src/NimBLEScan.cpp +++ b/src/NimBLEScan.cpp @@ -34,7 +34,7 @@ NimBLEScan::NimBLEScan() { m_scan_params.itvl = 0; // This is defined as the time interval from when the Controller started its last LE scan until it begins the subsequent LE scan. (units=0.625 msec) m_scan_params.window = 0; // The duration of the LE scan. LE_Scan_Window shall be less than or equal to LE_Scan_Interval (units=0.625 msec) m_scan_params.limited = 0; // If set, only discover devices in limited discoverable mode. - m_scan_params.filter_duplicates = 0; // If set, the controller ignores all but the first advertisement from each device. + m_scan_params.filter_duplicates = 1; // If set, the controller ignores all but the first advertisement from each device. m_pAdvertisedDeviceCallbacks = nullptr; m_ignoreResults = false; m_pTaskData = nullptr; @@ -134,6 +134,10 @@ NimBLEScan::~NimBLEScan() { event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP)); if (pScan->m_pAdvertisedDeviceCallbacks) { + if (pScan->m_scan_params.filter_duplicates && advertisedDevice->m_callbackSent) { + return 0; + } + // If not active scanning or scan response is not available // or extended advertisement scanning, report the result to the callback now. if(pScan->m_scan_params.passive || !isLegacyAdv ||