esp-nimble-cpp  1.4.1
NimBLEScan Class Reference

Perform and manage BLE scans. More...

Public Member Functions

bool start (uint32_t duration, void(*scanCompleteCB)(NimBLEScanResults), bool is_continue=false)
 Start scanning. More...
 
NimBLEScanResults start (uint32_t duration, bool is_continue=false)
 Start scanning and block until scanning has been completed. More...
 
bool isScanning ()
 Get the status of the scanner. More...
 
void setAdvertisedDeviceCallbacks (NimBLEAdvertisedDeviceCallbacks *pAdvertisedDeviceCallbacks, bool wantDuplicates=false)
 Set the call backs to be invoked. More...
 
void setActiveScan (bool active)
 Should we perform an active or passive scan? The default is a passive scan. An active scan means that we will request a scan response. More...
 
void setInterval (uint16_t intervalMSecs)
 Set the interval to scan. More...
 
void setWindow (uint16_t windowMSecs)
 Set the window to actively scan. More...
 
void setDuplicateFilter (bool enabled)
 Set whether or not the BLE controller should only report results from devices it has not already seen. More...
 
void setLimitedOnly (bool enabled)
 Set whether or not the BLE controller only report scan results from devices advertising in limited discovery mode, i.e. directed advertising. More...
 
void setFilterPolicy (uint8_t filter)
 Sets the scan filter policy. More...
 
void clearDuplicateCache ()
 Clears the duplicate scan filter cache.
 
bool stop ()
 Stop an in progress scan. More...
 
void clearResults ()
 Clear the results of the scan.
 
NimBLEScanResults getResults ()
 Get the results of the scan. More...
 
void setMaxResults (uint8_t maxResults)
 Sets the max number of results to store. More...
 
void erase (const NimBLEAddress &address)
 Delete peer device from the scan results vector. More...
 

Detailed Description

Perform and manage BLE scans.

Scanning is associated with a BLE client that is attempting to locate BLE servers.

Member Function Documentation

◆ erase()

void NimBLEScan::erase ( const NimBLEAddress address)

Delete peer device from the scan results vector.

Parameters
[in]addressThe address of the device to delete from the results.

After disconnecting, it may be required in the case we were connected to a device without a public address.

◆ getResults()

NimBLEScanResults NimBLEScan::getResults ( )

Get the results of the scan.

Returns
NimBLEScanResults object.

◆ isScanning()

bool NimBLEScan::isScanning ( )

Get the status of the scanner.

Returns
true if scanning or scan starting.

◆ setActiveScan()

void NimBLEScan::setActiveScan ( bool  active)

Should we perform an active or passive scan? The default is a passive scan. An active scan means that we will request a scan response.

Parameters
[in]activeIf true, we perform an active scan otherwise a passive scan.

◆ setAdvertisedDeviceCallbacks()

void NimBLEScan::setAdvertisedDeviceCallbacks ( NimBLEAdvertisedDeviceCallbacks pAdvertisedDeviceCallbacks,
bool  wantDuplicates = false 
)

Set the call backs to be invoked.

Parameters
[in]pAdvertisedDeviceCallbacksCall backs to be invoked.
[in]wantDuplicatesTrue if we wish to be called back with duplicates. Default is false.

◆ setDuplicateFilter()

void NimBLEScan::setDuplicateFilter ( bool  enabled)

Set whether or not the BLE controller should only report results from devices it has not already seen.

Parameters
[in]enabledIf true, scanned devices will only be reported once.

The controller has a limited buffer and will start reporting duplicate devices once the limit is reached.

◆ setFilterPolicy()

void NimBLEScan::setFilterPolicy ( uint8_t  filter)

Sets the scan filter policy.

Parameters
[in]filterCan be one of:
  • BLE_HCI_SCAN_FILT_NO_WL (0) Scanner processes all advertising packets (white list not used) except
    directed, connectable advertising packets not sent to the scanner.
  • BLE_HCI_SCAN_FILT_USE_WL (1) Scanner processes advertisements from white list only. A connectable,
    directed advertisement is ignored unless it contains scanners address.
  • BLE_HCI_SCAN_FILT_NO_WL_INITA (2) Scanner process all advertising packets (white list not used). A
    connectable, directed advertisement shall not be ignored if the InitA is a resolvable private address.
  • BLE_HCI_SCAN_FILT_USE_WL_INITA (3) Scanner process advertisements from white list only. A connectable,
    directed advertisement shall not be ignored if the InitA is a resolvable private address.

◆ setInterval()

void NimBLEScan::setInterval ( uint16_t  intervalMSecs)

Set the interval to scan.

Parameters
[in]intervalMSecsThe scan interval (how often) in milliseconds.

◆ setLimitedOnly()

void NimBLEScan::setLimitedOnly ( bool  enabled)

Set whether or not the BLE controller only report scan results from devices advertising in limited discovery mode, i.e. directed advertising.

Parameters
[in]enabledIf true, only limited discovery devices will be in scan results.

◆ setMaxResults()

void NimBLEScan::setMaxResults ( uint8_t  maxResults)

Sets the max number of results to store.

Parameters
[in]maxResultsThe number of results to limit storage to
0 == none (callbacks only) 0xFF == unlimited, any other value is the limit.

◆ setWindow()

void NimBLEScan::setWindow ( uint16_t  windowMSecs)

Set the window to actively scan.

Parameters
[in]windowMSecsHow long to actively scan.

◆ start() [1/2]

NimBLEScanResults NimBLEScan::start ( uint32_t  duration,
bool  is_continue = false 
)

Start scanning and block until scanning has been completed.

Parameters
[in]durationThe duration in seconds for which to scan.
[in]is_continueSet to true to save previous scan results, false to clear them.
Returns
The NimBLEScanResults.

◆ start() [2/2]

bool NimBLEScan::start ( uint32_t  duration,
void(*)(NimBLEScanResults scanCompleteCB,
bool  is_continue = false 
)

Start scanning.

Parameters
[in]durationThe duration in seconds for which to scan.
[in]scanCompleteCBA function to be called when scanning has completed.
[in]is_continueSet to true to save previous scan results, false to clear them.
Returns
True if scan started or false if there was an error.

◆ stop()

bool NimBLEScan::stop ( )

Stop an in progress scan.

Returns
True if successful.