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

Error invalid parameter on charateristic add

Hello !

I'm struggling with my Bluetooth configuration on the NRF52832. I'm running with the latest SDK (14) and the S132 SoftDevice.

When I'm trying to add a characteristic to my service, I'm getting an error 7 (Invalid parameter), but can't tell which one. This is my code for the characteristic.

ble_gatts_char_md_t char_md;
ble_gatts_attr_t    attr_char_value;
ble_uuid_t          ble_uuid;
ble_gatts_attr_md_t attr_md;
ble_gatts_attr_md_t cccd_md;
uint32_t err_code;

ble_uuid.uuid = uuid;
ble_uuid.type = uuid_type;

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

memset(&attr_md, 0, sizeof(attr_md));
attr_md.vloc       = BLE_GATTS_VLOC_STACK;

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

attr_char_value.p_uuid       = &ble_uuid;
attr_char_value.p_attr_md    = &attr_md;

//ble_gatts_char_handles_t handle;
m_char_handles = new ble_gatts_char_handles_t[1];
err_code = sd_ble_gatts_characteristic_add(m_handle,
	&char_md,
	&attr_char_value,
	m_char_handles);
APP_ERROR_CHECK(err_code);

Here UUID is defined as :

#define BTRY_UUID_CHAR 0x1215

And the uuid_type comes from this code :

uint8_t ble_driver::add_uuid(ble_uuid128_t uuid)
{
    	uint32_t err_code;
    	uint8_t uuid_type;
    	err_code = sd_ble_uuid_vs_add(&uuid, &uuid_type);
    	APP_ERROR_CHECK(err_code);
    	return uuid_type;
}

The last parameter, m_handle, come from here :

uint32_t   err_code;
ble_uuid_t ble_uuid;

// Add service.

ble_uuid.type = uuid_type;
ble_uuid.uuid = service->get_uuid_service();

err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, service->get_handle());
VERIFY_SUCCESS(err_code);

Where the function get_handle() is a pointer to the m_handle from above.

I really don't know why my code doesn't work. I know it was correct on the SDK 12 but wanted to update it. Thx for the future help.

Related