I have a simple BLE example running on an ESP32. It has a single characteristic and appears to work fine. It shows up in nRFconnect and I can communicate with it on my Android app. However, when I add a 2nd charateristic, it doesn't appear to be advertised. No errors, either in the client or server, and I can still access the 1st characteristic OK.
It looks like it's a resource limitation but I can't see what to change. Any ideas?
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h> // Include this for BLE2902 (notifications)
...
BLEDevice::init("ESP32-c3-zero test");
pServer = BLEDevice::createServer ();
pServer->setCallbacks (new MyServerCallbacks ()); // Set the disconnect callback
pService = pServer->createService (SERVICE_UUID);
pCharacteristic_1 = pService->createCharacteristic (CHARACTERISTIC_UUID_1,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
pCharacteristic_1->setValue("Characteristic output: Hello world");
pCharacteristic_1->setCallbacks (new MyCallbacks ());
pCharacteristic_2 = pService->createCharacteristic (CHARACTERISTIC_UUID_2,
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
pCharacteristic_2->setValue("Initial value for Characteristic 2");
pCharacteristic_2->setCallbacks (new MyCallbacks ());
Serial.println("Starting service");
pService->start();
pAdvertising = BLEDevice::getAdvertising ();
pAdvertising->addServiceUUID (SERVICE_UUID);
pAdvertising->setScanResponse (true); // true => the ESP32 responds to scan requests with extra data (e.g., device name, more service UUIDs).
pAdvertising->setMinPreferred (0x06); // Sets the preferred connection interval (in BLE units, where 1 unit = 1.25ms).
pAdvertising->setMinPreferred (0x12); // These values influence how often the device communicates with a connected client.
delay(100); //
BLEDevice::startAdvertising(); // Start advertising
// pServer->getAdvertising()->start(); is this a better alternative?
Serial.println("Characteristic defined! Now you can read it in your phone!");
I think the problem might be in nRFconnect. Even though it claims to be discovering services and characteristics, it actually has some info cached. It's very inconsistent though. It has a 'bonded' state which appears to imply caching is happening, but the effect appears to be that it remembers the number of characteristics but not the UUIDs. I'm still working out the details but a step forward at least, so many thanks for your help.