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

Service Notification problem - BLE_ERROR_INVALID_ATTR_HANDLE

Hello everyone,

I am trying to enable notification on a characteristic based on the code example from nAN36. Unfortunately the sd_ble_gatts_hvx() function returns:

BLE_ERROR_INVALID_ATTR_HANDLE - "Invalid attribute handle(s) supplied. Only attributes added directly by the application are available to notify and indicate."

I can't quite get the meaning of the "attributes added directly by the application". Any ideas how to interpret that or general guidelines how to approach this problem?

The setup is: ARMGCC + S110 + 51822. I am testing it with the nRF Master Control Panel, where it says that the notifications are enabled.

Thank you in advance!

Parents
  • Hello Petter, Thank you for the answer. However I am still having troubles with BLE_ERROR_INVALID_ATTR_HANDLE when I try to check if the notify/indicate is enabled.

    This is how the characteristic is added to the service:

    	    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;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.read   = 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.type = p_lbs->uuid_type;
        ble_uuid.uuid = LBS_UUID_BUTTON_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_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;
        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;
    
        return sd_ble_gatts_characteristic_add(p_lbs->service_handle, &char_md,
                                                   &attr_char_value,
                                                   &p_lbs->button_char_handles);
    

    This is what happens whne the button gets pressed:

    uint32_t err_code;
    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(button_state);
    
    memset(&params, 0, sizeof(params));
    params.type = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_lbs->button_char_handles.value_handle;
    params.p_data = &button_state;
    params.p_len = &len;
    
    err_code = sd_ble_gatts_hvx(p_lbs->conn_handle, &params);
    

    Is it correct to add "button_char_handles" and later try to notify on "params.handle = p_lbs->button_char_handles.value_handle"?

    Any input will be highly appreciated. Thanks!

Reply
  • Hello Petter, Thank you for the answer. However I am still having troubles with BLE_ERROR_INVALID_ATTR_HANDLE when I try to check if the notify/indicate is enabled.

    This is how the characteristic is added to the service:

    	    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;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.read   = 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.type = p_lbs->uuid_type;
        ble_uuid.uuid = LBS_UUID_BUTTON_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_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;
        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;
    
        return sd_ble_gatts_characteristic_add(p_lbs->service_handle, &char_md,
                                                   &attr_char_value,
                                                   &p_lbs->button_char_handles);
    

    This is what happens whne the button gets pressed:

    uint32_t err_code;
    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(button_state);
    
    memset(&params, 0, sizeof(params));
    params.type = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_lbs->button_char_handles.value_handle;
    params.p_data = &button_state;
    params.p_len = &len;
    
    err_code = sd_ble_gatts_hvx(p_lbs->conn_handle, &params);
    

    Is it correct to add "button_char_handles" and later try to notify on "params.handle = p_lbs->button_char_handles.value_handle"?

    Any input will be highly appreciated. Thanks!

Children
Related