I am using ESP32-S3 board Lilygo T-Display.
So I have been trying with few different ways of defining services and characteristics using this long string as well as with BLEUUID()
function as follows
#define SERVICE_UUID BLEUUID((uint16_t)0x180D)
#define CHARACTERISTIC_UUID BLEUUID((uint16_t)0x2A37)
BLEDescriptor heartRateDescriptor(BLEUUID((uint16_t)0x2901));
Following is the sketch where I am trying to create a UART service as specified in Nordic Semiconductor Infocenter
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
uint8_t txValue = 0;
bool deviceConnected = false;
class MyServerCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer *pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer *pServer) {
deviceConnected = false;
}
};
class MyCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
}
};
void
setup() {
BLEDevice::init("UART Service");
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY);
pCharacteristic->addDescriptor(new BLE2902());
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE);
pCharacteristic->setCallbacks(new MyCallbacks());
pService->start();
pServer->getAdvertising()->start();
}
void loop() {
// put your main code here, to run repeatedly:
if (deviceConnected) {
Serial.printf("*** Sent Value: %d ***\n",
txValue);
pCharacteristic->setValue(&txValue, 1);
pCharacteristic->notify();
txValue++;
delay(1000);
}
}
The resulting service and characteristics show completely different UUIDs on the NRFConnect app. It also has a wrong PROPERTIES, shows all of them, and instead of 2 there is only one characteristic.
Which is why the logger app does not detect it as a UART enabled device.
What am I doing wrong here?