Bluetooth LE GattServer AddDescriptor

Hey ,
I use for the creation of a Bluettoth GattServer the NodeMCu-ESP-s and the Arduino- IDE.
I create a Server Service with 3 Characteristics.
I want to add to each Characteristic a Descriptor.
But I dont know how.Alltime I get a Error.

I attched my Scetch.

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

#define SERVICE_UUID "58A329BE-1B1F-4A53-A874-854081499990"
#define CHARACTERISTIC_UUID_TX "C0448006-6CEE-4B41-9E73-D3FB3FF9FD81"
#define CHARACTERISTIC_UUID_RX "c0de0003-feed-f00d-c0ff-eeb3d2dbcce5"
#define CHARACTERISTIC_UUID_PacketCountTX "9308cd72-ac82-11e9-a2a3-2a2ae2dbcce4"
#define DESCRIPTOR_UUID_RX "ec57c662-ac5f-11e9-a2a3-2a2ae2dbcce4"

BLECharacteristic *pCharacteristicRX;
BLECharacteristic *pCharacteristicTX;
BLECharacteristic *pCharacteristicPacketCountTX;
BLEDescriptor pDescriptorRX(DESCRIPTOR_UUID_RX);

bool deviceConnected = false;       
 
class EchoServerCallbacks: public BLEServerCallbacks
{
    void onConnect(BLEServer* pServer)
    {
      deviceConnected = true;
      //stop advt?
      Serial.println("Connected!");     
    };
 
    void onDisconnect(BLEServer* pServer)
    {
      //restart advt?
      deviceConnected = false;
      Serial.println("Disconnected!");     
    }
};
 
void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println("GATT Server Test");
 
  BLEDevice::init("GATT Server Test");
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new EchoServerCallbacks());
 
  BLEService *pService = pServer->createService(SERVICE_UUID);

 
  pCharacteristicRX = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID_RX,                                         
                                         BLECharacteristic::PROPERTY_WRITE
                                       );
   /******************************** What is wrong? ************************/                                 
   pDescriptorRX->setValue("Percentage 0 - 100");
   pCharacteristicRX->addDescriptor(pDescriptorRX);
   pCharacteristicRX->addDescriptor(new BLE2902());
  /******************************************************************************/       
 
  pCharacteristicTX = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID_TX,                                         
                                         BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
                                       );
                                         
  pCharacteristicPacketCountTX = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID_PacketCountTX,                                         
                                         BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ
                                       );
  pService->start(); 
  BLEAdvertising *pAdvertising = pServer->getAdvertising();
  pAdvertising->start(); 
  Serial.println("Characteristic defined! Now you can read it in your phone!");   
}

void loop()
{
  //do stuff
  // some delay before running repeatedly
  delay(1000);
}
   /******************************** What is wrong? ************************/

You tell us. Something happens when you try to compile that code. You forgot to tell us.

Hello Paul,

during compilation is stopped in this line.

 pDescriptorRX->setValue("Percentage 0 - 100");

The error message is "base operand of '->' has non-pointer type 'BLEDescriptor'.

So I tried it with this

  pDescriptorRX.setValue("Percentage 0 - 100");

Now during compilation is stopped in this line.

 pDescriptorRX->setValue("Percentage 0 - 100");

The error message is now "no matching function for call to 'BLECharacteristic::addDescriptor(BLEDescriptor&)'"

So I tried it with this

   pCharacteristicRX.addDescriptor(pDescriptorRX);

The error message is now "request for member 'addDescriptor' in 'pCharacteristicRX', which is of pointer type 'BLECharacteristic*' (maybe you meant to use '->' ?)'"

Hmm I am very confused, should I use a Pointer or not?

BLECharacteristic *pCharacteristicPacketCountTX;
BLEDescriptor pDescriptorRX(DESCRIPTOR_UUID_RX);

I use the p prefix on variable names to indicate that the variable IS a pointer. pDescriptorRX is NOT a pointer. So, why does the name start with a p?

Now during compilation is stopped in this line.
Code: [Select]

pDescriptorRX->setValue("Percentage 0 - 100");

The error message is now "no matching function for call to 'BLECharacteristic::addDescriptor(BLEDescriptor&)'"

The error messages have NOTHING to do with that (changed) line.

Ok, I understand.

Now I removed the p in the code.

During compilation is stopped in this line.

pCharacteristicRX->addDescriptor(DescriptorRX);

The error message is "no matching function for call to 'BLECharacteristic::addDescriptor(BLEDescriptor&)'".

Ok, it seems to be, that the Function AddDescriptor not exists.
In my research for the Characteristic class , where I can see the functions I could not find something helpfull.

Where I can find this Characteristic functions or how the function toAddDescriptor() is right?

I am very grateful for any help.

Ok, it seems to be, that the Function AddDescriptor not exists.

That is not what the error means. It means that there is no overload of the method that takes the kind of thing you are trying to pass it.

There is nothing magic about libraries for the Arduino. Every library is simply a collection of header files (where classes and variables are defined) and source files (where functions and methods are implemented). So, if you want to know what methods, taking what arguments, exist, look at the header file for that class. Since the class is BLECharacteristic, the header file should be called BLECharacteristic.h.

In that file, there should be one or more AddDescriptor() methods, with arguments.