8 years ago.

Why can't I use the getBaseUUID() method of a UUID instance directly as GapAdvertisingData?

In developing my BLE application, I declared a UUID in C as follows ...

const UUID myServiceUUID = UUID("1BC50001-0200-9BA0-E511-60E640FE968D");

... then to build the Advertisement I used the following ...

ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, myServiceUUID.getBaseUUID(), sizeof(myServiceUUID.getBaseUUID()));

However, when I ran the code, the Service didn't actually appear in the Advertisement Data (as checked using LightBlue).

This was somewhat perplexing, and annoyingly time-consuming, because I had read the UUID.h file and the documentation, and it clearly showed that the getBaseUUID() returned the UUID as a uint8_t array in the correct reversed form for the advertisement. I even checked this to be this case by printing out each of the bytes individually, and also the result of the sizeof() function.

This was very curious, so I decided to make an intermediate copy of the uint8_t array returned by the getBaseUUID() method, and use it in the advertisement instead.

uint8_t foo[16];

...

for (int i=0; i<16; i++) {
        foo[i] = myServiceUUID.getBaseUUID()[i]);
}

...

ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, foo, sizeof(foo));

Guess what; it worked perfectly!

So for practical reasons, I will follow this "recipe" in subsequent applications. But I would still like to know why I can't use the result from the call to getBaseUUID() directly in the Advertisement.

Any thoughts?

Be the first to answer this question.