Commit graph

14 commits

Author SHA1 Message Date
h2zero
82524c80e3 [NimBLEScan] Use controller duplicate filter and add max result limit.
* Adds setMaxResults to NimBLEScan to limit the number of advertised devices stored.
  If set to 0 no devices will be stored in memory and only the callback will be invoked.
  If set to 0xFF (default) stored devices will be unlimited. Any other value will be the limit.

* Uses the controller to filter duplicate devices from the scan results when wantDuplicates == false.
2021-01-30 18:27:06 -07:00
Asuki Kono
f61bd5c2df Add option to use resolvable and non-resolvable private address.
Adds the possibility to configure a resolvable or non-resolvable address (BLE privacy).
2021-01-13 18:01:41 -07:00
h2zero
372c79a6b8 Only start scan/advertise when host re-synced if duration was indefinite.
Previously when the host reset while scanning (if active prior) it would be restarted automatically.
This caused errors for some applications and has been removed since the event invokes the scan
ended callback for the app to take action. Instead scanning will now only be restarted if the duration
was indefinite and a callback was set for the advertisment events, this use case is less likely to have
a scan ended callback.

Advertising (if active prior) would be started without regard to it's previous state.
This has been corrected to only start advertising again if it was advertising for an idefinite time.
2021-01-12 20:42:19 -07:00
h2zero
8fe2766e01 Remove loop on BLE_HS_EBUSY in NimBLEScan::start
The BLE_HS_EBUSY return code was causing the application to hang when starting scan as
occasionally the code would not change, resulting in an infinite loop.

This patch handles the return code more appopriately and removes the loop.

Additionally a race condition would sometimes allow the code to execute past the conditional checks
and clear the advertised device vector while a scan was active and writing to it causing an exception.
This has been hopefully corrected by only clearing the vector if the return code from starting the scan is 0.
2021-01-10 21:54:32 -07:00
h2zero
abdf6cda35
Add clearAll parameter to deinit() (#22)
* Add clearAll parameter to deinit()

Adds the ability to clear all resources consumed during BLE operation when deinitializing and shutting down BLE.
Useful when BLE is used intermittently or in a task that initializes, performs operations then deinitializes.

By setting the clearAll parameter to true all created BLE objects will be deleted, freeing the memory for other tasks.

Warning: This will invalidate any pointers that may be referencing the deleted objects.

* Add bool deleteCallbacks parameter to NimBLEServer::setCallbacks, if true (default) will delete the callback class when server is destructed.

* Delete scan results when scan is destructed.
2020-07-28 20:57:33 -06:00
h2zero
fe4586a3ca NimBLEScan: Add isScanning method.
Adds a method to check if the scan is currently running.

* Clear up some NimBLEScan method parameter semantics.
2020-07-23 20:18:41 -06:00
h2zero
aae2a8f1e3
Fix comments for doxygen (#16)
* Fix comments for doxygen

* Add documentation and update readme.
2020-07-08 19:27:26 -06:00
h2zero
745f9c00ed Implement scan wantDuplicates parameter in callback registration.
Also adds:
* NimBLEScan::setDuplicateFilter() to tell the controller to filter duplicates
before sending the result to the host.

* NimBLEScan::setLimitedOnly() to tell the controller only report scan results
from devices advertising in limited discovery mode, i.e. directed advertising.

* NimBLEScan::setFilterPolicy() to set the filter policy i.e whitelist only devices.
2020-07-01 17:26:44 -06:00
h2zero
f5541d18de
Replace semaphores with task notifications. (#9)
* Replace all semaphores with task notifications.

* use critical sections to prevent concurrent data access.

* Ensure scan stop has been called before connecting.

* Optimize and cleanup

* Add template casting to NimBLERemoteDescriptor::readValue()

* Removed storage of the descriptor value read as it did not serve any purpose.
2020-06-21 22:07:01 -06:00
h2zero
10e50a8791 Add iterators to client remote attributes.
Add iterators for NimBLEScan: NimBLEadvertisedDevice, NimBLEClient: NimBLERemoteService, NimBLERemoteService: NimBLERemoteCharacteristic and NimBLERemoteCharacteristic: NimBLERemoteDescriptor

This is handy e.g. for showing every address of the advertised devices from a scan. To do so, first get a new scan and next:
```
for(auto pAdvertisedDevice: pBLEScan->getResults()) {
  Serial.printf("Address is %s\n", std::string(pAdvertisedDevice->getAddress()).c_str());
}
```
Of course any other property of the advertised device can be shown (or looked up, if that is your use case)

Also this is handy e.g. for showing every UUID in a peripheral. To do so, first connect to a peripheral and next:
```
for(auto pService: *pClient) {
  Serial.printf("Service UUID is %s\n", std::string(pService->getUUID()).c_str());
  for(auto pCharacteristic: *pService) {
    Serial.printf("Characteristic UUID is %s\n", std::string(pCharacteristic->getUUID()).c_str());
    for(auto pDescriptor: *pCharacteristic) {
      Serial.printf("Descriptor UUID is %s\n", std::string(pDescriptor->getUUID()).c_str());
    }
  }
}
```
Again of course any other property can be shown, or looked up.
2020-05-22 20:13:52 -06:00
h2zero
6f4ee4b498 Breaking: Use std::vector instead of std::map in client classes (#46)
* Exchange map for vector, saving 1,076 bytes of program memory and 5,024 bytes of heap for a small device (LYWSD03MMC)

* Removing m_characteristicMapByHandle (using the handles form m_characteristicVector instead) saving in total (compared to the current master) 1,508 bytes of program memory and 6,500 bytes of heap for a small device (LYWSD03MMC)

* Change NimBLEScan container from std::map to std::vector

* Add function to get advertised device by address

* Update documentation
2020-05-17 20:22:58 -06:00
h2zero
03cb7b21d9 Conditionally compile code for specific roles.
This allows NimBLE options in menuconfig to reduce code size based on
the roles selected (scan/advertising/central/peripheral).

Significant code space can be saved by removing unnecessary roles for the application.
2020-05-13 22:03:56 -06:00
h2zero
f0191eb1e6 Add ==,!= operators to NimBLEAddress, pass parameters by const reference. 2020-05-10 07:21:46 -06:00
h2zero
5d4332e945 Initial commit. 2020-03-29 17:44:20 -06:00