From 07d249acb64f07b2fa338355c7852d519d328b72 Mon Sep 17 00:00:00 2001 From: Steve Allasia <40604011+sallasia@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:07:44 +0200 Subject: [PATCH 1/2] Fix BLE scanning block after few minutes --- src/utility/GAP.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index f3ee32fa..08c9c3f0 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -22,7 +22,7 @@ #include "GAP.h" -#define GAP_MAX_DISCOVERED_QUEUE_SIZE 5 +#define GAP_MAX_DISCOVERED_QUEUE_SIZE 32 #define GAP_ADV_IND (0x00) #define GAP_ADV_SCAN_IND (0x02) @@ -86,8 +86,14 @@ int GAPClass::scan(bool withDuplicates) { HCI.leSetScanEnable(false, true); - // active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public own address type, no filter - if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, 0x00, 0x00) != 0) { + // active scan, 20 ms scan interval (N * 0.625), 20 ms scan window (N * 0.625), public own address type, no filter + /* + Warning (from BLUETOOTH SPECIFICATION 5.x): + - scan interval: mandatory range from 0x0012 to 0x1000; only even values are valid + - scan window: mandatory range from 0x0011 to 0x1000 + - The scan window can only be less than or equal to the scan interval + */ + if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, 0x00, 0x00) != 0) { return false; } @@ -216,8 +222,11 @@ void GAPClass::handleLeAdvertisingReport(uint8_t type, uint8_t addressType, uint if (discoveredDevice == NULL) { if (_discoveredDevices.size() >= GAP_MAX_DISCOVERED_QUEUE_SIZE) { - // drop - return; + // delete data in first list posistion + BLEDevice* device_first = _discoveredDevices.remove(0); + if (device_first != NULL) { + delete device_first; + } } discoveredDevice = new BLEDevice(addressType, address); From c928892cc1eb89de2a112bdf0844fc5252067ccc Mon Sep 17 00:00:00 2001 From: Steve Allasia <40604011+sallasia@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:26:48 +0200 Subject: [PATCH 2/2] Update GAP.cpp Removed comment --- src/utility/GAP.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index 08c9c3f0..f1bf02fe 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -222,7 +222,6 @@ void GAPClass::handleLeAdvertisingReport(uint8_t type, uint8_t addressType, uint if (discoveredDevice == NULL) { if (_discoveredDevices.size() >= GAP_MAX_DISCOVERED_QUEUE_SIZE) { - // delete data in first list posistion BLEDevice* device_first = _discoveredDevices.remove(0); if (device_first != NULL) { delete device_first;