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

ERROR_INVALID_PARAM error while trying to add characteristics

Hi I have this piece of code which works in SDK 12 but when I port it to SDK 15 the sd_ble_gatts_characteristic_add function would fail with an error code of 7. No change seems to be working. Any help is appreciated,.

uint32_t                    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          		char_uuid;
	ble_gatts_attr_md_t 		attr_md;

	NRF_LOG_INFO("Resetting Characteristics security\r\n")
	memset(&cccd_md, 0, sizeof(ble_gatts_char_md_t));

	cccd_md.vloc = BLE_GATTS_VLOC_STACK;
	/*
	 * The access must be open for both read and write for
	 * the Client Characteristic Configuration descriptor
	 */
	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

	NRF_LOG_INFO("Resetting Characteristics\r\n")
	memset(&char_md, 0, sizeof(ble_gatts_char_md_t));

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

	char_uuid.uuid = UUID_CHAR_0_0;
	char_uuid.type = p_service->uuid_type;

	NRF_LOG_INFO("Resetting Attribute\r\n")
	memset(&attr_md, 0, sizeof(ble_gatts_attr_md_t));

	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_USER;

	NRF_LOG_INFO("Resetting value\r\n")
	memset(&attr_char_value, 0, sizeof(ble_gatts_attr_t));

	attr_char_value.p_uuid    = &char_uuid;
	attr_char_value.p_attr_md = &attr_md;
	attr_char_value.init_len  = MAX_CHANNELS * SAMPLES_IN_BUFFER;
	attr_char_value.init_offs = 0;
	attr_char_value.max_len   = MAX_CHANNELS * SAMPLES_IN_BUFFER;
	attr_char_value.p_value   = m_char_buf;

	NRF_LOG_INFO("Adding new characteristics\r\n")
	err_code = sd_ble_gatts_characteristic_add(p_service->service_handle,
											   &char_md,
											   &attr_char_value,
											   &p_service->char_handles);
	APP_ERROR_CHECK(err_code);
	NRF_LOG_INFO("Added new characteristics\r\n");

Parents Reply Children
  • Hi msromero

    Thanks for your response. To avoid the complexity of upgrades I changed the code to the one below. This I got from ble_hrs.c and works fine but in my project produces the exact same error. I can send you the project but cannot upload the project in public domain. So is there a way to upload the project?

    uint32_t              	err_code;
    ble_add_char_params_t 	add_char_params;
    uint8_t 				buf[NRF_SDH_BLE_GATT_MAX_MTU_SIZE];
    
    NRF_LOG_INFO("Adding Characteristics\r\n");
    memset(&add_char_params, 0, sizeof(add_char_params));
    memset(buf, 0, NRF_SDH_BLE_GATT_MAX_MTU_SIZE);
    
    add_char_params.uuid              	= UUID_CHAR_0_0;
    add_char_params.max_len           	= NRF_SDH_BLE_GATT_MAX_MTU_SIZE;
    add_char_params.init_len          	= MAX_CHANNELS * SAMPLES_IN_BUFFER;
    add_char_params.p_init_value      	= buf;
    add_char_params.is_var_len        	= true;
    add_char_params.char_props.notify 	= 1;
    add_char_params.cccd_write_access 	= SEC_OPEN;
    add_char_params.read_access			= SEC_OPEN;
    add_char_params.write_access		= SEC_OPEN;
    
    err_code = characteristic_add(p_service->service_handle, &add_char_params, &(p_service->char_handles));
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Added Characteristics\r\n");

  • Hi msromero

    Very sorry for the confusion. Finally figured out the issue. I was calling the add characteristics function after the ble_dis_init. So softdevice was trying to add the characteristics to DIS. Moved the call before that and works like a charm. Sorry for the stupidity. Please close the issue if it is needed and thanks as always.

  • Hi Ranajyoti,

    Nice to hear that the problem is fixed. And don't worry, we are here to help Slight smile

    Ranajyoti Chakraborti said:
    I can send you the project but cannot upload the project in public domain. So is there a way to upload the project?

    If you have any more questions and want to upload a project some other time so we can review it and give you guidance you can do that by marking a question as a "private support ticket".

    Happy to help and hope you have a nice day.

    Best Regards,

    Marjeris

Related