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

sd_ble_gatts_characteristic_add returns NRF_ERROR_INVALID_PARAM

I get NRF_ERROR_INVALID_PARAM when calling sd_ble_gatts_characteristic_add(); If I comment custom service initialization where is this function I get the same error NRF_ERROR_INVALID_PARAM when calling ble_advertising_init(&advdata, &srdata, &options, on_adv_evt, NULL);

What could be the problem?

  • Hi.

    In ble_gatts.h you can read the error code:

     @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, service handle,
     Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.

    Are you sure that you are supplying the function with the correct parameters?

    I'm not sure what you have put in the function ble_advertising_init(), as this function should only have 2 inputs.

    As you can read in ble_advertising.h:

    /**@brief   Function for initializing the Advertising Module.
     *
     * @details Encodes the required advertising data and passes it to the stack.
     *          Also builds a structure to be passed to the stack when starting advertising.
     *          The supplied advertising data is copied to a local structure and is manipulated
     *          depending on what advertising modes are started in @ref ble_advertising_start.
     *
     * @param[out] p_advertising Advertising module instance. This structure must be supplied by
     *                           the application. It is initialized by this function and will later
     *                           be used to identify this particular module instance.
     * @param[in] p_init         Information needed to initialize the module.
     *
     * @retval NRF_SUCCESS             If initialization was successful.
     * @retval NRF_ERROR_INVALID_PARAM If the advertising configuration in \p p_init is invalid.
     * @return If functions from other modules return errors to this function, the @ref nrf_error are propagated.
     */
    uint32_t ble_advertising_init(ble_advertising_t            * const p_advertising,
                                  ble_advertising_init_t const * const p_init);
    

    - Andreas

  • I am using sdk13 with softdevice 4.0.2. So ble_advertising_init take more then 2 arguments.

    For the function sd_ble_gatts_characteristic_add() I use code:

    static uint32_t lenoba_char_add(ble_les_t * p_lenoba_service)
    {   
        uint32_t     		err_code;
    	ble_uuid_t     	    char_uuid;
    	ble_uuid128_t  	    base_uuid = BLE_UUID_LENOBA_BASE;
    	ble_gatts_attr_md_t cccd_md;
    	ble_gatts_char_md_t char_md;
        ble_gatts_attr_md_t attr_md;	
    	ble_gatts_attr_t    attr_char_value;
    
    	// Add a custom characteristic UUID
    	char_uuid.uuid  = BLE_UUID_LENOBA_CHAR_CMD;
    	err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
    	APP_ERROR_CHECK(err_code);
    	
        // Add read/write properties to our characteristic   
        memset(&char_md, 0, sizeof(char_md));
    	char_md.char_props.write 	= 1;
    	char_md.p_cccd_md           = &cccd_md;		
        
        // Configure the attribute metadata
        memset(&attr_md, 0, sizeof(attr_md));  
        attr_md.vloc = BLE_GATTS_VLOC_STACK;  
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
        
        // Configure the characteristic value attribute    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    	attr_char_value.p_uuid      = &char_uuid;
        attr_char_value.p_attr_md   = &attr_md; 
        attr_char_value.max_len     = 1;
    	attr_char_value.init_len    = 1;
    		
        // Add our new characteristic to the service
        err_code = sd_ble_gatts_characteristic_add(p_lenoba_service->service_handle,
    												&char_md,
    										        &attr_char_value,
    												&p_lenoba_service->char_handles_cmd);
    	APP_ERROR_CHECK(err_code);
    }

  • I changed char_md.p_cccd_md = NULL; and is now OK. 

Related