From 2ce5075a453812397283a82f5994cd2422576345 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 17 Jun 2024 17:06:54 -0300 Subject: [PATCH 1/6] feat(ble): Adds Characteristic User Descriptor Adds a class for 0x2901 - Characteristic User Descriptor. This Descriptor is usual in BLE and describes with text what each characteristic is about. --- libraries/BLE/src/BLE2901.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 libraries/BLE/src/BLE2901.h diff --git a/libraries/BLE/src/BLE2901.h b/libraries/BLE/src/BLE2901.h new file mode 100644 index 00000000000..9186dbe71c0 --- /dev/null +++ b/libraries/BLE/src/BLE2901.h @@ -0,0 +1,37 @@ +/* + BLE2901.h + + GATT Descriptor 0x2901 Characteristic User Description + + The value of this description is a user-readable string + describing the characteristic. + + The Characteristic User Description descriptor + provides a textual user description for a characteristic + value. + If the Writable Auxiliary bit of the Characteristics + Properties is set then this descriptor is written. Only one + User Description descriptor exists in a characteristic + definition. + +*/ + +#ifndef COMPONENTS_CPP_UTILS_BLE2901_H_ +#define COMPONENTS_CPP_UTILS_BLE2901_H_ +#include "soc/soc_caps.h" +#if SOC_BLE_SUPPORTED + +#include "sdkconfig.h" +#if defined(CONFIG_BLUEDROID_ENABLED) + +#include "BLEDescriptor.h" + +class BLE2901 : public BLEDescriptor { + public: + BLE2901(); + void setDescription(String desc); +}; // BLE2901 + +#endif /* CONFIG_BLUEDROID_ENABLED */ +#endif /* SOC_BLE_SUPPORTED */ +#endif /* COMPONENTS_CPP_UTILS_BLE2901_H_ */ From d66ca4ced3b5160375351bc5fa1294b3ba01ed29 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 17 Jun 2024 17:11:02 -0300 Subject: [PATCH 2/6] feat(ble): Adds Characteristic User Description Adds Descriptor 0x2901 This is the Characteristic User Description, commomnly used in BLE. Adds the implementation for make it easier to be used. --- libraries/BLE/src/BLE2901.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 libraries/BLE/src/BLE2901.cpp diff --git a/libraries/BLE/src/BLE2901.cpp b/libraries/BLE/src/BLE2901.cpp new file mode 100644 index 00000000000..4be14787391 --- /dev/null +++ b/libraries/BLE/src/BLE2901.cpp @@ -0,0 +1,41 @@ +/* + BLE2901.h + + GATT Descriptor 0x2901 Characteristic User Description + + The value of this description is a user-readable string + describing the characteristic. + + The Characteristic User Description descriptor + provides a textual user description for a characteristic + value. + If the Writable Auxiliary bit of the Characteristics + Properties is set then this descriptor is written. Only one + User Description descriptor exists in a characteristic + definition. +*/ + +#include "soc/soc_caps.h" +#if SOC_BLE_SUPPORTED + +#include "sdkconfig.h" +#if defined(CONFIG_BLUEDROID_ENABLED) + +#include "BLE2901.h" + +BLE2901::BLE2901() : BLEDescriptor(BLEUUID((uint16_t)0x2901)) { +} // BLE2901 + +/** + * @brief Set the Characteristic User Description + */ +void BLE2901::setDescription(String userDesc) { + if (userDesc.length() > ESP_GATT_MAX_ATTR_LEN) { + log_e("Size %d too large, must be no bigger than %d", userDesc.length(), ESP_GATT_MAX_ATTR_LEN); + return; + } + setValue(userDesc); +} + +#endif +#endif /* SOC_BLE_SUPPORTED */ From cdca672dfb0eae4219ef6cfbe3cc0e70b06a9f56 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 17 Jun 2024 17:43:57 -0300 Subject: [PATCH 3/6] feat(BLE): Update Notify.ino Improve Notify.ino example by adding the 0x2901 descriptor This also prevents and helps to find issues when testing CI. --- libraries/BLE/examples/Notify/Notify.ino | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libraries/BLE/examples/Notify/Notify.ino b/libraries/BLE/examples/Notify/Notify.ino index 896cc2260f7..fee3cd737ed 100644 --- a/libraries/BLE/examples/Notify/Notify.ino +++ b/libraries/BLE/examples/Notify/Notify.ino @@ -23,9 +23,12 @@ #include #include #include +#include BLEServer *pServer = NULL; BLECharacteristic *pCharacteristic = NULL; +BLE2901 *descriptor_2901 = NULL; + bool deviceConnected = false; bool oldDeviceConnected = false; uint32_t value = 0; @@ -33,8 +36,8 @@ uint32_t value = 0; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" -#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" +#define SERVICE_UUID "0000ff00-0000-1000-8000-00805f9b34fb" +#define CHARACTERISTIC_UUID "0000ff01-0000-1000-8000-00805f9b34fb" class MyServerCallbacks : public BLEServerCallbacks { void onConnect(BLEServer *pServer) { @@ -65,9 +68,13 @@ void setup() { BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE ); - // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml - // Create a BLE Descriptor + // Creates BLE Descriptor 0x2902: Client Characteristic Configuration Descriptor (CCCD) pCharacteristic->addDescriptor(new BLE2902()); + // Adds also the Characteristic User Description - 0x2901 descriptor + descriptor_2901 = new BLE2901(); + descriptor_2901->setDescription("My own description for this characteristic."); + descriptor_2901->setAccessPermissions(ESP_GATT_PERM_READ); // enforce read only - default is Read|Write + pCharacteristic->addDescriptor(descriptor_2901); // Start the service pService->start(); @@ -87,7 +94,7 @@ void loop() { pCharacteristic->setValue((uint8_t *)&value, 4); pCharacteristic->notify(); value++; - delay(3); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms + delay(500); } // disconnecting if (!deviceConnected && oldDeviceConnected) { From 80b2a6f1763f0369c66632a45c8188ea77d89202 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 17 Jun 2024 17:46:26 -0300 Subject: [PATCH 4/6] fix(BLE): fixes the UUIDs used in the example Fixes the UUIDs to used the ame as in BLE Client example. Makes sure that all examples use the same UUIDs. --- libraries/BLE/examples/Notify/Notify.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/BLE/examples/Notify/Notify.ino b/libraries/BLE/examples/Notify/Notify.ino index fee3cd737ed..502979c75ea 100644 --- a/libraries/BLE/examples/Notify/Notify.ino +++ b/libraries/BLE/examples/Notify/Notify.ino @@ -36,8 +36,8 @@ uint32_t value = 0; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ -#define SERVICE_UUID "0000ff00-0000-1000-8000-00805f9b34fb" -#define CHARACTERISTIC_UUID "0000ff01-0000-1000-8000-00805f9b34fb" +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" class MyServerCallbacks : public BLEServerCallbacks { void onConnect(BLEServer *pServer) { From 651b941da7efed85817ac44293bea4d8613fdb61 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 17 Jun 2024 17:54:10 -0300 Subject: [PATCH 5/6] fix(BLE): adds library code to the CMakeLists.txt Adds the necessary new Library code to CMake. Solves CI issue. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba19b8cf035..cad3c3a079d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,6 +236,7 @@ set(ARDUINO_LIBRARY_WiFiProv_SRCS libraries/WiFiProv/src/WiFiProv.cpp) set(ARDUINO_LIBRARY_Wire_SRCS libraries/Wire/src/Wire.cpp) set(ARDUINO_LIBRARY_BLE_SRCS + libraries/BLE/src/BLE2901.cpp libraries/BLE/src/BLE2902.cpp libraries/BLE/src/BLE2904.cpp libraries/BLE/src/BLEAddress.cpp From 1a5b276a1107f186902d7d536e6bfa3d80e1d03f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:02:16 +0000 Subject: [PATCH 6/6] ci(pre-commit): Apply automatic fixes --- libraries/BLE/examples/Notify/Notify.ino | 4 ++-- libraries/BLE/src/BLE2901.cpp | 7 +++---- libraries/BLE/src/BLE2901.h | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libraries/BLE/examples/Notify/Notify.ino b/libraries/BLE/examples/Notify/Notify.ino index 502979c75ea..6b552b01d11 100644 --- a/libraries/BLE/examples/Notify/Notify.ino +++ b/libraries/BLE/examples/Notify/Notify.ino @@ -68,12 +68,12 @@ void setup() { BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE ); - // Creates BLE Descriptor 0x2902: Client Characteristic Configuration Descriptor (CCCD) + // Creates BLE Descriptor 0x2902: Client Characteristic Configuration Descriptor (CCCD) pCharacteristic->addDescriptor(new BLE2902()); // Adds also the Characteristic User Description - 0x2901 descriptor descriptor_2901 = new BLE2901(); descriptor_2901->setDescription("My own description for this characteristic."); - descriptor_2901->setAccessPermissions(ESP_GATT_PERM_READ); // enforce read only - default is Read|Write + descriptor_2901->setAccessPermissions(ESP_GATT_PERM_READ); // enforce read only - default is Read|Write pCharacteristic->addDescriptor(descriptor_2901); // Start the service diff --git a/libraries/BLE/src/BLE2901.cpp b/libraries/BLE/src/BLE2901.cpp index 4be14787391..e929262b023 100644 --- a/libraries/BLE/src/BLE2901.cpp +++ b/libraries/BLE/src/BLE2901.cpp @@ -1,6 +1,6 @@ /* BLE2901.h - + GATT Descriptor 0x2901 Characteristic User Description The value of this description is a user-readable string @@ -23,8 +23,7 @@ #include "BLE2901.h" -BLE2901::BLE2901() : BLEDescriptor(BLEUUID((uint16_t)0x2901)) { -} // BLE2901 +BLE2901::BLE2901() : BLEDescriptor(BLEUUID((uint16_t)0x2901)) {} // BLE2901 /** * @brief Set the Characteristic User Description @@ -32,7 +31,7 @@ BLE2901::BLE2901() : BLEDescriptor(BLEUUID((uint16_t)0x2901)) { void BLE2901::setDescription(String userDesc) { if (userDesc.length() > ESP_GATT_MAX_ATTR_LEN) { log_e("Size %d too large, must be no bigger than %d", userDesc.length(), ESP_GATT_MAX_ATTR_LEN); - return; + return; } setValue(userDesc); } diff --git a/libraries/BLE/src/BLE2901.h b/libraries/BLE/src/BLE2901.h index 9186dbe71c0..f5ad7c94add 100644 --- a/libraries/BLE/src/BLE2901.h +++ b/libraries/BLE/src/BLE2901.h @@ -27,9 +27,9 @@ #include "BLEDescriptor.h" class BLE2901 : public BLEDescriptor { - public: - BLE2901(); - void setDescription(String desc); +public: + BLE2901(); + void setDescription(String desc); }; // BLE2901 #endif /* CONFIG_BLUEDROID_ENABLED */