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

I'd like to change Characteristic UUID, not based service UUID.

Hello

I have some problem that I want to change Characteristic UUID different from Service UUID. Like,

Service UUID : 11111111 - 1111 -1111 -1111 -111111111111

Charcteristic UUID : 11111111 - 1111 -1111 -1111 -111111115555

I already read other question about chage characteristic UUID. And I try it, but if I add service UUID to use API (sd_ble_uuid_vs_add), advertising is not working.

I have used exemple source which is ble_app_uart. And I used SDK 12.3.0 (S130)

this is my source.

static uint32_t tx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init) { ble_gatts_char_md_t char_md; ble_gatts_attr_t attr_char_value; ble_uuid_t ble_uuid; ble_gatts_attr_md_t attr_md;

ble_uuid128_t tx_base_uuid = TEST_TXCHARACTER_UUID;		// change characteristic UUID diffrent frow service UUID.

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

char_md.char_props.write         = 1;
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc         = NULL;
char_md.p_char_pf                = NULL;
char_md.p_user_desc_md           = NULL;
char_md.p_cccd_md                = NULL;
char_md.p_sccd_md                = NULL;

ble_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;

ble_uuid.type = p_nus->uuid_type;
sd_ble_uuid_vs_add(&tx_base_uuid, &ble_uuid.type);	// Add new base UUID for add characteristic UUID

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

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);

attr_md.vloc    = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen    = 1;

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

attr_char_value.p_uuid    = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len  = 1;
attr_char_value.init_offs = 0;
attr_char_value.max_len   = BLE_NUS_MAX_TX_CHAR_LEN;

return sd_ble_gatts_characteristic_add(p_nus->service_handle,
                                       &char_md,
                                       &attr_char_value,
                                     //  &aa_char_handles);
                                       &p_nus->tx_handles);

}

Please let me know, how to change characteristic UUID.

  • This post should hint how UUIDs work in Nordic stack (always pair of 128-bit base and 16-bit "short" UUID). If for whatever reason you want to set Service or Characteristic (all GATT "objects" are independent so you can assign whatever UUID to whatever object) with new custom 128-bit UUID (as you suggest = altering UUIDs in the end means completely different 128-bit UUID base) then you do the same steps as always:

    1. Provision it to Nordic stack through sd_ble_uuid_vs_add function call.
    2. Make sure that FW still compiles and boots (ATT UUID table is dynamic so you need to adjust SD RAM space if you grow it over certain limit set by your previous configuration).
    3. Use new UUID base index when provisioning any GATT object which has UUID derived from it.

    Looks simple, doesn't it?

Related