Replace old ESP32 BLE Library

The current DEV branch is using the ESP32 BLE for Arduino, but a newer version looks to be included in the ESP32 framework(?) now.

The newer version looks to have a few changes, including only returning one ServiceData and ServiceDataUUID per device.

I don’t know if this functionality is used with other devices, but switching to the built-in library still reports the steps for my Xiaomi MiBand 4. This version has a few bug fixes, including allowing OMG to compile with a CORE_DEBUG_LEVEL value set.

Changes

ZgatewayBT.ino : 397

if (advertisedDevice.haveServiceData()) {
    std::string serviceData = advertisedDevice.getServiceData();
    int serviceDataLength = serviceData.length();
    String returnedString = "";
    for (int i = 0; i < serviceDataLength; i++) {
      int a = serviceData[i];
      if (a < 16) {
        returnedString += F("0");
      }
      returnedString += String(a, HEX);
    }
    Log.trace(F("Service data: %s" CR), returnedString.c_str());
    BLEdata.set("servicedata", returnedString.c_str());
    std::string serviceDatauuid = advertisedDevice.getServiceDataUUID().toString();
    Log.trace(F("Service data UUID: %s" CR), (char*)serviceDatauuid.c_str());
    BLEdata.set("servicedatauuid", (char*)serviceDatauuid.c_str());
    PublishDeviceData(BLEdata);
} else {
  PublishDeviceData(BLEdata); // publish device even if there is no service data
}

Hi,

I’m working on using an alternative library called NimBLE Arduino, it is not using Bluedroid and reduce drasticaly the amount of ressources used.
This is the result of my researches around the LYWSD03MMC integration, note that this branch is based on PR724 so should be merged once we merge this PR.

1 Like

Excellent. I’ll look forward to testing it when it’s ready.