9 years, 8 months ago.

Best practice for creating custom 128 bit UUIDs

I' looking for some guidance in creating custom service UUIDs with this API and how to advertise them. All of the examples only use the SIG specified services and add them in the form

static const uint16_t uuid16_list[] = {GattService::UUID_DEVICE_INFORMATION_SERVICE,
                                                         GattService::UUID_BATTERY_SERVICE};

and then add them to the advertising data with

ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, 
                                                       (uint8_t*)uuid16_list, sizeof(uuid16_list));

I would like to achieve this with a combination of SIG specified service UUIDs (which I would need to convert from short to long) and custom UUIDs. As shown in the BLE_UART example I'd like to reverse them add add them with

ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                    (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));

Are there an helper functions for this or should I just continue to define them statically?

Question relating to:

High level Bluetooth Low Energy API and radio abstraction layer

Still not answered "What is the best procedure for creating custom Services/Characteristics?" Thank you. Peter

posted by Peter Kmet 27 Jan 2015

1 Answer

9 years, 8 months ago.

Hello Richard,

There are no helper functions yet to go from 16-bit UUID representation to 128-bit; or to reverse a 128-bit UUID to prepare for accumulation to the advertising payload. Perhaps these could be added as static helpers to the UUID class. If you submit such code, I'd be happy to include it in the BLE_API.

thanks, Rohit.

I'm still struggling to create my 128 bit UUIDs and implement a custom Service for some custom Characteristics (to me the Adopted stuff seems to cover a very limited number of use cases).

What is the best procedure for creating custom Services/Characteristics?

Also, I have a question about the 31byte limit for the advertising payload. How exactly does the advertising payload stack up? I've commented in what I believe to be the number of bytes added in each step of accumulateAdvertisingPayload in the code below.

I'm a little confused on, for example, the (uint8_t *) uuid16_list, and sizeof(uuid16_list)? Is the (uint8_t *) a typecast (pointer in a 32 bit architecture = 4 bytes?)... and the sizeof(data) is that the actual size of the data? (i.e. 6 bytes, or the accumulation of three 2 byte, short UUIDs).

I think that verbose commenting of what's in there might be useful for people like me just starting out.

It seems this device is already close to the limit of it's advertising payload... Also Is there any dependency on the size of the characteristic's UUIDs on the advertising payload? And lastly, If I need more space am I limited to just one scan response?

Thanks

    /* Setup advertising. */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
 ** BYTES: 1**

    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
**BYTES: 1 + 4? + 6?**

    ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); 
**How big is Appearance enum?**

    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
**BYTES: 1 + 4? + 1 byte memory for each char in "Nordic_HRM" so.. 10bytes?**

    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
    ble.startAdvertising();
posted by Nathan Argetsinger 03 Dec 2014