Skip to content

Commit ccdca60

Browse files
authored
Merge pull request #264 from sallasia/steve_allasia
Fix BLE scanning block after few minutes
2 parents dd56eb7 + c928892 commit ccdca60

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: src/utility/GAP.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "GAP.h"
2424

25-
#define GAP_MAX_DISCOVERED_QUEUE_SIZE 5
25+
#define GAP_MAX_DISCOVERED_QUEUE_SIZE 32
2626

2727
#define GAP_ADV_IND (0x00)
2828
#define GAP_ADV_SCAN_IND (0x02)
@@ -86,8 +86,14 @@ int GAPClass::scan(bool withDuplicates)
8686
{
8787
HCI.leSetScanEnable(false, true);
8888

89-
// active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public own address type, no filter
90-
if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, 0x00, 0x00) != 0) {
89+
// active scan, 20 ms scan interval (N * 0.625), 20 ms scan window (N * 0.625), public own address type, no filter
90+
/*
91+
Warning (from BLUETOOTH SPECIFICATION 5.x):
92+
- scan interval: mandatory range from 0x0012 to 0x1000; only even values are valid
93+
- scan window: mandatory range from 0x0011 to 0x1000
94+
- The scan window can only be less than or equal to the scan interval
95+
*/
96+
if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, 0x00, 0x00) != 0) {
9197
return false;
9298
}
9399

@@ -216,8 +222,10 @@ void GAPClass::handleLeAdvertisingReport(uint8_t type, uint8_t addressType, uint
216222

217223
if (discoveredDevice == NULL) {
218224
if (_discoveredDevices.size() >= GAP_MAX_DISCOVERED_QUEUE_SIZE) {
219-
// drop
220-
return;
225+
BLEDevice* device_first = _discoveredDevices.remove(0);
226+
if (device_first != NULL) {
227+
delete device_first;
228+
}
221229
}
222230

223231
discoveredDevice = new BLEDevice(addressType, address);

0 commit comments

Comments
 (0)