Hello,
I am working on application using nrf52810 SDK version nRF5_SDK_14.2.0_17b948a
In my application i need to read characteristics value, so after following tutorial and post , found that we need to enable rd_auth, when ever we read from nrf connect , some event is generated.
But whenever i read some characteristics value, nrf connect freezes and disconnects.
Following is my implementation, I have added multiple characteristics in service and need to read value of third charcteristics
/**@snippet [Adding proprietary characteristic to the SoftDevice] */
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_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;
/*Add char1 to service 2*/
static char *text1 = "CHAR_1";
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc = (uint8_t *)text1; //NULL;
char_md.char_user_desc_size = strlen(text1);
char_md.char_user_desc_max_size = strlen(text1);
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = &cccd_md;
char_md.p_sccd_md = NULL;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
/* Add con char */
ble_uuid.type = p_alert->uuid_type;
ble_uuid.uuid = CON_CHAR;
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = TOTAL_LEN;
attr_char_value.init_offs = 0;
attr_char_value.max_len = TOTAL_LEN;;
attr_char_value.p_value = value;
sd_ble_gatts_characteristic_add(p_alert->data_service_handle,
&char_md,
&attr_char_value,
&p_alert->tx_c_handles);
/*Add char2 to service 2*/
static char *text2 = "CHAR_2";
char_md.char_props.write_wo_resp = 0;
char_md.char_props.notify = 1;
char_md.p_char_user_desc = (uint8_t *)text2; //NULL;
char_md.char_user_desc_size = strlen(text2);
char_md.char_user_desc_max_size = strlen(text2);
ble_uuid.uuid = ALE_CHAR;
sd_ble_gatts_characteristic_add(p_alert->data_service_handle,
&char_md,
&attr_char_value,
&p_alert->tx_d_handles);
memset(&cccd_md, 0, sizeof(cccd_md));
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
/*Add char3 to service 2*/
static char *text3 = "CHAR_3";
char_md.char_props.write_wo_resp = 1;
char_md.char_props.notify = 0;
char_md.char_props.read = 1;
char_md.p_char_user_desc = (uint8_t *)text3; //NULL;
char_md.char_user_desc_size = strlen(text3);
char_md.char_user_desc_max_size = strlen(text3);
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
ble_uuid.uuid = RT_CHAR;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 1;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = 4;
attr_char_value.init_offs = 0;
attr_char_value.max_len = 4;
attr_char_value.p_value = value;
sd_ble_gatts_characteristic_add(p_alert->data_service_handle,
&char_md,
&attr_char_value,
&p_alert->tx_r_handles);
/*Add Fact mode char to service 2*/
static char *text4 = "CHAR_4";
char_md.char_props.write_wo_resp = 1;
char_md.char_props.notify = 0;
char_md.char_props.read = 1;
char_md.p_char_user_desc = (uint8_t *)text4; //NULL;
char_md.char_user_desc_size = strlen(text4);
char_md.char_user_desc_max_size = strlen(text4);
ble_uuid.uuid = FACT_CHAR;
attr_char_value.init_len = 1;
attr_char_value.init_offs = 0;
attr_char_value.max_len = 1;
attr_char_value.p_value = value;
sd_ble_gatts_characteristic_add(p_alert->data_service_handle,
&char_md,
&attr_char_value,
&p_alert->tx_f_handles);
Please let me know if any changes are required.
