Commit graph

234 commits

Author SHA1 Message Date
h2zero
d793b1251e Remove data length extension in IDF (not released yet) 2021-09-13 20:45:36 -06:00
Author: Mr-Mime
5925782a65 [Server][Client] Add function to set data length.
Enables the use of BLE data length extension to improve data transfer rates.
2021-09-12 19:11:38 -06:00
h2zero
ccea428b9e Refactor include directives to use different paths for arduino/idf.
* Sets macros to allow compiling when Central role is enabled and Observer disabled, or Peripheral enabled and Broadcaster disabled.

* Adds a macro definition for CONFIG_NIMBLE_CPP_IDF to enable different include paths/functionality for IDF / Arduino.
2021-09-12 18:43:31 -06:00
h2zero
e238a18a80 Update Doxygen version 2021-08-04 18:58:12 -06:00
h2zero
7b40829e77 Release 1.3.1 2021-08-04 18:55:34 -06:00
h2zero
b24597ac56 Remove definition of btInUse().
This reverts a previous change @2e1d78ff that caused compiling/linking errors due to the redefinition of btInUse() when another linked library uses the Arduino bluetooth code.
2021-08-03 12:43:34 -06:00
h2zero
9961c5605c Update docs version. 2021-08-02 21:25:17 -06:00
h2zero
d4e4074f5a Release 1.3.0 2021-08-02 21:14:12 -06:00
h2zero
e5edc9d59e Add missing return documentation in NimBLEAdvertising. 2021-08-02 19:51:04 -06:00
h2zero
2e1d78ff78 Code cleanup 2021-08-02 13:29:19 -06:00
h2zero
6be6a111d0
[Server] Implement remove Characteristics/Descriptors. (#54)
This allows for adding and removing of characteristics and descriptors after initial setup of the server.
When used it will send a service changed notification to all clients.
The changes will not take effect until all clients have disconnected and advertising restarted.
2021-07-30 20:56:52 -06:00
h2zero
0a2714c169
[Server] Add callback for MTU change. (#55)
onMTUChange callback added that is called when a connection MTU is updated.
2021-07-19 21:47:59 -06:00
h2zero
7d01fa595d
Fix compilation for ESP32C3. (#53) 2021-07-19 21:46:30 -06:00
h2zero
2decc0682a Remove FreeRTOS from CmakeLists. 2021-07-14 10:30:41 -06:00
h2zero
6ff1a49dd5 Update documentation. 2021-07-12 13:33:56 -06:00
h2zero
09adf86036 Remove FreeRTOS files. 2021-07-12 10:25:32 -06:00
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
h2zero
3c33129600 Remove extra Kconfig and add cmakelists for IDF3 2021-03-28 15:06:27 -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
h2zero
1210772332 Update changelog. 2021-02-08 10:18:59 -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
James Fellows
43c9d96373 Update migration guide to include Characteristic constructor now being private 2021-02-03 20:18:44 -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