arduino-libraries / ArduinoBLE

ArduinoBLE library for Arduino
GNU Lesser General Public License v2.1
307 stars 205 forks source link

Issue adding Descriptors to Arduino Nano 33 BLE #312

Open dntpannik opened 1 year ago

dntpannik commented 1 year ago

I'm writing some bluetooth application using the Nano 33 BLE. I was trying to use the addDescriptor method as described in the ArduinoBLE documentation but I'm finding that the descriptor isn't actually being added.

I found an example on Stack Overflow where a user posted their code and a screenshot from a scanner like nRF connect showing the descriptors.

I copied this code and am still not finding the descriptors. Here is the code in question.

#include <ArduinoBLE.h>

BLEService echoService("00000000-0000-1000-8000-00805f9b34fb");
BLEStringCharacteristic charac ("741c12b9-e13c-4992-8a5e-fce46dec0bff", BLERead | BLEWrite | BLENotify,40);
BLEDescriptor Descriptor("beca6057-955c-4f8a-e1e3-56a1633f04b1","Descriptor");
String var = "";

void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
  while(!Serial);

  if(!BLE.begin()){
    Serial.println("starting BLE failed.");
    while(1);
  }

  BLE.setLocalName("Arduino BLE Echo");
  BLE.setAdvertisedService(echoService);
  charac.addDescriptor(Descriptor);
  echoService.addCharacteristic(charac);
  BLE.addService(echoService);
  BLE.advertise();

  Serial.print("Descriptor Count: ");
  Serial.println(charac.descriptorCount());

  Serial.println("Bluetooth device active, waiting for connections...");
  Serial.println(" ");
}

void loop() {
  // put your main code here, to run repeatedly:

}

I'm outputting the number of descriptors and that's coming back as zero. Connecting to the device in nRF connect shows the expected service/characteristic, but no descriptors. I've verified this with 2 different BLE scanner apps and with my iOS app.

I'm really unsure what I'm doing wrong. Hopefully someone can point me in a direction.

Thanks

dntpannik commented 1 year ago

I've done some more investigating via my iOS app, and I'm finding that the descriptor exists, but the value isn't being set. Seems like it's nul.