BLE notify not working with ESP32

I currently use an ESP32 who publishes (notify) when a user interacts with it. I would like to grab these notifications with a boron. I confirmed that the ESP32 works correctly with the mobile app “nRF Connect”. I also confirmed that my boron is able to receive notification from the mobile app. Strangely both devices won’t work together. Here is my sample code from the boron:

SYSTEM_MODE(MANUAL);

Logger logger("app.ble");
BleCharacteristic identifiedNFCCharacteristic;
BlePeerDevice peer;
SerialLogHandler logHandler(LOG_LEVEL_INFO);

void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) {
  logger.info("Data received %d", len);
}


// setup() runs once, when the device is first turned on.
void setup() {
  Serial.begin();
  // Put initialization like pinMode and begin functions here.
  BLE.on();
  identifiedNFCCharacteristic.onDataReceived(onDataReceived, NULL);
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
  logger.info("Looing for ble devices");
  if (BLE.connected()) {
      // We're currently connected to a sensor
      String value;
      identifiedNFCCharacteristic.getValue(value);
      logger.info("Connected: %s", value.c_str());
  } else {
      BleScanFilter filter;
      filter.serviceUUID("4c594d50-494b-2f4e-4643-524541444552"); // serviceNFCReader
      Vector<BleScanResult> scanResults = BLE.scanWithFilter(filter);
      logger.info("Found %d", scanResults.size());
      for(int i = 0; i < scanResults.size(); i++) {
          peer = BLE.connect(scanResults[i].address());
          if (peer.connected()) {
              logger.info("successfully connected!");
              if (peer.getCharacteristicByUUID(identifiedNFCCharacteristic, "4c594d50-494b-2f49-4445-4e542f4e4643") && identifiedNFCCharacteristic.isValid()) {
                  logger.info("successfully claimed char!");
              } else {
                  logger.info("failed claimed char!");
              }
          }
          else {
              logger.info("connection failed");
          }
      }
  }
  delay(1000);
}

I get the following output:

0000005346 [app.ble] INFO: Found 1
0000007130 [app.ble] INFO: successfully connected!
0000007131 [app.ble] INFO: successfully claimed char!
0000008131 [app.ble] INFO: Looing for ble devices
0000008255 [app.ble] INFO: Connected: 
0000009255 [app.ble] INFO: Looing for ble devices
0000009380 [app.ble] INFO: Connected: 
0000010380 [app.ble] INFO: Looing for ble devices
0000010505 [app.ble] INFO: Connected: 
0000011505 [app.ble] INFO: Looing for ble devices
0000011630 [app.ble] INFO: Connected: 
0000012630 [app.ble] INFO: Looing for ble devices
0000012755 [app.ble] INFO: Connected: 
0000013755 [app.ble] INFO: Looing for ble devices
0000013880 [app.ble] INFO: Connected: Hello
0000014880 [app.ble] INFO: Looing for ble devices
0000015005 [app.ble] INFO: Connected: Hello
0000016005 [app.ble] INFO: Looing for ble devices
0000016130 [app.ble] INFO: Connected: Hello
0000017130 [app.ble] INFO: Looing for ble devices

So it seems like the boron is able to read my ESP32 but I don’t get the notification. Anyone an idea why it doesn’t work with the ESP?

I found the problem. Seems like Particle devices need a description so you need to add:

BLEDescriptor *pStatusDescriptor = new BLE2902();
pCharacteristic->addDescriptor(pStatusDescriptor);

whereas mobile apps like nrf Connect also work without it.

2 Likes