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

How to change value of descriptor?

Hello,

I've generated code via latest BDS and nRF51 SDK 10 plugin, and everything works OK, beside "desciptor" change. When I execute function to set value of descriptor:

ble_control_register_data_descriptor_set(&service_struct, &control_register_data_descriptor);

it returns "NRF_ERROR_INVALID_PARAM" and descriptor remain unchanged. I've checked arguments of the function and they match to declaration. in similar way, line above, I'm using also generated function for change related characteristic value:

ble_mug_control_register_data_set(&service_struct, &control_register_data);

and it works.

I can add that I'm calling this functions inside write event:

static void on_write(ble_service_t * p_service, ble_gatts_evt_write_t * p_ble_evt)

of other characteristic - I want achieve such behavior, that when client write "characteristic 1", then in "on_write", value of "characteristic 2" is evaluated as well as descriptor related to this characteristic.

I've prepared example, based on SDK10 example "experimental_bluetoothds_template", full source: experimental_bluetoothds_template_COPY.zip

www.filedropper.com/experimentalbluetoothdstemplatecopy

ble_service.c:114-118 contain code related to update descriptor value:

ble_service_control_register_data_new_descriptor_t descriptor;
uint8_t data = 0x88;
descriptor.control_register_data.size = 1;
descriptor.control_register_data.p_data = &data;
ble_service_control_register_data_new_descriptor_set(p_service, &descriptor);

Is there something I've missed, is impossible to change descriptor value in such scenario or there is other way to do this?

  • I cannot access the attached file on filedropper for some reason. Can you attach a zip of the project to your question post?

  • Finally found attach file button :) File: "experimental_bluetoothds_template_COPY.zip"

  • I cannnot find ble_mug_control_register_data_set nor ble_control_register_data_descriptor_set in the files you provided. In which file and what line under can i find them?

  • Sorry for misleading - ble_mug_control_register_data_set and ble_control_register_data_descriptor_set was edited by hand before I've attached example project (original source). In attached example project where I extracted problem ble_control_register_data_descriptor_set corresponds to ble_service_control_register_data_new_descriptor_setas you can see in code snippet (ble_service.c:114-118). ble_mug_control_register_data_set in example isn't present (it's work, so not included).

  • Inside ble_service_control_register_data_new_descriptor_set we find

    return sd_ble_gatts_value_set(p_service->conn_handle, p_service->control_register_data_new_descriptor_handles.value_handle, &gatts_value);
    

    The attribute handle we use here (second parameter) is never set. It is given to us here In ble_service_init :

    err_code = descriptor_add(BLE_GATT_HANDLE_INVALID, &control_register_data_new_descriptor, &descr_handle);
    

    But descr handle is not saved to p_service->control_register_data_new_descriptor_handles.value_handle, &gatts_value.

    I am not sure if this is a bug in BDS or the Nordic Plugin. Try replacing this in ble_service_init

    err_code = descriptor_add(BLE_GATT_HANDLE_INVALID, &control_register_data_new_descriptor, &descr_handle);
    

    with this:

    err_code = descriptor_add(BLE_GATT_HANDLE_INVALID, &control_register_data_new_descriptor, &(p_service->control_register_data_new_descriptor_handles.value_handle));
    

    Now we pass the attribute handle of the service struct, and the function descriptor_add will save the handle for us.

    PS: Try to avoid naming your descriptors "New descriptor". It is very confusing to read the generated code :)

Related