From 13165a587443edba0589cee9593895be22b9d8d3 Mon Sep 17 00:00:00 2001 From: h2zero Date: Fri, 29 Nov 2024 15:47:09 -0700 Subject: [PATCH] Refresh advertising data dynamically --- src/NimBLEAdvertising.cpp | 16 ++++++++++++++++ src/NimBLEAdvertising.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index f3227a0c..8dea708e 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -385,6 +385,22 @@ void NimBLEAdvertising::clearData() { m_advDataSet = false; } // clearData +/** + * @brief Refresh advertsing data dynamically without stop/start cycle. + * For instance allows refreshing manufacturer data dynamically. + * + * @return True if the data was set successfully. + * @details If scan response is enabled it will be refreshed as well. + */ +bool NimBLEAdvertising::refreshAdvertisingData() { + bool success = setAdvertisementData(m_advData); + if (m_scanData) { + success = setScanResponseData(m_scanData); + } + + return success; +} // refreshAdvertisingData + /** * @brief Add a service uuid to exposed list of services. * @param [in] serviceUUID The UUID of the service to expose. diff --git a/src/NimBLEAdvertising.h b/src/NimBLEAdvertising.h index 52dddbd6..ff84913a 100644 --- a/src/NimBLEAdvertising.h +++ b/src/NimBLEAdvertising.h @@ -67,6 +67,7 @@ class NimBLEAdvertising { const NimBLEAdvertisementData& getAdvertisementData(); const NimBLEAdvertisementData& getScanData(); void clearData(); + bool refreshAdvertisingData(); bool addServiceUUID(const NimBLEUUID& serviceUUID); bool addServiceUUID(const char* serviceUUID);