Skip to content

Commit cdca672

Browse files
authored
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.
1 parent d66ca4c commit cdca672

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libraries/BLE/examples/Notify/Notify.ino

+12-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@
2323
#include <BLEServer.h>
2424
#include <BLEUtils.h>
2525
#include <BLE2902.h>
26+
#include <BLE2901.h>
2627

2728
BLEServer *pServer = NULL;
2829
BLECharacteristic *pCharacteristic = NULL;
30+
BLE2901 *descriptor_2901 = NULL;
31+
2932
bool deviceConnected = false;
3033
bool oldDeviceConnected = false;
3134
uint32_t value = 0;
3235

3336
// See the following for generating UUIDs:
3437
// https://www.uuidgenerator.net/
3538

36-
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
37-
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
39+
#define SERVICE_UUID "0000ff00-0000-1000-8000-00805f9b34fb"
40+
#define CHARACTERISTIC_UUID "0000ff01-0000-1000-8000-00805f9b34fb"
3841

3942
class MyServerCallbacks : public BLEServerCallbacks {
4043
void onConnect(BLEServer *pServer) {
@@ -65,9 +68,13 @@ void setup() {
6568
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE
6669
);
6770

68-
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
69-
// Create a BLE Descriptor
71+
// Creates BLE Descriptor 0x2902: Client Characteristic Configuration Descriptor (CCCD)
7072
pCharacteristic->addDescriptor(new BLE2902());
73+
// Adds also the Characteristic User Description - 0x2901 descriptor
74+
descriptor_2901 = new BLE2901();
75+
descriptor_2901->setDescription("My own description for this characteristic.");
76+
descriptor_2901->setAccessPermissions(ESP_GATT_PERM_READ); // enforce read only - default is Read|Write
77+
pCharacteristic->addDescriptor(descriptor_2901);
7178

7279
// Start the service
7380
pService->start();
@@ -87,7 +94,7 @@ void loop() {
8794
pCharacteristic->setValue((uint8_t *)&value, 4);
8895
pCharacteristic->notify();
8996
value++;
90-
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
97+
delay(500);
9198
}
9299
// disconnecting
93100
if (!deviceConnected && oldDeviceConnected) {

0 commit comments

Comments
 (0)