23
23
#include < BLEServer.h>
24
24
#include < BLEUtils.h>
25
25
#include < BLE2902.h>
26
+ #include < BLE2901.h>
26
27
27
28
BLEServer *pServer = NULL ;
28
29
BLECharacteristic *pCharacteristic = NULL ;
30
+ BLE2901 *descriptor_2901 = NULL ;
31
+
29
32
bool deviceConnected = false ;
30
33
bool oldDeviceConnected = false ;
31
34
uint32_t value = 0 ;
32
35
33
36
// See the following for generating UUIDs:
34
37
// https://www.uuidgenerator.net/
35
38
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 "
38
41
39
42
class MyServerCallbacks : public BLEServerCallbacks {
40
43
void onConnect (BLEServer *pServer) {
@@ -65,9 +68,13 @@ void setup() {
65
68
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE
66
69
);
67
70
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)
70
72
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);
71
78
72
79
// Start the service
73
80
pService->start ();
@@ -87,7 +94,7 @@ void loop() {
87
94
pCharacteristic->setValue ((uint8_t *)&value, 4 );
88
95
pCharacteristic->notify ();
89
96
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 );
91
98
}
92
99
// disconnecting
93
100
if (!deviceConnected && oldDeviceConnected) {
0 commit comments