onread() event in SDK17

Hello all,

I am migrating our FW NRF52832 from SDK11 to SDK17. (Actually I am starting from scratch on 17).
Here I have two characteristics with only read properties (e.g. version string).
I can't get the read to read out so that I get a readevent (onread()). The read from the client only gets 0 values. I can't find any examples in the ./Examples where only the read characteristic is described.
I also don't know how/ where to include "on_read()".
Do you have a working example for me to copy this from?

I have tried this:
in uint32_t ble_cus_init(ble_cus_t *
/***********************************************************************************

// Add the version characteristic.

uint8_t pot_char_init_value [1] = {0};

memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = VERSION_STRING_CHAR_UUID;
add_char_params.uuid_type = p_cus->uuid_type;

add_char_params.init_len = 16;// (in bytes)
add_char_params.max_len = 16;
add_char_params.p_init_value = pot_char_init_value;

add_char_params.char_props.read = 1;
add_char_params.char_props.notify = 0;

add_char_params.read_access = SEC_OPEN;
add_char_params.cccd_write_access = SEC_NO_ACCESS;

err_code = characteristic_add(p_cus->service_handle,
&add_char_params,
&p_cus->version_string_char_handles);
if (err_code != NRF_SUCCESS)
{
return err_code;
}

Parents
  • Hi,

    There should not be any problems having characteristics with only read properties. Could it be that you somehow forget or fail to update the value, so that the init value is still used when you test? You can se an example of only read in for instance the implementation of the GLS service (SDK 17.1, around line 249 in components\ble\ble_services\ble_gls\ble_gls.c).

    If you want an event on read you need to use authorized read, as without it this is handled by the stack without notifying the application. See this thread for details.

Reply
  • Hi,

    There should not be any problems having characteristics with only read properties. Could it be that you somehow forget or fail to update the value, so that the init value is still used when you test? You can se an example of only read in for instance the implementation of the GLS service (SDK 17.1, around line 249 in components\ble\ble_services\ble_gls\ble_gls.c).

    If you want an event on read you need to use authorized read, as without it this is handled by the stack without notifying the application. See this thread for details.

Children
  • Okay, I got it.
    I modified my code and it now works as expected.
    Thanks for that.

    // Add the VersionString characteristic.

    uint8_t VersionString[16] = {"01.02.03.04"};

    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid = VERSION_STRING_CHAR_UUID;
    add_char_params.uuid_type = p_cus->uuid_type;

    add_char_params.init_len = strlen(VersionString);
    add_char_params.max_len = add_char_params.init_len;
    add_char_params.p_init_value = VersionString;

    add_char_params.char_props.read = 1;
    add_char_params.read_access = SEC_OPEN;

    err_code = characteristic_add(p_cus->service_handle, &add_char_params, &p_cus->version_string_char_handles);
    if (err_code != NRF_SUCCESS)
    {
    return err_code;
    }

Related