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

Couldn't add a custom characteristics with 128 bit uuid

I'm using nrf52832 and want to add a custom characteristics. But if I call the function below, the device stops advertising.

Do you have any idea?

static void add_characteristics(ble_os_t *p_our_service) 
uint32_t   err_code = 0; // Variable to hold return codes from library and softdevice functions

// OUR_JOB: Step 2.A, Add a custom characteristic UUID
ble_uuid_t          char_uuid;
ble_uuid128_t       base_uuid = {SERVICE_CHARACTERISTIC_UUID};
char_uuid.uuid      = 0x8ec3;
sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
APP_ERROR_CHECK(err_code);

// OUR_JOB: Step 2.F Add read/write properties to our characteristic
ble_gatts_char_md_t char_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;


// OUR_JOB: Step 3.A, Configuring Client Characteristic Configuration Descriptor metadata and add to char_md structure
ble_gatts_attr_md_t cccd_md;
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc                = BLE_GATTS_VLOC_STACK;    
char_md.p_cccd_md           = &cccd_md;
char_md.char_props.notify   = 1;


// OUR_JOB: Step 2.B, Configure the attribute metadata
ble_gatts_attr_md_t attr_md;
memset(&attr_md, 0, sizeof(attr_md)); 
attr_md.vloc        = BLE_GATTS_VLOC_STACK;   


// OUR_JOB: Step 2.G, Set read/write security levels to our characteristic
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);


// OUR_JOB: Step 2.C, Configure the characteristic value attribute
ble_gatts_attr_t    attr_char_value;
memset(&attr_char_value, 0, sizeof(attr_char_value));        
attr_char_value.p_uuid      = &char_uuid;
attr_char_value.p_attr_md   = &attr_md;

// OUR_JOB: Step 2.H, Set characteristic length in number of bytes
attr_char_value.max_len     = 4;
attr_char_value.init_len    = 4;
uint8_t value[4]            = {0x12,0x34,0x56,0x78};
attr_char_value.p_value     = value;

// OUR_JOB: Step 2.E, Add our new characteristic to the service
err_code = sd_ble_gatts_characteristic_add(p_our_service->service_handle,
                                   &char_md,
                                   &attr_char_value,
                                   &p_our_service->char_handles);
APP_ERROR_CHECK(err_code);}
Related