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

How to add characteristic user description?

The SDK version I use is 15.3. And I tried to add the following code to the ble_nus.c

static uint32_t char2_add(ble_nus_t * p_nus, ble_nus_init_t const * p_nus_init)
{
    /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
    ble_add_char_params_t add_char_params;
    uint8_t user_desc[] = "DFU";

    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid                     = BLE_UUID_NUS_CHARACTERISTIC2;
    add_char_params.uuid_type                = p_nus->uuid_type;
    add_char_params.max_len                  = BLE_NUS_MAX_TX_CHAR_LEN;
    add_char_params.init_len                 = sizeof(uint8_t);
    add_char_params.is_var_len               = true;
    add_char_params.char_props.notify        = 1;
    add_char_params.char_props.write         = 1;
    add_char_params.char_props.write_wo_resp = 1;

    add_char_params.p_user_descr->is_var_len       = true;
    add_char_params.p_user_descr->char_props.write = 1;
    add_char_params.p_user_descr->char_props.read  = 1;
    add_char_params.p_user_descr->p_char_user_desc = (uint8_t *)user_desc;
    add_char_params.p_user_descr->size             = sizeof(user_desc);
    add_char_params.p_user_descr->max_size         = sizeof(user_desc);
    
    add_char_params.read_access       = SEC_OPEN;
    add_char_params.write_access      = SEC_OPEN;
    add_char_params.cccd_write_access = SEC_OPEN;

    add_char_params.p_user_descr->write_access = SEC_OPEN;
    add_char_params.p_user_descr->read_access  = SEC_OPEN;

    return characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->handles2);
}

But it didn't work.There is no characteristic 0x2901. I don't know what's wrong. Can you give me some advice?

Best regards,

June6

Parents
  • Hello,

     p_user_descr is a NULL pointer in your case. Please try to set it up like this instead:

        ble_add_char_user_desc_t  user_desc;
    
        uint8_t user_desc_str[] = "DFU";
    
        memset(&user_desc, 0, sizeof(user_desc));
        user_desc.is_var_len       = 1;
        user_desc.char_props.read  = 1;
        user_desc.size             = (sizeof(user_desc_str) - 1); // Don't include null termination
        user_desc.max_size         = (sizeof(user_desc_str) - 1); // Don't include null termination
        user_desc.p_char_user_desc = user_desc_str;
        user_desc.read_access      = SEC_OPEN;
        user_desc.write_access     = SEC_OPEN;
        
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.p_user_descr = &user_desc;
        ...

    Best regards,

    Vidar

  • Hi,

    Yes, maybe it's the null pointer problem, because I found through debugging that the parameters there are indeed null. However, after I add your suggested code, I will receive an error (NRF_ERROR_INVALID_PARAM) when I perform the characteristic_add operation

    Best regards,

    June6

Reply Children
Related