Skip to content

Fix BLE scanning block after few minutes #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/utility/GAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

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

if (discoveredDevice == NULL) {
if (_discoveredDevices.size() >= GAP_MAX_DISCOVERED_QUEUE_SIZE) {
// drop
return;
BLEDevice* device_first = _discoveredDevices.remove(0);
if (device_first != NULL) {
delete device_first;
}
}

discoveredDevice = new BLEDevice(addressType, address);
Expand Down