Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2.2 #902

Closed
wants to merge 11 commits into from
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.2.2] 2025-02-24

## Fixed
- Crash when calling `NimBLEClient::DiscoverAttributes`.

## Added
- `NimBLEDeviceCallbacks` class with a callback for handling bond storage.

## [2.2.1] 2025-01-26

## Fixed
- remote descriptor discovery error when no descriptors exist.
- scan filter settings not enabled for esp32s3/c3.
- remote descriptor discovery returning more than the desired descriptor.

## [2.2.0] 2025-01-12

## Fixed
- Crash when retrieving descriptors if more than one exists.
- Incorrect TX power value being advertised.
- New user guide code for 2.x
- Potential race condition if `NimBLEScan::clearResults1 is called from multiple tasks.
- Potential race condition if `NimBLEScan::clearResults` is called from multiple tasks.

## Changed
- If privacy is not enabled identity keys will not be shared.
Expand Down
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
esp-nimble-cpp
NimBLE-Arduino
Copyright 2020-2024 Ryan Powell <[email protected]> and
Copyright 2020-2025 Ryan Powell <[email protected]> and
esp-nimble-cpp, NimBLE-Arduino contributors.

The Initial Developer of some parts of this library, which are copied from,
The Initial Developer of some parts of this library, which are copied from,
derived from, or inspired by is, esp32-snippets, Copyright 2017 Neil Kolban.

If this library is used for commercial purposes, it is requested that the user consider
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = NimBLE-Arduino
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.2.0
PROJECT_NUMBER = 2.2.2
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NimBLE-Arduino
version=2.2.0
version=2.2.2
author=h2zero
maintainer=Ryan Powell <[email protected]>
sentence=Bluetooth low energy (BLE) library for Arduino based on NimBLE.
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLE2904.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 2 additions & 2 deletions src/NimBLE2904.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -68,7 +68,7 @@ class NimBLE2904 : public NimBLEDescriptor {
static const uint8_t FORMAT_OPAQUE = 27;
static const uint8_t FORMAT_MEDASN1 = 28;

void setDescription(uint16_t);
void setDescription(uint16_t description);
void setExponent(int8_t exponent);
void setFormat(uint8_t format);
void setNamespace(uint8_t namespace_value);
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAddress.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAddress.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
12 changes: 11 additions & 1 deletion src/NimBLEAdvertisedDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -780,6 +780,16 @@ bool NimBLEAdvertisedDevice::isLegacyAdvertisement() const {
# endif
} // isLegacyAdvertisement

/**
* @brief Convenience operator to convert this NimBLEAdvertisedDevice to NimBLEAddress representation.
* @details This allows passing NimBLEAdvertisedDevice to functions
* that accept NimBLEAddress and/or or it's methods as a parameter.
*/
NimBLEAdvertisedDevice::operator NimBLEAddress() const {
NimBLEAddress address(getAddress());
return address;
} // operator NimBLEAddress

/**
* @brief Get the payload advertised by the device.
* @return The advertisement payload.
Expand Down
3 changes: 2 additions & 1 deletion src/NimBLEAdvertisedDevice.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -93,6 +93,7 @@ class NimBLEAdvertisedDevice {
uint8_t getSecondaryPhy() const;
uint16_t getPeriodicInterval() const;
# endif
operator NimBLEAddress() const;

const std::vector<uint8_t>& getPayload() const;
const std::vector<uint8_t>::const_iterator begin() const;
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAdvertisementData.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 2 additions & 2 deletions src/NimBLEAdvertisementData.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -38,7 +38,7 @@ class NimBLEAdvertisementData {
bool addData(const uint8_t* data, size_t length);
bool addData(const std::vector<uint8_t>& data);
bool setAppearance(uint16_t appearance);
bool setFlags(uint8_t);
bool setFlags(uint8_t flag);
bool addTxPower();
bool setPreferredParams(uint16_t minInterval, uint16_t maxInterval);
bool addServiceUUID(const NimBLEUUID& serviceUUID);
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAdvertising.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAdvertising.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAttValue.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAttValue.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAttribute.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEBeacon.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEBeacon.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLECharacteristic.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLECharacteristic.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
18 changes: 1 addition & 17 deletions src/NimBLEClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -141,22 +141,6 @@ bool NimBLEClient::connect(bool deleteAttributes, bool asyncConnect, bool exchan
return connect(m_peerAddress, deleteAttributes, asyncConnect, exchangeMTU);
} // connect

/**
* @brief Connect to an advertising device.
* @param [in] device The device to connect to.
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
* have created when last connected.
* @param [in] asyncConnect If true, the connection will be made asynchronously and this function will return immediately.\n
* If false, this function will block until the connection is established or the connection attempt times out.
* @param [in] exchangeMTU If true, the client will attempt to exchange MTU with the server after connection.\n
* If false, the client will use the default MTU size and the application will need to call exchangeMTU() later.
* @return true on success.
*/
bool NimBLEClient::connect(const NimBLEAdvertisedDevice* device, bool deleteAttributes, bool asyncConnect, bool exchangeMTU) {
NimBLEAddress address(device->getAddress());
return connect(address, deleteAttributes, asyncConnect, exchangeMTU);
} // connect

/**
* @brief Connect to a BLE Server by address.
* @param [in] address The address of the server.
Expand Down
6 changes: 1 addition & 5 deletions src/NimBLEClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,10 +48,6 @@ struct NimBLETaskData;
*/
class NimBLEClient {
public:
bool connect(const NimBLEAdvertisedDevice* device,
bool deleteAttributes = true,
bool asyncConnect = false,
bool exchangeMTU = true);
bool connect(const NimBLEAddress& address, bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true);
bool connect(bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true);
bool disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEConnInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEDescriptor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEDescriptor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
18 changes: 16 additions & 2 deletions src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -76,6 +76,9 @@ extern "C" void ble_store_config_init(void);
/**
* Singletons for the NimBLEDevice.
*/
NimBLEDeviceCallbacks NimBLEDevice::defaultDeviceCallbacks{};
NimBLEDeviceCallbacks* NimBLEDevice::m_pDeviceCallbacks = &defaultDeviceCallbacks;

# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
NimBLEScan* NimBLEDevice::m_pScan = nullptr;
# endif
Expand Down Expand Up @@ -900,7 +903,9 @@ bool NimBLEDevice::init(const std::string& deviceName) {
// Setup callbacks for host events
ble_hs_cfg.reset_cb = NimBLEDevice::onReset;
ble_hs_cfg.sync_cb = NimBLEDevice::onSync;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /*TODO: Implement handler for this*/
ble_hs_cfg.store_status_cb = [](struct ble_store_status_event* event, void* arg) {
return m_pDeviceCallbacks->onStoreStatus(event, arg);
};

// Set initial security capabilities
ble_hs_cfg.sm_io_cap = BLE_HS_IO_NO_INPUT_OUTPUT;
Expand Down Expand Up @@ -1262,4 +1267,13 @@ void nimble_cpp_assert(const char* file, unsigned line) {
}
# endif // CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED

void NimBLEDevice::setDeviceCallbacks(NimBLEDeviceCallbacks* cb) {
m_pDeviceCallbacks = cb ? cb : &defaultDeviceCallbacks;
}

int NimBLEDeviceCallbacks::onStoreStatus(struct ble_store_status_event* event, void* arg) {
NIMBLE_LOGD("NimBLEDeviceCallbacks", "onStoreStatus: default");
return ble_store_util_status_rr(event, arg);
}

#endif // CONFIG_BT_ENABLED
28 changes: 27 additions & 1 deletion src/NimBLEDevice.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -66,6 +66,7 @@ class NimBLEConnInfo;
# endif

class NimBLEAddress;
class NimBLEDeviceCallbacks;

# define BLEDevice NimBLEDevice
# define BLEClient NimBLEClient
Expand Down Expand Up @@ -129,6 +130,7 @@ class NimBLEDevice {
static bool setOwnAddrType(uint8_t type);
static bool setOwnAddr(const NimBLEAddress& addr);
static bool setOwnAddr(const uint8_t* addr);
static void setDeviceCallbacks(NimBLEDeviceCallbacks* cb);
static void setScanDuplicateCacheSize(uint16_t cacheSize);
static void setScanFilterMode(uint8_t type);
static bool setCustomGapHandler(gap_event_handler handler);
Expand Down Expand Up @@ -213,6 +215,8 @@ class NimBLEDevice {
static ble_gap_event_listener m_listener;
static uint8_t m_ownAddrType;
static std::vector<NimBLEAddress> m_whiteList;
static NimBLEDeviceCallbacks* m_pDeviceCallbacks;
static NimBLEDeviceCallbacks defaultDeviceCallbacks;

# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
static NimBLEScan* m_pScan;
Expand Down Expand Up @@ -295,5 +299,27 @@ class NimBLEDevice {

# include "NimBLEUtils.h"

/**
* @brief Callbacks associated with a BLE device.
*/
class NimBLEDeviceCallbacks {
public:
virtual ~NimBLEDeviceCallbacks() {};

/**
* @brief Indicates an inability to perform a store operation.
* This callback should do one of two things:
* -Address the problem and return 0, indicating that the store operation
* should proceed.
* -Return nonzero to indicate that the store operation should be aborted.
* @param event Describes the store event being reported.
* BLE_STORE_EVENT_FULL; or
* BLE_STORE_EVENT_OVERFLOW
* @return 0 if the store operation should proceed;
* nonzero if the store operation should be aborted.
*/
virtual int onStoreStatus(struct ble_store_status_event* event, void* arg);
};

#endif // CONFIG_BT_ENABLED
#endif // NIMBLE_CPP_DEVICE_H_
2 changes: 1 addition & 1 deletion src/NimBLEEddystoneTLM.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 Ryan Powell <[email protected]> and
* Copyright 2020-2025 Ryan Powell <[email protected]> and
* esp-nimble-cpp, NimBLE-Arduino contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading