Commit graph

192 commits

Author SHA1 Message Date
h2zero
d3a0f95aaf Add whitelist API.
This adds the functions:
- bool NimBLEDevice::whiteListAdd(const NimBLEAddress & address);
- bool NimBLEDevice::whiteListRemove(const NimBLEAddress & address);
- bool NimBLEDevice::onWhiteList(const NimBLEAddress & address);
- size_t NimBLEDevice::getWhiteListCount();
- NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index);
2021-05-23 13:12:44 -06:00
h2zero
d9d794ae40 [Server] Add ability to create static attributes.
This allows creating instances of services/characteristics and decriptors without
needing to call the parent createX() methods. This allows creation of the attibutes
within a class or other structure and the attributes can be linked to the parent by
calling the parent addX() method.

Additonally this increases the backward compatibility with the original bluedroid library
to further support user migration.
2021-05-23 13:07:00 -06:00
boozer2
30d6c399b8 [Client] Fix for truncation of strings with null in writeValue std::string overload 2021-05-21 19:54:08 -06:00
Bascy
7815d89dbf Call onSubscribe() after adding connection to subscribedVector
This allows for sending BLE messages in the onSubscribe() handler
2021-05-19 22:28:30 -06:00
Ketan Padegaonkar
9fa9531e50 Add method to get the callbacks from a characteristic.
This is useul to be able to unit/integration test the behavior of a
characteristic.
2021-05-19 22:23:40 -06:00
h2zero
946b971750 Properly find the remote characteristic end handle for descriptor discovery.
Previously we used the service end handle or, if available, the handle of the next characteristic in the service
as the end handle when retrieving the descriptors of a characteristic. This process would fail when connecting to some
devices if the characteristics were retrieved individually instead of all together. The cause of failure was requesting
a handle range that is out of characteristic scope which is also out of line with BLE
specifications.

The fix included in this is to set the end handles of the characteristics either after retrieving all the characteristics
in a service by using the next charactertistic definition handle or, if the characteristic was retrieved separately,
we retrieve the next characteristic just before retrieving the descriptors.
2021-05-17 14:37:03 -06:00
h2zero
b62358a520 Remove task notification for server indications.
This resolves an issue when sending an indication from a callback that can cause the server to hang.
2021-05-17 14:08:02 -06:00
h2zero
e45fb8616a Cleanup logs. 2021-05-15 09:52:00 -06:00
h2zero
d38865e022 Remove some asserts. 2021-05-07 11:06:45 -06:00
h2zero
62d1f67d8b Add connection info class and access methods to server and client.
This adds the ability to access information about the current connection.
A new class was created to wrap the struct ble_gap_conn_desc with methods to retrieve the connection information.

Example server use:
```
for(auto i=0; i<pServer->getConnectedCount();i++) {
    NimBLEConnInfo connInfo = pServer->getPeerInfo(i);
    printf("Connected client %d info:\n", i);
    printf("Peer address: %s\n", connInfo.getAddress().toString().c_str());
    printf("Peer ID address: %s\n", connInfo.getIdAddress().toString().c_str());
    printf("Handle: %u\n", connInfo.getConnHandle());
    printf("Interval: %u\n", connInfo.getConnInterval());
    printf("Timeout: %u\n", connInfo.getConnTimeout());
    printf("Latency: %u\n", connInfo.getConnLatency());
    printf("MTU: %u\n", connInfo.getMTU());
    printf("Master: %s\n", connInfo.isMaster()? "true":"false");
    printf("Slave: %s\n", connInfo.isSlave()? "true":"false");
    printf("Bonded: %s\n", connInfo.isBonded()? "true":"false");
    printf("Authenticated: %s\n", connInfo.isAuthenticated()? "true":"false");
    printf("Encrypted: %s\n", connInfo.isEncrypted()? "true":"false");
    printf("Encryption Key Size: %u\n", connInfo.getSecKeySize());
}
```

Example client use:
```
if (pClient->isConnected()) {
    NimBLEConnInfo connInfo = pClient->getConnInfo();
    printf("Connection info:\n");
    printf("Peer address: %s\n", connInfo.getAddress().toString().c_str());
    printf("Peer ID address: %s\n", connInfo.getIdAddress().toString().c_str());
    printf("Handle: %u\n", connInfo.getConnHandle());
    printf("Interval: %u\n", connInfo.getConnInterval());
    printf("Timeout: %u\n", connInfo.getConnTimeout());
    printf("Latency: %u\n", connInfo.getConnLatency());
    printf("MTU: %u\n", connInfo.getMTU());
    printf("Master: %s\n", connInfo.isMaster()? "true":"false");
    printf("Slave: %s\n", connInfo.isSlave()? "true":"false");
    printf("Bonded: %s\n", connInfo.isBonded()? "true":"false");
    printf("Authenticated: %s\n", connInfo.isAuthenticated()? "true":"false");
    printf("Encrypted: %s\n", connInfo.isEncrypted()? "true":"false");
    printf("Encryption Key Size: %u\n", connInfo.getSecKeySize());
}
```
2021-05-07 09:02:43 -06:00
h2zero
4f8342e275 Add bond management API.
* Adds these new methods to NimBLEDevice to manage bonded peers:

- NimBLEDevice::deleteBond(const NimBLEAddress &address);
- NimBLEDevice::getNumBonds();
- NimBLEDevice::isBonded(const NimBLEAddress &address);
- NimBLEDevice::deleteAllBonds();
- NimBLEDevice::getBondedAddress(int index);
2021-04-25 08:06:38 -06:00
h2zero
05080abad4 Add clear scan duplicate filter cache method + clear on start.
This allows for clearing the duplicate filter cache when required and will also clear it
automatically when starting a scan.

This is useful when unexpectedly disconnected from a device and attempting to reconnect.
Previously the scan filter would not report advertisements from a device if it was multi-connectable
and advertising while connected. The result was long delays until the device would be scanned again.
This resolves it by clearing the filter cache on each scan start/clearResults call
and adding a method to NimBLEScan for manually clearing the cache on demand.
2021-03-31 20:24:57 -06:00
h2zero
f5eab87a87 Fix missing data in long write to descriptor. 2021-03-31 17:43:19 -06:00
David Robertson
3227681476
Use ESP_LOGx macros for logging (#42)
This allows filtering of this components logging when using higher log levels in IDF.
2021-03-28 14:47:30 -06:00
Aron Rubin
cf3227503b
Use more stable arduino detection methods (#38)
* Use a more stable arduino detection macro.

* Detection method for both IDF config phases. Newer IDF API and targets.
2021-03-04 21:00:21 -07:00
h2zero
ef049ddf19 Fix compile errors in latest IDF (NimBLE 1.3.0) see (#37).
Const qualifiers were added to multiple struct members in NimBLE 1.3.0.
This solves compilation errors related to those.
2021-02-10 10:54:53 -07:00
h2zero
7bec9c240a Release 1.2.0 2021-02-08 11:46:11 -07:00
David Robertson
7dd4d68806
[NimBLEServer] Support duplicate characteristics (#36)
* Add method to get all characteristics of a service

* Added method on NimBLEDescriptor to get the value out as a std::string

* Added methods to get things by handle where UUID could be used already.

* Added helper methods for getting a list of characteristics with a given UUID and service

* Demote the warning log for adding duplicate characteristics to a debug level log.

* Add methods to get services and characteristics using UUID + index
2021-02-08 08:28:32 -07:00
h2zero
28d6492ea4 NimBLEAdvertising::reset check if the stack is initialized before stop.
This prevents an exception when initializing a NimBLEAdvertising instance before calling NimBLEDevice::init().
The constructor calls reset() which calls stop(), if the stack was not yet initialized it will cause an exception.
2021-02-07 22:26:02 -07:00
h2zero
dff5122ce2 Add complementary methods to NimBLEAdvertising and NimBLEAdvertisementData
Previous to this NimBLEAdvertising did not have some functionality that was in NimBLEAdvertisementData.
Also NimBLEAdvertisementData was missing functionality that exists in NimBLEAdvertising.

This resolves that by adding the missing functions to both classes.

Changed:
NimBLEAdvertising: Transmission power is no longer advertised by default and can be added to the advertisement by calling ::addTxPower()

Added:
- NimBLEAdvertising::setName
- NimBLEAdvertising::setManufacturerData
- NimBLEAdvertising::setURI
- NimBLEAdvertising::setServiceData
- NimBLEAdvertising::addTxPower
- NimBLEAdvertising::reset

- NimBLEAdvertisementData::addTxPower
- NimBLEAdvertisementData::setPreferredParams
- NimBLEAdvertisementData::setURI
2021-02-07 20:33:57 -07:00
h2zero
6e104dfb45 Allow custom scan response data without custom advertising.
This lets applications use custom scan response data while using the advertisment data added by the NimBLEAdvertising add/set methods.
2021-02-06 14:29:03 -07:00
h2zero
b290ca9077 [NimBLEAdvertisementData] Add setServices methods for multiple UUID's
Adds:
- setPartialServices16
- setPartialServices32
- setCompleteServices16
- setCompleteServices32

Each takes an input parameter of std::vector<NimBLEUUID> to allow for advertising multiple services with a simple interface.
2021-02-06 13:27:12 -07:00
h2zero
ae2ff3a638 Fix Documentation. 2021-02-06 11:12:40 -07:00
h2zero
af24cd7720 Add controller scan filter options and refactor nimconfig.h
* Add the option to change the scan filter mode through NimBLEDevice::setScanFilterMode

* Add the option to change the scan filter cache size through NimBLEDevice::setScanDuplicateCacheSize

* Refactor nimconfig to make it for doxygen use only.
2021-01-31 21:15:31 -07:00
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
h2zero
9527c41486 Refactor advertisedDevice (#181)
* Stores complete advertisement payload and only performs parsing on demand. The advertised data is no longer parsed automatically as it is discovered, instead it will be parsed to find only the data requested by the user application when it makes a call to do so. This saves processing time and approximately 2.4k in flash size, with the new methods listed below included.

Add more advertised device field methods:
* Adds haveAdvInterval/getAdvInterval - checks if the interval is advertised / gets the advertisement interval value.

* Adds haveConnParams/getMinInterval/getMaxInterval - checks if the parameters are advertised / get min value / get max value.

* Adds haveURI/getURI - checks if a URI is advertised / gets the URI data.

* Adds haveTargetAddress/getTargetAddressCount/getTargetAddress(index) - checks if a target address is present / gets a count of the addresses targeted / gets the address of the target at index.
2021-01-30 18:06:29 -07:00
wakwak_koba
51c49ba9fc [NimBLEHIDDevice] Modern Apple devices require READ_ENC and WRITE_ENC (#182)
- Added `READ_ENC` to the attribute of characteristics in 1812/2a4d
- Added `READ_ENC` and `WRITE_ENC` to the default values ​​of properties of `createDescriptor()`
2021-01-30 09:04:51 -07:00
h2zero
4e24a06645 Release 1.1.0 2021-01-20 20:18:23 -07:00
h2zero
310c5f7c84 Remove log print in disconnect timer callback.
Timer callback runs in ISR context, so log printing is inappropriate.
2021-01-20 12:29:22 -07:00
h2zero
026864e031 Set Client connect/disconnect data before stack calls.
Connect should set m_pTaskData before calling ble_gap_connect in case of an early event.

Disconnect should check if the timer has already started before starting the timer so it does not reset it.
The timer should also be started before calling ble_gap_terminate in case of an early event that would cause the timer to start
after disconnection, resetting the host unnecessarily.
2021-01-20 12:28:07 -07:00
h2zero
cf64169bc0 Update documentation.
* Docuemnt HID device class.

* Add usage tips.
2021-01-17 17:29:28 -07:00
h2zero
559a6e6970 Update documentation. 2021-01-15 21:51:49 -07:00
h2zero
c089eab595 Check connection status when returning in NimBLEClient::Connect.
There is a chance to become disconnected before returning from the onConnect callback so the connection
status should be checked when returning from client connect.
2021-01-14 10:21:25 -07:00
h2zero
c157680575 Limit delay in NimBLEClient::connect to connection timeout.
In the case the controller become unresponsive, or does not comply with the timeout period,
this will ensure the application continues instead of potentially blocking forever.
2021-01-13 22:00:39 -07:00
h2zero
6ee1cc236a Advertising start: add return status, use more verbose logging.
Advertising start did not return a value to indicate success/failure,
this patch adds that functionality. In addition, more verbose logging of errors from
this function are provided with the removal of the related asserts.

* Minor code cleanup
2021-01-13 19:48:38 -07:00
h2zero
6487225563 Call advertising stopped callback when the host re-synced.
If the stack was reset and duration was not indefinite the callback for
advertising stopped should be called when re-synced.
2021-01-13 18:34:49 -07:00
h2zero
5629f4d3e9 Initialize duration member variable in NimBLEAdvertising constructor.
m_duration member variable was not set previously which could trigger advertising to start if the
host was reset prior to the application calling start.
2021-01-13 18:21:23 -07:00
wakwak_koba
b064cc65d4 Find characteristic end handle using the next characterisic handle.
On some devices, searching for descriptors using the service end handle would return an invalid error.
This patch instead uses the handle of the next characteristic as the end handle (if available).
2021-01-13 18:05:19 -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
57ba0e583d Fix commit 8fe2766 in scan start.
Scan start would return false when the return code was BLE_HS_EALREADY.
2021-01-12 21:25:30 -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
28573f5abe Fix crash in NimBLEDevice::deleteClient when notification arrives.
While deleting the client attribute database, if a notification occurs there is a possibility of
concurrency causing an exception. This fixes that by setting a flag before calling disconnect in
the deleteClient function to prevent processing further notifications.
2021-01-12 14:01:44 -07:00
h2zero
b807321d1b NimBLEDevice::onSync should call taskYIELD() before returning.
This change is needed to allow any tasks that were stopped during a host reset to finish
before resuming from the re-sync. This would occasionally result in a LoadStoreError exception
if not done.
2021-01-12 13:59:49 -07:00
h2zero
4f4883d6ba Prevent notifications from triggering exception while deleting services.
If we client just connected and a notification comes before deleting services it could cause an exception
when accessing a vector that is being deleted. This will check the connection established flag before
processing of notifications.
2021-01-12 13:58:12 -07:00
h2zero
765d5b1be7 Prioritize processing host reset events in disconnect event handler. 2021-01-12 13:56:29 -07:00
h2zero
09ff0c3472 Remove client delay calls and check if task is valid before notifying. 2021-01-12 13:54:53 -07:00
h2zero
740f280664 Don't call application callbacks invoked when connection not established.
If a connection event was sent but failed to establish then the disconnect
callback would be triggered when the application was not yet informed of the connection.

* Cleanup logs and add comments.
2021-01-12 13:52:28 -07:00
h2zero
28717c300a Fix client connect return code handling, add disconnect timer.
* Handle the return codes from ble_gap_connect to take proper actions for different codes.

* Improve client event handling to accomodate delayed PDU responses.

* Use connection ID as a replacement for the isConnected flag. Also check if a task is waiting for
  results instead of the waitingToConnect flag.

* Adds a disconnect timer so that calling disconnect will start a timer for the connection
  supervision timeout time + a small delay. When this expires it will reset the host if a disconnect event
  does not occur in this time. This is added as a workaround for the occasional situation
  when the controller does not send an event after the disconnect command.
2021-01-12 13:50:08 -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
39a3a63f80 Fix attributes not found with 16/32bit UUIDs.
* Some peripherals will advertise 16/32bit UUIDs but when queried for their handles
they do not convert the UUID to 128 bit locally and will return attribute not found.

This patch will query the peripheral a second time with a 128bit converted UUID.
2020-12-28 15:40:01 -07:00
h2zero
27fc792952 Fix UUID comparison for 16bit + base UUID's
* Add more information to UUID debug messages.
2020-12-28 12:05:54 -07:00
h2zero
ebd7598c49 Re-introduce NimBLEAdvertising::setMin/MaxPreferred.
This implements the functionality of the original library min/max preferred connection parameters settings.
2020-12-27 15:25:38 -07:00
Deepak Singhal
36317e18db Allow subscribing to characteristics if CCCD does not exist on peer device.
- This changes NimBLERemoteCharacteristic::subscribe and NimBLERemoteCharacteristic::registerForNotify functionality
such that the notification callback will always be set.

Additionally these methods will always return true unless the descriptor write fails.

This allows for notifications to trigger the callback when a peer device sends them and does not have a CCCD.
Also it should not be flagged as a failure if the CCCD does not exist.
It should only be flagged when an acutal write operation fails.
2020-12-24 19:59:45 -07:00
h2zero
22d5564d04 Fix compilation errors when using latest Arduino master and IDF 3.3+ 2020-12-24 15:05:32 -07:00
h2zero
d29ad95dfe Rename command line config macros for role disable. 2020-12-20 14:11:19 -07:00
h2zero
de59693f0f Add response parameter to NimBLEClient::setValue 2020-12-20 09:57:26 -07:00
h2zero
77f477f428 Add conditional checks to nimconfig to support command line defines.
* Support platformio config settings on command line.

* Update changelog.
2020-12-19 23:05:54 -07:00
Anthony Doud
7ed962d963 Fix crashing caused by calling time() in a critical section (#159)
* Fix for random notify crash in ISR context

Tested for stability over 30 minutes with a daisy chain of 3 esp32

Co-authored-by: h2zero <powellperalta@gmail.com>
2020-12-19 21:58:37 -07:00
h2zero
a85ac6ad5a Add connection desc param to disconnect callback. 2020-12-04 19:03:52 -07:00
h2zero
3e9a63a514 Correct flags for advertisement type. 2020-11-06 15:44:35 -07:00
wakwak_koba
8d550a6905 Fixed incomplete payload size calculation
* Fixed incomplete payload size calculation

* Disable tx_pwr_lvl when RSP is not possible
2020-10-24 07:57:17 -06:00
wakwak_koba
8e7fcafa9e Add NimBLEHIDDevice class 2020-10-13 19:55:51 -06:00
h2zero
22103af037 Allow scan start from scan complete callback.
* Correct comment in scan start
2020-10-13 19:49:45 -06:00
Guo-Rong Koh
a331cb05e9 NimBLEClient/ Add getCharacteristic() by handle.
* Add getCharacteristic() by handle.

Add a convenience method for getting a characteristic by the 16-bit
handle.
2020-09-23 19:44:11 -06:00
h2zero
91b5916cf4
Add duration and callback parameter to NimBLEAdvertising::start
* Adds functionality to advertise for a set duration, similar to NimBLEScan::start.
The first parameter being the duration (in seconds).
The second parameter is a pointer to a callback function that is invoked when advertising stops.

* NimBLEAdvertising::isAdvertising method added, returns true if advertising is currently active.
2020-09-13 20:36:59 -06:00
h2zero
1a52245012 Update documentation.
* typo fix
2020-09-13 20:02:15 -06:00
h2zero
10acb004dc NimBLEAddress: New constructor added to create blank addresses
* Docuement NimBLEAddress::getNative in migration docs.
2020-09-02 14:52:34 -06:00
Cornelius Munz
9cdf60d360 Change notify_callback typedef to enable the usage of member function as callback
With this change the callback function could be also a member function
2020-09-02 12:15:02 -06:00
h2zero
26b3ba3e8f Fix delayed advertising when first called. 2020-09-02 12:05:05 -06:00
h2zero
d3aa435448 NimBLEAdvertising: Remove setMin/maxPreferred methods.
* These methods were noop's and are now removed due to lack of usefulness and advertisment space consumed if used.
Applications can still manually set these values if desired using NimBLEAdvertisementData::addData.
2020-08-21 20:22:13 -06:00
h2zero
708afebbbf Fix compilation in IDF v4 2020-08-21 11:46:45 -06:00
Guo-Rong
88562bb310 Delete peer keys on key missing and retry.
On BLE_ERR_PINKEY_MISSING, delete the peer keys from the store and
retry the connection.
2020-08-20 09:57:20 -06:00
Roland Szabo
5823703670 incorrect buffer index used when processing longer writes 2020-08-20 09:24:04 +02:00
h2zero
e9bb7eff65 Add doxygen comments in nimconfig.h 2020-08-18 15:02:57 -06:00
h2zero
a17f3199bd Fix client passkey callback value not sent to server. 2020-08-15 07:49:32 -06:00
h2zero
492bcf6f78 Add undefined getServiceUUIDCount() 2020-08-15 07:40:01 -06:00
h2zero
a460eca1ef Update documentation
Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
2020-08-03 22:13:57 -06:00
h2zero
97832d4d95 Initialize peerAddress in client constructor.
Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
2020-08-03 22:13:57 -06:00
h2zero
73cec7a92a Remove type parameter from NimBLEClient::connect()
* The type is available in the NimBLEAddress parameter, no longer needed separately.

Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
2020-08-03 22:13:57 -06:00
h2zero
b901eeb1e5 Connect address type default to public.
* Cleanup logs.

Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
2020-08-03 22:13:57 -06:00
h2zero
8fbab09f53 Rename refreshServices to deleteAttributes in connect().
Minor semantic change for clarity.

Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
2020-08-03 22:13:57 -06:00
h2zero
33d0a732a6 Set peer address of client when creating the instance.
* Adds new client connect method that will connect to the address already set.

Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
2020-08-03 22:13:57 -06:00
h2zero
f3e0d66853 Remove advertisment type from advertised device string. 2020-08-03 20:25:48 -06:00
h2zero
28e9e3d79d Remove type from address string. 2020-08-03 07:33:11 -06:00
h2zero
353e5a6cb1 Fix compile error. 2020-08-01 20:17:12 -06:00
h2zero
1a5beaa7c0
Store address type in NimBLEAddress. (#25) 2020-07-30 14:57:47 -06: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
b2df8384b3
Add support for getting multiple services data from advertisments. (#20)
* Add support for getting multiple services data from advertisments.

* Adds new methods for getting advertised service data and UUIDS.
- getServiceData(index), gets the service data by index value.
- getServiceData(NimBLEUUID), gets the service data by UUID.
- getServiceDataCount(), gets the number of services with data advertised.

* Templates added for getServiceData(index) and getServiceData(NimBLEUUID)
  to be able to specify the data type returned by these methods
  Example:
      getServiceData<uint32_t>(NimBLEUUID("ABCD");

* Also added:
- getServiceUUID(index), gets the advertised service UUID by index value.
- getServiceUUIDCount(), gets the number of advertised services.
2020-07-28 20:09:54 -06:00
h2zero
f1a13d5949 Advertising: Add overloaded method for addData.
* Implements addData(char * data, size_t length) as an alternative to passing a std::string.
2020-07-27 21:38:22 -06:00
h2zero
4723b1cc53
Server: Add onSubscribe() callback for characteristics. (#21)
Server: Add onSubscribe() callback for characteristics.

Adds a new method to NimBLECharacteristicCallbacks that gets called when a client
changes it's subscription status.

* Remove NimBLE2902 class.

As the NimBLE2902 class usefulness was only related to callback functions that were replaced
by the NimBLECharacteristicCallbacks:onSubscribe() method this removes the NimBLE2902 class and
moves all subscription handling to NimBLECharacteristic.

* Update documents and examples to reflect this change.

* Add getSubscribedCount() to get the number of subscribed clients.
2020-07-27 21:11:38 -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
lknop
11b6f816ca Reverse discovered beacon UUID
Author:    lknop <lknop@users.noreply.github.com>
2020-07-19 18:25:10 -06:00
h2zero
2b4c1cd4f1 Add alternative characteristic read/write callbacks
Added alternative characteristic read/write callbacks that carry the connection description information.
Fixes h2zero/NimBLE-Arduino#83

Author: lknop <lknop@users.noreply.github.com>
2020-07-14 15:14:29 -06:00
h2zero
2a5df0c905
Add feature: remove service (#17)
* Get service handles on server start

* remove service + indicate service changed

* Reset gatt services when no connections active and services changed.

* NimBLEServer::createService can now be used any time and will send service changed
indication if server was already active.

* Add ability to remove advertised serviceUUIDS

* Adds addService() method to server to be allow user to re-add a service previously removed

* Add destructior to NimBLEServer, NimBLEService and NimBLECharacteristic to release allocated resources.
2020-07-13 21:24:07 -06:00
h2zero
5857879612 Fix calling scan ended callback when scan was already stopped. 2020-07-12 20:35:10 -06:00
h2zero
bad4051ca8 Cleanup 2020-07-09 10:59:08 -06:00
h2zero
6df7b1331a Refactor NimBLERemoteCharacteristic::subscribe
* Rearrange subscribe parameters to remove requirement of specifying write response to register a callback.
2020-07-08 21:10:11 -06:00
h2zero
2af26fad1f Include NimBLE2904 and NimBLE2902 in NimBLEDescriptor.h
* Removes the need to include these in the application.
2020-07-08 19:47:32 -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
8d2821a429 Use templates for attribute values.
* Add timestamps for NimBLECharacteristic.
2020-07-01 17:32:41 -06:00