esp-nimble-cpp/docs/Migration_guide.md

418 lines
19 KiB
Markdown
Raw Normal View History

2020-08-14 21:25:50 +02:00
# Migrating from Bluedroid to NimBLE
2022-05-30 04:08:23 +02:00
This guide describes the required changes to existing projects migrating from the original bluedroid API to NimBLE.
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
**The changes listed here are only the required changes that must be made**, and a short overview of options for migrating existing applications.
2020-08-14 21:25:50 +02:00
For more information on the improvements and additions please refer to the [class documentation](https://h2zero.github.io/esp-nimble-cpp/annotated.html)
2020-08-21 00:07:07 +02:00
* [General Changes](#general-information)
* [Server](#server-api)
* [Services](#services)
* [Characteristics](#characteristics)
* [Characteristic Callbacks](#characteristic-callbacks)
* [Descriptors](#descriptors)
* [Descriptor Callbacks](#descriptor-callbacks)
2020-08-22 17:15:53 +02:00
* [Security](#server-security)
* [Advertising](#advertising-api)
2020-08-21 00:07:07 +02:00
* [Client](#client-api)
* [Remote Services](#remote-services)
* [Remote characteristics](#remote-characteristics)
* [Client Callbacks](#client-callbacks)
2020-08-22 17:15:53 +02:00
* [Security](#client-security)
2024-12-08 00:49:40 +01:00
* [BLE scan](#ble-scan)
2020-08-22 17:15:53 +02:00
* [General Security](#security-api)
* [Configuration](#arduino-configuration)
2022-05-30 04:08:23 +02:00
<br/>
2020-08-14 21:25:50 +02:00
2020-08-22 17:15:53 +02:00
## General Information
2020-08-14 21:25:50 +02:00
### Header Files
2022-05-30 04:08:23 +02:00
All classes are accessible by including `NimBLEDevice.h` in your application, no further headers need to be included.
2020-08-14 21:25:50 +02:00
(Mainly for Arduino) You may choose to include `NimBLELog.h` in your application if you want to use the `NIMBLE_LOGx` macros for debugging. These macros are used the same way as the `ESP_LOGx` macros.
2020-08-14 21:25:50 +02:00
<br/>
### Class Names
2022-05-30 04:08:23 +02:00
Class names remain the same as the original with the addition of a "Nim" prefix.
For example `BLEDevice` is now `NimBLEDevice` and `BLEServer` is now `NimBLEServer` etc.
2020-08-14 21:25:50 +02:00
For convenience definitions have been added to allow applications to use either name for all classes this means **no class names need to be changed in existing code** and makes migrating easier.
2020-08-14 21:25:50 +02:00
<br/>
### BLE Addresses
`BLEAddress` (`NimBLEAddress`) When constructing an address the constructor now takes an *(optional)* `uint8_t type` parameter to specify the address type. Default is (0) Public static address.
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
For example `BLEAddress addr(11:22:33:44:55:66, 1)` will create the address object with an address type of: 1 (Random).
2020-08-14 21:25:50 +02:00
As this parameter is optional no changes to existing code are needed, it is mentioned here for information.
2022-05-30 04:08:23 +02:00
2024-12-07 18:44:50 +01:00
`BLEAddress::getNative` is now named `NimBLEAddress::getBase` and returns a pointer to `const ble_addr_t` instead of a pointer to the address value.
<br/>
2020-08-22 17:15:53 +02:00
## Server API
2020-08-14 21:25:50 +02:00
Creating a `BLEServer` instance is the same as original, no changes required.
2022-05-30 04:08:23 +02:00
For example `BLEDevice::createServer()` will work just as it did before.
2020-08-14 21:25:50 +02:00
`BLEServerCallbacks` (`NimBLEServerCallbacks`) has new methods for handling security operations.
<br/>
`BLEServerCallbacks::onConnect` (`NimBLEServerCallbacks::onConnect`) only has a single callback declaration which takes an additional (required) parameter `NimBLEConnInfo & connInfo`, which has methods to get information about the connected peer.
```
void onConnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo)`
```
<br/>
`BLEServerCallbacks::onDisconnect` (`NimBLEServerCallbacks::onDisconnect`) only has a single callback declaration which takes 2 additional (required) parameters `NimBLEConnInfo & connInfo`, which provides information about the peer and `int reason`, which gives the reason code for disconnection.
```
void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason)`
```
<br/>
2024-12-07 18:44:50 +01:00
`BLEServerCallbacks::onMtuChanged` is now (`NimBLEServerCallbacks::onMtuChange`) and takes the parameter `NimBLEConnInfo & connInfo` instead of `esp_ble_gatts_cb_param_t`, which has methods to get information about the connected peer.
```
onMTUChange(uint16_t MTU, NimBLEConnInfo& connInfo)
```
**Note:** All callback methods have default implementations which allows the application to implement only the methods applicable.
2020-08-14 21:25:50 +02:00
<br/>
2020-08-22 17:15:53 +02:00
### Services
2022-05-30 04:08:23 +02:00
Creating a `BLEService` (`NimBLEService`) instance is the same as original, no changes required.
For example `BLEServer::createService(SERVICE_UUID)` will work just as it did before.
<br/>
2020-08-14 21:25:50 +02:00
2020-08-22 17:15:53 +02:00
### Characteristics
2022-05-30 04:08:23 +02:00
`BLEService::createCharacteristic` (`NimBLEService::createCharacteristic`) is used the same way as originally except the properties parameter has changed.
2020-08-14 21:25:50 +02:00
When creating a characteristic the properties are now set with `NIMBLE_PROPERTY::XXXX` instead of `BLECharacteristic::XXXX`.
#### Originally
> BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
2020-08-14 21:25:50 +02:00
#### Is Now
> NIMBLE_PROPERTY::READ |
NIMBLE_PROPERTY::WRITE
2020-08-14 21:25:50 +02:00
<br/>
#### The full list of properties
> NIMBLE_PROPERTY::READ
NIMBLE_PROPERTY::READ_ENC
NIMBLE_PROPERTY::READ_AUTHEN
NIMBLE_PROPERTY::READ_AUTHOR
NIMBLE_PROPERTY::WRITE
NIMBLE_PROPERTY::WRITE_NR
NIMBLE_PROPERTY::WRITE_ENC
NIMBLE_PROPERTY::WRITE_AUTHEN
NIMBLE_PROPERTY::WRITE_AUTHOR
NIMBLE_PROPERTY::BROADCAST
NIMBLE_PROPERTY::NOTIFY
NIMBLE_PROPERTY::INDICATE
2022-05-30 04:08:23 +02:00
2020-08-14 21:25:50 +02:00
<br/>
**Example:**
```
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
2022-05-30 04:08:23 +02:00
BLECharacteristic::PROPERTY_WRITE
2020-08-14 21:25:50 +02:00
);
```
Needs to be changed to:
```
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
NIMBLE_PROPERTY::READ |
2022-05-30 04:08:23 +02:00
NIMBLE_PROPERTY::WRITE
2020-08-14 21:25:50 +02:00
);
```
<br/>
#### Characteristic callbacks
2024-12-07 18:44:50 +01:00
2022-05-30 04:08:23 +02:00
`BLECharacteristicCallbacks` (`NimBLECharacteristicCallbacks`) has a new method `NimBLECharacteristicCallbacks::onSubscribe` which is called when a client subscribes to notifications/indications.
2020-08-22 17:15:53 +02:00
`BLECharacteristicCallbacks::onRead` (`NimBLECharacteristicCallbacks::onRead`) only has a single callback declaration, which takes an additional (required) parameter of `NimBLEConnInfo& connInfo`, which provides connection information about the peer.
`BLECharacteristicCallbacks::onWrite` (`NimBLECharacteristicCallbacks::onWrite`) only has a single callback declaration, which takes an additional (required) parameter of `NimBLEConnInfo& connInfo`, which provides connection information about the peer.
`BLECharacteristicCallbacks::onStatus` (`NimBLECharacteristicCallbacks::onStatus`) has had the status parameter removed as it was unnecessary since the status code from the BLE stack was also provided. The status code for success is 0 for notifications and BLE_HS_EDONE for indications, any other value is an error.
**Note:** All callback methods have default implementations which allows the application to implement only the methods applicable.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> BLECharacteristic::getData
2020-08-22 17:15:53 +02:00
2022-05-30 04:08:23 +02:00
**Has been removed from the API.**
Originally this returned a `uint8_t*` to the internal data, which is volatile.
To prevent possibly throwing exceptions this has been removed and `NimBLECharacteristic::getValue` should be used
to get a copy of the data first which can then safely be accessed via pointer.
2020-08-22 17:15:53 +02:00
**Example:**
```
std::string value = pCharacteristic->getValue();
uint8_t *pData = (uint8_t*)value.data();
```
Alternatively use the `getValue` template:
```
my_struct_t myStruct = pChr->getValue<my_struct_t>();
```
<br/>
### Descriptors
2020-08-14 21:25:50 +02:00
2020-08-17 21:45:13 +02:00
Descriptors are now created using the `NimBLECharacteristic::createDescriptor` method.
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
BLE2902 or NimBLE2902 class has been removed.
NimBLE automatically creates the 0x2902 descriptor if a characteristic has a notification or indication property assigned to it.
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
It was no longer useful to have a class for the 0x2902 descriptor as a new callback `NimBLECharacteristicCallbacks::onSubscribe` was added
to handle callback functionality and the client subscription status is handled internally.
2024-12-07 18:44:50 +01:00
**Note:** Attempting to create a 0x2902 descriptor will trigger a warning message and flag it internally as removed and will not be functional.
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
All other descriptors are now created just as characteristics are by using the `NimBLECharacteristic::createDescriptor` method (except 0x2904, see below).
2020-08-14 21:25:50 +02:00
Which are defined as:
```
NimBLEDescriptor* createDescriptor(const char* uuid,
2022-05-30 04:08:23 +02:00
uint32_t properties =
2020-08-14 21:25:50 +02:00
NIMBLE_PROPERTY::READ |
NIMBLE_PROPERTY::WRITE,
uint16_t max_len = 100);
2022-05-30 04:08:23 +02:00
2020-08-14 21:25:50 +02:00
NimBLEDescriptor* createDescriptor(NimBLEUUID uuid,
2022-05-30 04:08:23 +02:00
uint32_t properties =
2020-08-14 21:25:50 +02:00
NIMBLE_PROPERTY::READ |
NIMBLE_PROPERTY::WRITE,
uint16_t max_len = 100);
```
2024-12-08 00:49:40 +01:00
#### Example
2020-08-14 21:25:50 +02:00
```
2022-05-30 04:08:23 +02:00
pDescriptor = pCharacteristic->createDescriptor("ABCD",
NIMBLE_PROPERTY::READ |
2020-08-14 21:25:50 +02:00
NIMBLE_PROPERTY::WRITE |
NIMBLE_PROPERTY::WRITE_ENC,
25);
```
Would create a descriptor with the UUID 0xABCD, publicly readable but only writable if paired/bonded (encrypted) and has a max value length of 25 bytes.
2020-08-14 21:25:50 +02:00
<br/>
2024-12-07 18:44:50 +01:00
For the 0x2904, there is a specialized class that is created through `NimBLECharacteristic::create2904` which returns a pointer to a `NimBLE2904` instance which has specific
functions for handling the data expect in the Characteristic Presentation Format Descriptor specification.
2020-08-14 21:25:50 +02:00
<br/>
#### Descriptor callbacks
> `BLEDescriptorCallbacks::onRead` (`NimBLEDescriptorCallbacks::onRead`)
2024-12-07 18:44:50 +01:00
`BLEDescriptorCallbacks::onWrite` (`NimBLEDescriptorCallbacks::onWrite`)
The above descriptor callbacks take an additional (required) parameter `NimBLEConnInfo& connInfo`, which contains the connection information of the peer.
<br/>
2020-08-14 21:25:50 +02:00
### Server Security
Security is set on the characteristic or descriptor properties by applying one of the following:
> NIMBLE_PROPERTY::READ_ENC
NIMBLE_PROPERTY::READ_AUTHEN
NIMBLE_PROPERTY::READ_AUTHOR
NIMBLE_PROPERTY::WRITE_ENC
NIMBLE_PROPERTY::WRITE_AUTHEN
NIMBLE_PROPERTY::WRITE_AUTHOR
2022-05-30 04:08:23 +02:00
<br/>
When a peer wants to read or write a characteristic or descriptor with any of these properties applied it will trigger the pairing process. By default the "just-works" pairing will be performed automatically.
2020-08-14 21:25:50 +02:00
This can be changed to use passkey authentication or numeric comparison. See [Security API](#security-api) for details.
2020-08-14 21:25:50 +02:00
<br/>
2020-08-22 17:15:53 +02:00
## Advertising API
2022-05-30 04:08:23 +02:00
Advertising works the same as the original API except:
2020-09-14 04:02:15 +02:00
2022-05-30 04:08:23 +02:00
Calling `NimBLEAdvertising::setAdvertisementData` will entirely replace any data set with `NimBLEAdvertising::addServiceUUID`, or
`NimBLEAdvertising::setAppearance` or similar methods. You should set all the data you wish to advertise within the `NimBLEAdvertisementData` instead.
2020-08-22 17:15:53 +02:00
<br/>
2020-09-14 05:37:13 +02:00
> BLEAdvertising::start (NimBLEAdvertising::start)
2024-12-07 18:44:50 +01:00
Now takes 2 optional parameters, the first is the duration to advertise for (in milliseconds), the second `NimBLEAddress` to direct advertising to a specific device.
2020-09-14 05:37:13 +02:00
<br/>
2020-08-22 17:15:53 +02:00
## Client API
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
Client instances are created just as before with `BLEDevice::createClient` (`NimBLEDevice::createClient`).
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
Multiple client instances can be created, up to the maximum number of connections set in the config file (default: 3). To delete a client instance you must use `NimBLEDevice::deleteClient`.
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
`BLEClient::connect`(`NimBLEClient::connect`) Has had it's parameters altered.
2020-08-14 21:25:50 +02:00
Defined as:
2024-12-07 18:44:50 +01:00
> NimBLEClient::connect(bool deleteServices = true, , bool asyncConnect = false, bool exchangeMTU = true);
> NimBLEClient::connect(const NimBLEAddress& address, bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true);
> NimBLEClient::connect(const NimBLEAdvertisedDevice* device, bool deleteServices = true, bool asyncConnect = false, bool exchangeMTU = true);
2022-05-30 04:08:23 +02:00
The type parameter has been removed and a new bool parameter has been added to indicate if the client should delete the attribute database previously retrieved (if applicable) for the peripheral, default value is true.
2024-12-07 18:44:50 +01:00
If set to false the client will use the attribute database it retrieved from the peripheral when previously connected. This allows for faster connections and power saving if the devices dropped connection and are reconnecting.
2020-08-14 21:25:50 +02:00
2024-12-07 18:44:50 +01:00
The parameter `bool asyncConnect` if true, will cause the client to send the connect command to the stack and return immediately without blocking. The return value will represent wether the command was sent successfully or not and the `NimBLEClientCallbacks::onConnect` or `NimBLEClientCallbacks::onConnectFail` will be called when the operation is complete.
The parameter `bool exchangeMTU` if true, will cause the client to perform the exchange MTU process upon connecting. If false the MTU exchange will need to be performed by the application by calling `NimBLEClient::exchangeMTU`. If the connection is only sending small payloads it may be advantageous to not exchange the MTU to gain performance in the connection process.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `BLEClient::getServices` (`NimBLEClient::getServices`)
2020-08-14 21:25:50 +02:00
This method now takes an optional (bool) parameter to indicate if the services should be retrieved from the server (true) or the currently known database returned (false : default).
Also now returns a pointer to `std::vector` instead of `std::map`.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
**Removed:** the automatic discovery of all peripheral attributes as they consumed time and resources for data the user may not be interested in.
**Added:** `NimBLEClient::discoverAttributes` for the user to discover all the peripheral attributes to replace the the removed automatic functionality.
2020-08-14 21:25:50 +02:00
<br/>
2020-08-22 17:15:53 +02:00
### Remote Services
2022-05-30 04:08:23 +02:00
`BLERemoteService` (`NimBLERemoteService`) Methods remain mostly unchanged with the exceptions of:
2020-08-21 00:07:07 +02:00
2020-08-14 21:25:50 +02:00
> BLERemoteService::getCharacteristicsByHandle
2020-08-21 00:07:07 +02:00
This method has been removed.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `BLERemoteService::getCharacteristics` (`NimBLERemoteService::getCharacteristics`)
2020-08-21 00:07:07 +02:00
2024-12-07 18:44:50 +01:00
This method now takes an optional (bool) parameter to indicate if the characteristics should be retrieved from the server (true) or the currently known database returned, default = false.
Also now returns a pointer to `std::vector` instead of `std::map`.
2020-08-14 21:25:50 +02:00
<br/>
2020-08-22 17:15:53 +02:00
### Remote Characteristics
`BLERemoteCharacteristic` (`NimBLERemoteCharacteristic`)
2022-05-30 04:08:23 +02:00
There have been a few changes to the methods in this class:
2020-08-14 21:25:50 +02:00
> `BLERemoteCharacteristic::writeValue` (`NimBLERemoteCharacteristic::writeValue`)
2020-08-14 21:25:50 +02:00
Now returns true or false to indicate success or failure so you can choose to disconnect or try again.
2020-08-14 21:25:50 +02:00
<br/>
> `BLERemoteCharacteristic::registerForNotify`
2020-08-14 21:25:50 +02:00
Has been removed.
> `NimBLERemoteCharacteristic::subscribe`
> `NimBLERemoteCharacteristic::unsubscribe`
2020-08-14 21:25:50 +02:00
Are the new methods added to replace it.
2020-08-14 21:25:50 +02:00
<br/>
2024-12-07 18:44:50 +01:00
> `BLERemoteCharacteristic::readUInt8` (`NimBLERemoteCharacteristic::readUInt8`)
> `BLERemoteCharacteristic::readUInt16` (`NimBLERemoteCharacteristic::readUInt16`)
> `BLERemoteCharacteristic::readUInt32` (`NimBLERemoteCharacteristic::readUInt32`)
2022-05-30 04:08:23 +02:00
> `BLERemoteCharacteristic::readFloat` (`NimBLERemoteCharacteristic::readFloat`)
2020-08-14 21:25:50 +02:00
2024-12-07 18:44:50 +01:00
Are **removed** a template: `NimBLERemoteCharacteristic::readValue<type\>(time_t\*, bool)` has been added to replace them.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `BLERemoteCharacteristic::readRawData`
2020-08-14 21:25:50 +02:00
2022-05-30 04:08:23 +02:00
**Has been removed from the API**
Originally it stored an unnecessary copy of the data and was returning a `uint8_t` pointer to volatile internal data.
2022-05-30 04:08:23 +02:00
The user application should use `NimBLERemoteCharacteristic::readValue` or `NimBLERemoteCharacteristic::getValue`.
2024-12-07 18:44:50 +01:00
To obtain a copy of the data as a `NimBLEAttValue` instance and use the `NimBLEAttValue::data` member function to obtain the pointer.
2020-08-14 21:25:50 +02:00
```
2024-12-07 18:44:50 +01:00
NimBLEAttValue value = pChr->readValue();
const uint8_t *data = value.data();
2020-08-14 21:25:50 +02:00
```
2020-08-21 00:07:07 +02:00
Alternatively use the `readValue` template:
```
my_struct_t myStruct = pChr->readValue<my_struct_t>();
```
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `BLERemoteCharacteristic::getDescriptors` (`NimBLERemoteCharacteristic::getDescriptors`)
2024-12-07 18:44:50 +01:00
This method now takes an optional (bool) parameter to indicate if the descriptors should be retrieved from the server (true) or the currently known database returned, default = false.
Also now returns a pointer to `std::vector` instead of `std::map`.
2020-08-14 21:25:50 +02:00
<br/>
### Client callbacks
> `BLEClientCallbacks::onDisconnect` (`NimBLEClientCallbacks::onDisconnect`)
This now takes a second parameter `int reason` which provides the reason code for disconnection.
<br/>
2020-08-22 17:15:53 +02:00
### Client Security
The client will automatically initiate security when the peripheral responds that it's required.
The default configuration will use "just-works" pairing with no bonding, if you wish to enable bonding see below.
2020-08-14 21:25:50 +02:00
<br/>
## BLE Scan
2024-12-07 18:44:50 +01:00
The scan API is mostly unchanged from the original except for `NimBLEScan::start`, which has the following changes:
* The duration parameter is now in milliseconds instead of seconds.
* The callback parameter has been removed.
* A new parameter `bool restart` has been added, when set to true to restart the scan if already in progress and clear the duplicate cache.
The blocking overload of `NimBLEScan::start` has been replaced by an overload of `NimBLEScan::getResults` with the same parameters.
<br/>
2020-08-22 17:15:53 +02:00
## Security API
Security operations have been moved to `BLEDevice` (`NimBLEDevice`).
The security callback methods are now incorporated in the `NimBLEServerCallbacks` / `NimBLEClientCallbacks` classes.
2020-08-14 21:25:50 +02:00
The callback methods are:
> `bool onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin)`
2020-08-14 21:25:50 +02:00
Receives the pin when using numeric comparison authentication.
2024-12-07 18:44:50 +01:00
Call `NimBLEDevice::injectConfirmPasskey(connInfo, true);` to accept or `NimBLEDevice::injectConfirmPasskey(connInfo, false);` to reject.
2020-08-14 21:25:50 +02:00
<br/>
[BREAKING] Refactor attributes Refactor attributes to reduce code duplication and improve maintainability. * Add attribute base classes to provide common code. * Add const where possible to functions and parameters. * `NimBLECharacteristic::notify` no longer takes a `bool is_notification` parameter, instead `indicate()` should be called to send indications. * `NimBLECharacteristic::indicate` now takes the same parameters as `notify`. * `NimBLECharacteristicCallbacks` and `NimBLEDescriptorCallbacks` methods now take `const NimBLEConnInfo&` instead of non-const. * `NimBLECharacteristic::onNotify` callback removed as unnecessary, the library does not call notify without app input. * `NimBLERemoteCharacteristic::getRemoteService` now returns a `const NimBLERemoteService*` instead of non-const. * Add NimBLEUUID constructor that takes a reference to `ble_uuid_any_t`. * `NimBLERemoteService::getCharacteristics` now returns a `const std::vector<NimBLERemoteCharacteristic*>&` instead of non-const `std::vector<NimBLERemoteCharacteristic*>*` * `NimBLERemoteService::getValue` now returns `NimBLEAttValue` instead of `std::string` * `NimBLEService::getCharacteristics` now returns a `const std::vector<NimBLECharacteristic*>&` instead of a copy of std::vector<NimBLECharacteristic *>. * Remove const requirement for NimBLEConnInfo parameter in callbacks. Const is unnecessary as the data can't be changed by application code. * Change NimBLERemoteCharacteristic::getRemoteService to return const pointer.
2024-07-26 22:47:36 +02:00
> `void onPassKeyEntry(NimBLEConnInfo& connInfo)`
2020-08-14 21:25:50 +02:00
Client callback; client should respond with the passkey (pin) by calling `NimBLEDevice::injectPassKey(connInfo, 123456);`
2020-08-14 21:25:50 +02:00
<br/>
> `uint32_t onPassKeyDisplay()`
Server callback; should return the passkey (pin) expected from the client.
<br/>
[BREAKING] Refactor attributes Refactor attributes to reduce code duplication and improve maintainability. * Add attribute base classes to provide common code. * Add const where possible to functions and parameters. * `NimBLECharacteristic::notify` no longer takes a `bool is_notification` parameter, instead `indicate()` should be called to send indications. * `NimBLECharacteristic::indicate` now takes the same parameters as `notify`. * `NimBLECharacteristicCallbacks` and `NimBLEDescriptorCallbacks` methods now take `const NimBLEConnInfo&` instead of non-const. * `NimBLECharacteristic::onNotify` callback removed as unnecessary, the library does not call notify without app input. * `NimBLERemoteCharacteristic::getRemoteService` now returns a `const NimBLERemoteService*` instead of non-const. * Add NimBLEUUID constructor that takes a reference to `ble_uuid_any_t`. * `NimBLERemoteService::getCharacteristics` now returns a `const std::vector<NimBLERemoteCharacteristic*>&` instead of non-const `std::vector<NimBLERemoteCharacteristic*>*` * `NimBLERemoteService::getValue` now returns `NimBLEAttValue` instead of `std::string` * `NimBLEService::getCharacteristics` now returns a `const std::vector<NimBLECharacteristic*>&` instead of a copy of std::vector<NimBLECharacteristic *>. * Remove const requirement for NimBLEConnInfo parameter in callbacks. Const is unnecessary as the data can't be changed by application code. * Change NimBLERemoteCharacteristic::getRemoteService to return const pointer.
2024-07-26 22:47:36 +02:00
> `void onAuthenticationComplete(NimBLEConnInfo& connInfo)`
2020-08-14 21:25:50 +02:00
Authentication complete, success or failed information is available from the `NimBLEConnInfo` methods.
2020-08-14 21:25:50 +02:00
<br/>
Security settings and IO capabilities are now set by the following methods of NimBLEDevice.
> `NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc)`
2022-05-30 04:08:23 +02:00
> `NimBLEDevice::setSecurityAuth(uint8_t auth_req)`
2020-08-14 21:25:50 +02:00
Sets the authorization mode for this device.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `NimBLEDevice::setSecurityIOCap(uint8_t iocap)`
2020-08-14 21:25:50 +02:00
Sets the Input/Output capabilities of this device.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `NimBLEDevice::setSecurityInitKey(uint8_t init_key)`
2020-08-14 21:25:50 +02:00
If we are the initiator of the security procedure this sets the keys we will distribute.
2020-08-14 21:25:50 +02:00
<br/>
2022-05-30 04:08:23 +02:00
> `NimBLEDevice::setSecurityRespKey(uint8_t resp_key)`
2020-08-14 21:25:50 +02:00
Sets the keys we are willing to accept from the peer during pairing.
2020-08-14 21:25:50 +02:00
<br/>
2020-08-22 17:15:53 +02:00
## Arduino Configuration
2022-05-30 04:08:23 +02:00
Unlike the original library pre-packaged in the esp32-arduino, this library has all the configuration options that are normally set in menuconfig available in the *src/nimconfig.h* file.
2020-08-22 17:15:53 +02:00
2022-05-30 04:08:23 +02:00
This allows Arduino users to fully customize the build, such as increasing max connections or loading the BLE stack into external PSRAM.
2020-08-22 17:15:53 +02:00
For details on the options, they are fully commented in *nimconfig.h*
2020-08-22 17:15:53 +02:00
<br/>