This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can't connect to nrf51 if char property notify is set

Hey,

I have been trying to create a notification characteristic for nrf51822. Whenever I add char_md.char_props.notify = 1; lightblue doesn't connect to it. I do get a connection event on the nrf51822 but lightblue gives "Connection Alert : Timeout interrogating the peripheral" error. Why could this be happening? Any help will be appreciated. Thanks, Vandita

I'm using the following code to create the service and characteristic:

uint32_t   err_code;
ble_uuid_t ble_uuid;
ble_uuid128_t base_uuid = BASE_UUID;
ble_uuid.uuid = BLE_SERVICE;
err_code = sd_ble_uuid_vs_add(&base_uuid, &(ble_uuid.type));
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &service_handle);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}
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_1;
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;
cccd_md.rd_auth = 0;
cccd_md.wr_auth = 0;
cccd_md.vlen    = 1;

memset(&char_md, 0, sizeof(char_md));

char_md.char_props.write   = 1;
char_md.char_props.notify = 1;
char_md.p_char_user_desc  = NULL;
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;

ble_uuid_1.type = BLE_UUID_TYPE_BLE;
ble_uuid_1.uuid = 0x1234;

memset(&attr_md, 0, sizeof(attr_md));

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
attr_md.vloc       = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth    = 0;
attr_md.wr_auth    = 0;
attr_md.vlen       = 0;

memset(&attr_char_value, 0, sizeof(attr_char_value));

attr_char_value.p_uuid       = &ble_uuid_1;
attr_char_value.p_attr_md    = &attr_md;
attr_char_value.init_len     = sizeof(uint8_t);
attr_char_value.init_offs    = 0;
attr_char_value.max_len      = sizeof(uint8_t);
attr_char_value.p_value      = NULL;

err_code =  sd_ble_gatts_characteristic_add(service_handle, &char_md,
                                           &attr_char_value,
                                           &button_char_handles);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}
return NRF_SUCCESS;
Related