NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

Request for info - Dynamic MachineData Advertising/BroadCast

Open LeeNX opened this issue 9 months ago • 7 comments

Please could I ask for some help with getting Dynamic MachineData Advertising / BroadCast working?

I have Googled and LLM my way to what I think should work, but keep running into

E NimBLEAdvertisementData: Data length exceeded

my function been:

void setAdvertisingData() {
   NimBLEAdvertisementData advData = pAdvertising->getAdvertisementData(); // Get existing data

   uint8_t manufacturerData[12];
    manufacturerData[0] = 0xff; // manufacturer data value - custom
    manufacturerData[1] = 0xff;
    manufacturerData[2] = 0xa0; // begin sig
    manufacturerData[3] = 0x00;
    manufacturerData[4] = advertiseInterval;    // how often broadcast
    manufacturerData[5] = batteryLevel;         // battery level
    manufacturerData[6] = chargingState;        // charging state
    manufacturerData[7] = uint8_t(internalTempInt);  // temp of SOC
    manufacturerData[8] = uint8_t(internalTempDec);  // temp below decimal
    manufacturerData[9] = 0x00; // end sig
    manufacturerData[10] = 0xa0;

    advData.setManufacturerData(std::string((char *)manufacturerData, sizeof(manufacturerData)));

    pAdvertising->setAdvertisementData(advData);
}

First call works correctly, but future calls fails with the Data length exceeded.

I was not able to find any examples that did this, thou I did find a few PRs and issues that refer to this. I was also not able to following the Classes reference, like removeData() int, but which int Types?

Thinking I might need to remove the old setManufacturerData before updating and refreshAdvertisingData?

I was also wondering how I could get the Advertising data length? This is limited to 31 characters, if I understand. Would be nice to catch and oversized data length. I was not sure if sizeof(NimBLEAdvertisementData::getPayload()) would be correct.

If seeing the rest of my sketch is helpful - esp32base-test

LeeNX avatar Feb 13 '25 12:02 LeeNX