This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I setup a 128 bit service guid for extended advertising?

I have succesfully got extended advertising working using the nRF SDK on the nRF52 DK, however I haven't been able to assign it a 128 bit service guid.

Setup:

The device advertises 94 characters, as follows, which has an example of an intended service uuid in the advertisement:

"{'uuid':'d3fa3aa0-ba50-4224-a68f-f73fbd5055b8','name':'Hello Extended Advertising in JSON'}"

I've gone for this minimalistic example of 94 characters because, being between 31 and 255 characters, it falls into the extended advertising realm.

My advertising_init is as follows:

static void advertising_init(void)

{
ret_code_t err_code;
ble_advertising_init_t init;

memset(&init, 0, sizeof(init));

init.advdata.name_type = BLE_ADVDATA_FULL_NAME;

init.advdata.include_appearance = false;
init.config.ble_adv_fast_enabled = true;
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
init.config.ble_adv_primary_phy = BLE_GAP_PHY_1MBPS;
init.config.ble_adv_secondary_phy = BLE_GAP_PHY_2MBPS;
init.config.ble_adv_extended_enabled = true;
init.advdata.p_service_data_array = createTestSingleServiceArray();
init.advdata.service_data_count = 0x01;

init.evt_handler = on_adv_evt;

err_code = ble_advertising_init(&m_advertising, &init);

APP_ERROR_CHECK(err_code);

ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);

}
The service uuid itself is assigned in the createTestSingleServiceArray() function, which itself calls a helper function, as follows:
uint8_t *createTestService(void)
{
static const uint8_t buffer[] = { "{'uuid':'d3fa3aa0-ba50-4224-a68f-f73fbd5055b8','name':'Hello Extended Advertising in JSON'}" };
uint8_t *rv = malloc(sizeof(buffer));
if (rv != 0)
memmove(rv, buffer, sizeof(buffer));
return rv;
}

static ble_advdata_service_data_t *createTestSingleServiceArray(void)
{
ble_advdata_service_data_t myservice;
uint16_t my_service_uuid;
uint8_array_t mydata;

my_service_uuid = 0x0112;

mydata.size = 91;
mydata.p_data = createTestService();

myservice.data = mydata;
myservice.service_uuid = my_service_uuid;

const ble_advdata_service_data_t buffer[] = { myservice };

ble_advdata_service_data_t *rv = malloc(sizeof(buffer));
if (rv != 0)
memmove(rv, buffer, sizeof(buffer));
return rv;
}
As you can see, I have assigned the short uuid to the struct as follows:
myservice.service_uuid = my_service_uuid;
where 
my_service_uuid
is merely a uint16_t and cannot accept a 128 bit uuid.
Any ideas would be appreciated!
  • I expect you first will need to check that you have configured the softdevice to handle vendor specific 128-bit UUID, refer for instance to the ble_app_blinky and nrf_sdh_ble_default_cfg_set(), look for NRF_SDH_BLE_VS_UUID_COUNT.

    You can for instance find in ble_lbs_init() that sd_ble_uuid_vs_add() is called, and this must be called for each 128-bit base UUID you want to add. When calling sd_ble_uuid_vs_add() the last parameter (p_uuid_type) is updated to the index (starting from the value of 0x02) of the stored base UUID. 

    Now, each time you call sd_ble_gatts_service_add() or sd_ble_gatts_characteristic_add(), make sure that the uuid_type equal the index (p_uuid_type) you want to use.

Related