Finally! A new release with something more than a bugfix or some minor additions!
I'm excited to present this release properly after the unfortunate Arduino Library Manager debacle 🎉.
This was a complete overhaul of the codebase, every file as been touched up and some completely re-designed, removed, added, or changed significantly. This required A LOT of changes, many will break your current application code, but don't worry, it will be much better!
This release has so much in it!
Highlights
- Reduced the code size by over 40KB.
- Significant reduction in memory use.
- Huge performance boost.
- Asynchronous client connect, MTU exchange, and secure connection options to speed up the connecting process.
- Asynchronous passkey entry/confirmation so the client/server can have time to properly display/enter the passkey before action is performed.
- Scan restart option to clear the duplicate cache so the same devices will be found again.
- New scan callbacks class with extra functions that will get called on first discovery, before and scan response data is received.
- Ability to update advertised data while advertising.
- Improved support for dynamically changing services/characteristics/descriptors.
- Simplified code for easier maintenance and understanding for contributors.
Full Changelog
Breaking changes
- NimBLESecurity class removed.
- All connection oriented callbacks now receive a reference to
NimBLEConnInfo
, theble_gap_conn_desc
has also been replace withNimBLEConnInfo
in the functions that received it. - All functions that take a time input parameter now expect the value to be in milliseconds instead of seconds.
NimBLEDevice
Ignore list functions removed.NimBLEDevice::startSecurity
now returns abool
, true on success, instead of an int to be consistent with the rest of the library.NimBLEDevice::getInitialized
renamed toNimBLEDevice::isInitialized
.NimBLEDevice::setPower
no longer takes theesp_power_level_t
andesp_ble_power_type_t
, instead only an integer value in dbm units is accepted.NimBLEDevice::setOwnAddrType
no longer takes abool nrpa
parameter.NimBLEDevice::getClientListSize
replaced withNimBLEDevice::getCreatedClientCount
.NimBLEDevice::getClientList
was removed.NimBLEServer::disconnect
now returnsbool
, true = success, instead ofint
to be consistent with the rest of the library.NimBLEServer::getPeerIDInfo
renamed toNimBLEServer::getPeerInfoByHandle
to better describe it's use.NimBLEServerCallbacks::onMTUChanged
renamed toNimBLEServerCallbacks::onMTUChange
to be consistent with the client callback.NimBLEServerCallbacks::onPassKeyRequest
has been replaced withNimBLEServer::onPassKeyDisplay
which should display the pairing pin that the client is expected to send.NimBLEServerCallbacks::onAuthenticationComplete
now takes aNimBLEConnInfo&
parameter.NimBLEClient::getServices
now returns a const reference to std::vector<NimBLERemoteService*> instead of a pointer to the internal vector.NimBLEClient::getConnId
has been renamed togetConnHandle
to be consistent with bluetooth terminology.NimBLEClient::disconnect
now returns abool
, true on success, instead of an int to be consistent with the rest of the library.NimBLEClientCallbacks::onDisconnect
now takes an additionalint reason
parameter to let the application know why the disconnect occurred.NimBLEClientCallbacks::onPassKeyRequest
has been changed toNimBLEClientCallbacks::onPassKeyEntry
which takes aNimBLEConnInfo&
parameter and does not return a value. Instead or returning a value this callback should prompt a user to enter a pin number which is sent later viaNimBLEDevice::injectPassKey
.NimBLEClientCallbacks::onConfirmPIN
renamed toNimBLEClientCallbacks::onConfirmPasskey
and no longer returns a value and now takes aNimBLEConnInfo&
parameter. This should be used to prompt a user to confirm the pin on the display (YES/NO) after which the response should be sent withNimBLEDevice::injectConfirmPasskey
.NimBLEAdvertising::setMinPreferred
andNimBLEAdvertising::setMaxPreferred
have been removed, useNimBLEAdvertising::setPreferredParams
instead.- Advertising the name and TX power of the device will no longer happen by default and should be set manually by the application.
NimBLEAdvertising::setAdvertisementType
has been renamed toNimBLEAdvertising::setConnectableMode
to better reflect it's function.NimBLEAdvertising::setScanResponse
has been renamed toNimBLEAdvertising::enableScanResponse
to better reflect it's function.NimBLEAdvertising
; Scan response is no longer enabled by default.NimBLEAdvertising::start
No longer takes a callback pointer parameter, instead the new methodNimBLEAdvertising::setAdvertisingCompleteCallback
should be used.NimBLEAdvertisementData::addData
now takes either astd::vector<uint8_t>
oruint8_t* + length
instead ofstd::string
orchar + length
.NimBLEAdvertisementData::getPayload
now returnsstd::vector<uint8_t>
instead ofstd::string
.- The callback parameter for
NimBLEScan::start
has been removed and the blocking overload ofNimBLEScan::start
has been replaced by an overload ofNimBLEScan::getResults
with the same parameters. NimBLEAdvertisedDeviceCallbacks
Has been replaced byNimBLEScanCallbacks
which contains the following methods:onResult
,onScanEnd
, and `onDiscovered-
NimBLEScanCallbacks::onResult
, functions the same as the oldNimBLEAdvertisedDeviceCallbacks::onResult
but now takes aaconst NimBLEAdvertisedDevice*
instead of non-const.
-
NimBLEScanCallbacks::onScanEnd
, replaces the scanEnded callback passed toNimBLEScan::start
and now takes aconst NimBLEScanResults&
andint reason
parameter.
-
NimBLEScanCallbacks::onDiscovered
, This is called immediately when a device is first scanned, before any scan response data is available and takes aconst NimBLEAdvertisedDevice*
parameter.
NimBLEScan::stop
will no longer call theonScanEnd
callback as the caller should know its been stopped when this is called.NimBLEScan::clearDuplicateCache
has been removed as it was problematic and only for the esp32. Stop and start the scanner for the same effect.NimBLEScanResults::getDevice
methods now returnconst NimBLEAdvertisedDevice*
.NimBLEScanResults
iterators are nowconst_iterator
.NimBLEService::getCharacteristics
now returns aconst std::vector<NimBLECharacteristic*>&
instead of std::vector<NimBLECharacteristic *>.NimBLECharacteristic::notify
no longer takes abool is_notification
parameter, insteadindicate()
should be called to send indications.NimBLECharacteristicCallbacks::onNotify
removed as unnecessary, the library does not call notify without app input.NimBLECharacteristicCallbacks::onStatus
No longer takes astatus
parameter, refer to the return code for success/failure.NimBLERemoteService::getCharacteristics
now returns aconst std::vector<NimBLERemoteCharacteristic*>&
instead of non-conststd::vector<NimBLERemoteCharacteristic*>*
.NimBLERemoteService::getValue
now returnsNimBLEAttValue
instead ofstd::string
.NimBLERemoteCharacteristic::getRemoteService
now returns aconst NimBLERemoteService*
instead of non-const.NimBLERemoteCharacteristic::readUInt32
Has been removed.NimBLERemoteCharacteristic::readUInt16
Has been removed.NimBLERemoteCharacteristic::readUInt8
Has been removed.NimBLERemoteCharacteristic::readFloat
Has been removed.NimBLERemoteCharacteristic::registerForNotify
Has been removed.NimBLEAdvertisedDevice::hasRSSI
removed as redundant, RSSI is always available.NimBLEAdvertisedDevice::getPayload
now returnsconst std::vector<uint8_t>
instead of a pointer to internal memory.NimBLEAdvertisedDevice
Timestamp removed, if needed then the app should track the time from the callback.NimBLEAddress
constructor; default value for thetype
parameter removed, caller should know the address type and specify it.NimBLEAddress::getNative
replaced withNimBLEAddress::getBase
and now returns a pointer toconst ble_addr_t
instead of a pointer to the address value.NimBLEAddress::equals
method andNimBLEAddress::== operator
will now also test if the address types are the same.NimBLEUUID::getNative
method replaced withNimBLEUUID::getBase
which returns a read-only pointer to the underlyingble_uuid_t
struct.NimBLEUUID
;msbFirst
parameter has been removed from constructor, caller should reverse the data first or call the newreverseByteOrder
method after.NimBLEUtils::dumpGapEvent
function removed.NimBLEUtils::buildHexData
replaced withNimBLEUtils::dataToHexString
, which returns astd::string
containing the hex string.- Removed Eddystone URL as it has been shutdown by google since 2021.
NimBLEEddystoneTLM::setTemp
now takes anint16_t
parameter instead of float to be friendly to devices without floating point support.NimBLEEddystoneTLM::getTemp
now returnsint16_t
to work with devices that don't have floating point support.NimBLEEddystoneTLM::setData
now takes a reference to *NimBLEEddystoneTLM::BeaconData
instead ofstd::string
.NimBLEEddystoneTLM::getData
now returns a reference to *NimBLEEddystoneTLM::BeaconData
instead ofstd::string
.NimBLEBeacon::setData
now takesconst NimBLEBeacon::BeaconData&
instead ofstd::string
.NimBLEBeacon::getData
now returnsconst NimBLEBeacon::BeaconData&
instead ofstd::string
.NimBLEHIDDevice::reportMap
renamed toNimBLEHIDDevice::getReportMap
.NimBLEHIDDevice::hidControl
renamed toNimBLEHIDDevice::getHidControl
.NimBLEHIDDevice::inputReport
renamed toNimBLEHIDDevice::getInputReport
.NimBLEHIDDevice::outputReport
renamed toNimBLEHIDDevice::getOutputReport
.NimBLEHIDDevice::featureReport
renamed toNimBLEHIDDevice::getFeatureReport
.NimBLEHIDDevice::protocolMode
renamed toNimBLEHIDDevice::getProtocolMode
.NimBLEHIDDevice::bootOutput
renamed toNimBLEHIDDevice::getBootOutput
.NimBLEHIDDevice::pnp
renamed toNimBLEHIDDevice::setPnp
.NimBLEHIDDevice::hidInfo
renamed toNimBLEHIDDevice::setHidInfo
.NimBLEHIDDevice::deviceInfo
renamed toNimBLEHIDDevice::getDeviceInfoService
.NimBLEHIDDevice::hidService
renamed toNimBLEHIDDevice::getHidService
.NimBLEHIDDevice::batteryService
renamed toNimBLEHIDDevice::getBatteryService
.
Fixed
NimBLEDevice::getPower
andNimBLEDevice::getPowerLevel
bug worked around for the esp32s3 and esp32c3.NimBLEDevice::setPower
andNimBLEDevice::getPower
now support the full power range for all esp devices.NimBLEDevice::setOwnAddrType
will now correctly apply the provided address type for all devices.NimBLEDevice::getPower
(esp32) return value is now calculated to support devices with different min/max ranges.- Crash if
NimBLEDevice::deinit
is called when the stack has not been initialized. NimBLEServer
service changed notifications will now wait until the changes have taken effect and the server re-started before indicating the change to peers, reducing difficultly for some clients to update their data.NimBLEService::getHandle
will now fetch the handle from the stack if not valid to avoid returning an invalid value.std::vector
input to set/write values template.- Pairing failing when the process was started by the peer first.
Changed
NimBLEClient::secureConnection
now takes an additional parameterbool async
, if true, will send the secure command and return immediately with a true value for successfully sending the command, else false. This allows for asynchronously securing a connection.- Deleting the client instance from the
onDisconnect
callback is now supported. NimBLEClient::connect
will no longer cancel already in progress connections.NimBLEClient::setDataLen
now returns bool, true if successful.NimBLEClient::updateConnParams
now returns bool, true if successful.NimBLEClient::setPeerAddress
now returns a bool, true on success.NimBLEDevice::startSecurity
now takes and additional parameterint* rcPtr
which will provide the return code from the stack if provided.NimBLEDevice::deleteClient
no longer blocks tasks.NimBLEDevice::getAddress
will now return the address currently in use.NimBLEDevice::init
now returns a bool withtrue
indicating success.NimBLEDevice::deinit
now returns a bool withtrue
indicating success.NimBLEDevice::setDeviceName
now returns a bool withtrue
indicating success.NimBLEDevice::setCustomGapHandler
now returns a bool withtrue
indicating success.NimBLEDevice::setOwnAddrType
now returns a bool withtrue
indicating success and works with non-esp32 devices.NimBLEDevice::setPower
now returns a bool value, true = success.NimBLEDevice::setMTU
now returns a bool value, true = success.NimBLEDevice::deleteAllBonds
now returns true on success, otherwise false.NimBLEEddystoneTLM
internal data struct typeBeaconData
is now public and usable by the application.NimBLEBeacon
internal data struct typeBeaconData
is now public and can be used by the application.- Removed tracking of client characteristic subscription status from
NimBLEServer
andNimBLECharacteristic
and instead uses
the functions and tracking in the host stack. NimBLECharacteristic::indicate
now takes the same parameters asnotify
.NimBLECharacteristic::notify
andNimBLECharacteristic::indicate
now return abool
, true = success.- Added optional
connHandle
parameter toNimBLECharacteristic::notify
to allow for sending notifications to specific clients. NimBLEServer
Now uses a std::array to store client connection handles instead of std::vector to reduce memory allocation.NimBLEExtAdvertisement
; All functions that set data now returnbool
, true = success.NimBLEAdvertising
Advertising data is now stored in instances ofNimBLEAdvertisingData
and old vectors removed.NimBLEAdvertising::setAdvertisementData
andNimBLEAdvertising::setScanResponseData
now returnbool
, true = success.- Added optional
NimBLEAddress
parameter toNimBLEAdvertising::start
to allow for directed advertising to a peer. - All
NimBLEAdvertising
functions that change data values now returnbool
, true = success. - All
NimBLEAdvertisementData
functions that change data values now returnbool
, true = success. NimBLEAdvertisementData::setName
now takes an optionalbool
parameter to indicate if the name is complete or incomplete, default = complete.NimBLEAdvertisementData
moved to it's own .h and .cpp files.NimBLEScan::start
takes a newbool restart
parameter, defaulttrue
, that will restart an already in progress scan and clear the duplicate filter so all devices will be discovered again.- Scan response data that is received without advertisement first will now create the device and send a callback.
NimBLEScan::start
will no longer clear cache or results if scanning is already in progress.NimBLEScan::start
will now allow the start command to be sent with updated parameters if already scanning.NimBLEScan::clearResults
will now reset the vector capacity to 0.- Host reset will now no longer restart scanning and instead will call
NimBLEScanCallbacks::onScanEnd
. - Added optional
index
parameter toNimBLEAdvertisedDevice::getPayloadByType
NimBLEUtils
: Add missing GAP event strings.NimBLEUtils
: Add missing return code strings.NimBLEUtils
: Event/error code strings optimized.NimBLEAttValue
cleanup and optimization.- cleaned up code, removed assert/abort calls, replaced with a configurable option to enable debug asserts.
Added
- (esp32 specific)
NimBLEDevice::setPowerLevel
andNimBLEDevice::getPowerLevel
which take and return the relatedesp_power_level*
types. NimBLEDevice::setDefaultPhy
which will set the default preferred PHY for all connections.NimBLEDevice::getConnectedClients
, which returns a vector of pointers to the currently connected client instances.NimBLEDevice::setOwnAddr
function added, which takes auint8_t*
orNimBLEAddress&
and will set the mac address of the device, returnsbool
true = success.NimBLEDevice::injectPassKey
Used to send the pairing passkey instead of a return value from the client callback.NimBLEDevice::injectConfirmPasskey
Used to send the numeric comparison pairing passkey confirmation instead of a return value from the client callback.NimBLEDevice::setDeviceName
to change the device name after initialization.NimBLECharacteristic::create2904
which will specifically create a Characteristic Presentation Format (0x2904) descriptor.NimBLEAdvertising::refreshAdvertisingData
refreshes the advertisement data while still actively advertising.NimBLEClient::updatePhy
to request a PHY change with a peer.NimBLEClient::getPhy
to read the current connection PHY setting.Config
struct toNimBLEClient
to efficiently set single bit config settings.NimBLEClient::setSelfDelete
that takes the bool parametersdeleteOnDisconnect
anddeleteOnConnectFail
, which will configure the client to delete itself when disconnected or the connection attempt fails.NimBLEClient::setConfig
andNimBLEClient::getConfig
which takes or returns aNimBLEClient::Config
object respectively.NimBLEClient::cancelConnect()
to cancel an in-progress connection, returnsbool
, true = success.- Non-blocking
NimBLEClient::connect
option added via 2 newbool
parameters added to the function: -
asyncConnect
; if true, will send the connect command and return immediately.
-
exchangeMTU
; if true will send the exchange MTU command upon connection.
NimBLEClientCallbacks::onConnectFail
callback that is called when the connection attempt fail while connecting asynchronously.NimBLEClientCallbacks::onMTUChange
callback which will be called when the MTU exchange completes and takes aNimBLEClient*
anduint16_t MTU
parameter.NimBLEClientCallbacks::onPhyUpdate
and -NimBLEServerCallbacks::onPhyUpdate
Which are called when the PHY update is complete.- Extended scan example.
NimBLEServer::updatePhy
to request a PHY change with a peer.NimBLEServer::getPhy
to read the PHY of a peer connection.NimBLEServer::getClient
which will create a client instance from the provided peer connHandle or connInfo to facilitate reading/write from the connected client.NimBLEServerCallbacks::onConnParamsUpdate
callback.NimBLEScan::erase
overload that takes aconst NimBLEAdvertisedDevice*
parameter.NimBLEScan::setScanPhy
to enable/disable the PHY's to scan on (extended advertising only).NimBLEScan::setScanPeriod
which will allow for setting a scan restart timer in the controller (extended advertising only).NimBLEAdvertisedDevice::isScannable()
that returns true if the device is scannable.NimBLEAdvertisedDevice::begin
andNimBLEAdvertisedDevice::end
read-only iterators for convenience and use in range loops.NimBLEAdvertisedDevice::haveType
Generic use function that returns true if the advertisement data contains a field with the specified type.NimBLEExtAdvertisement::removeData
, which will remove the data of the specified type from the advertisement.NimBLEExtAdvertisement::addServiceUUID
, which will append to the service uuids advertised.NimBLEExtAdvertisement::removeServiceUUID
, which will remove the service from the uuids advertised.NimBLEExtAdvertisement::removeServices
, which will remove all service uuids advertised.- New overloads for
NimBLEExtAdvertisement::setServiceData
with the parametersconst NimBLEUUID& uuid, const uint8_t* data, size_t length
andconst NimBLEUUID& uuid, const std::vector<uint8_t>& data
. NimBLEExtAdvertisement::getDataLocation
, which returns the location in the advertisement data of the type requested in parameteruint8_t type
.NimBLEExtAdvertisement::toString
which returns a hex string representation of the advertisement data.NimBLEAdvertising::getAdvertisementData
, which returns a reference to the currently set advertisement data.NimBLEAdvertising::getScanData
, which returns a reference to the currently set scan response data.- New overloads for
NimBLEAdvertising::removeServiceUUID
andNimBLEAdvertisementData::removeServiceUUID
to accept aconst char*
NimBLEAdvertising::setManufacturerData
Overload that takes aconst uint8_t*
and , size_t` parameter.NimBLEAdvertising::setServiceData
Overload that takesconst NimBLEUUID& uuid
,const uint8_t* data
,size_t length
as parameters.NimBLEAdvertising::setServiceData
Overload that takesconst NimBLEUUID& uuid
,const std::vector<uint8_t>&
as parameters.NimBLEAdvertising::setDiscoverableMode
to allow applications to control the discoverability of the advertiser.NimBLEAdvertising::setAdvertisingCompleteCallback
sets the callback to call when advertising ends.NimBLEAdvertising::setPreferredParams
that takes the min and max preferred connection parameters as an alternative forsetMinPreferred
andsetMaxPreferred
.NimBLEAdvertising::setAdvertisingInterval
Sets the advertisement interval for min and max to the same value instead of callingsetMinInterval
andsetMaxInterval
separately if there is not value difference.NimBLEAdvertisementData::removeData
, which takes a parameteruint8_t type
, the data type to remove.NimBLEAdvertisementData::toString
, which will print the data in hex.NimBLEUtils::taskWait
which causes the calling task to wait for an event.NimBLEUtils::taskRelease
releases the task from and event.NimBLEUtils::generateAddr
function added with will generate a random address and takes abool
parameter, true = create non-resolvable private address, otherwise a random static address is created, returnsNimBLEAddress
.NimBLEUUID::getValue
which returns a read-onlyuint8_t
pointer to the UUID value.NimBLEUUID::reverseByteOrder
, this will reverse the bytes of the UUID, which can be useful for advertising/logging.NimBLEUUID
constructor overload that takes a reference toble_uuid_any_t
.NimBLEAddress::isNrpa
method to test if an address is random non-resolvable.NimBLEAddress::isStatic
method to test if an address is random static.NimBLEAddress::isPublic
method to test if an address is a public address.NimBLEAddress::isNull
methods to test if an address is NULL.NimBLEAddress::getValue
method which returns a read-only pointer to the address value.NimBLEAddress::reverseByteOrder
method which will reverse the byte order of the address value.NimBLEHIDDevice::batteryLevel
returns the HID device battery level characteristic.NimBLEBeacon::setData
overload that takesuint8_t* data
anduint8_t length
.NimBLEHIDDevice::getPnp
function added to access the pnp characteristic.NimBLEHIDDevice::getHidInfo
function added to access the hid info characteristic.