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

Configure characteristic char_props: NRF_ERROR_INVALID_PARAM when set notify = 1

I have a characteristic that i want to change to allow notification. 

But when I include the presently commented line below (that sets notify to 1), the code breaks, which is why I have to comment it out.

If I change char_props.notify to 1, then characteristic_add fails with error code NRF_ERROR_INVALID_PARAM.

I saw here that the problem is maybe that changing notify to 1 makes the attr_md and the char_props not match. 

But I searched through the whole solution and cannot find where the attr_md gets set. 

Also, if I set char_props.read = 0 or char_props.write = 0, it still works fine. If changing notify from 0 to 1 makes it break, I would expect changing read or write from 1 to 0 would also make it break, but it doesn't. So maybe attr_md is not the problem.

Why can't I turn "notify" on?

Code is here:

 ble_monitor_service_log_period_t log_period_initial_value = p_monitor_service_init->ble_monitor_service_log_period_initial_value; 

    uint8_t log_period_encoded_value[MAX_LOG_PERIOD_LEN];
    ble_add_char_params_t add_log_period_params;
    memset(&add_log_period_params, 0, sizeof(add_log_period_params));
    
    add_log_period_params.uuid                = 0xABCD; 
    add_log_period_params.max_len             = MAX_LOG_PERIOD_LEN;
    add_log_period_params.init_len            = log_period_encode(&log_period_initial_value, log_period_encoded_value, sizeof(log_period_encoded_value));
    add_log_period_params.p_init_value        = log_period_encoded_value; 
    add_log_period_params.char_props.read     = 1; 
//    add_log_period_params.char_props.notify   = 1;
    add_log_period_params.read_access         = SEC_OPEN; 
    add_log_period_params.char_props.write    = 1; 
    add_log_period_params.write_access        = SEC_OPEN; 
    // 1 for variable length and 0 for fixed length.
    add_log_period_params.is_var_len          = 1; 

    /* YOUR_JOB: Setup Characteristic User Description below */
    ble_add_char_user_desc_t log_period_characteristic_user_description;
    uint8_t log_period_characteristic_user_description_val[]  = "Log Period";
    memset(&log_period_characteristic_user_description, 0, sizeof(log_period_characteristic_user_description));
    log_period_characteristic_user_description.read_access      = SEC_OPEN;
    log_period_characteristic_user_description.write_access     = SEC_NO_ACCESS;
    log_period_characteristic_user_description.max_size         = MAX_CHARACTERISTIC_USER_DESCRIPTION_LEN;
    log_period_characteristic_user_description.size             = sizeof(log_period_characteristic_user_description_val) - 1;
    log_period_characteristic_user_description.is_value_user    = false;
    log_period_characteristic_user_description.p_char_user_desc = log_period_characteristic_user_description_val;
    add_log_period_params.p_user_descr = &log_period_characteristic_user_description;
    
    err_code = characteristic_add(p_monitor_service->service_handle, &add_log_period_params, &(p_monitor_service->log_period_handles));

Also, how does it make sense that 

    log_period_characteristic_user_description.write_access     = SEC_NO_ACCESS;

and also

     add_log_period_params.char_props.write = 1;
     add_log_period_params.write_access = SEC_OPEN;

can both be set simultaneously? It seems like one is saying there is no write access, and the other says there is write access. But somehow this works and the debugger does not complain. 

Parents Reply Children
No Data
Related