Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sd_ble_gatts_hvx and NRF_ERROR_SVC_HANDLER_MISSING

Hello.

   I try to periodically updated data in my characteristic that way:

uint32_t ble_first_service_send(uint16_t my_conn_handle, ble_my_service_t * p_my_service, ble_my_service_meas_t * p_my_service_meas)     
{
	uint8_t err_code;
  
	if(m_conn_handle != BLE_CONN_HANDLE_INVALID)		
	{	
		uint8_t             		encoded_sensor[MAX_SENSOR_LEN];		
		uint16_t               	len;
		ble_gatts_hvx_params_t 	hvx_params;

		NRF_LOG_INFO("CONNECTION OK");
		
		len = my_service_measurement_encode(p_my_service, p_my_service_meas, encoded_sensor); 

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

		hvx_params.handle = p_my_service->first_char_handles.value_handle;
		hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
		hvx_params.p_len  = &len;
		hvx_params.p_data = encoded_sensor;					

		err_code = sd_ble_gatts_hvx(m_conn_handle, &hvx_params);
	}
	else
	{
		err_code = NRF_ERROR_INVALID_STATE;
	}
	return err_code;
}

As soon as I connected via "nRF Connect", function "sd_ble_gatts_hvx" returns: NRF_ERROR_SVC_HANDLER_MISSING.

The window looks like:

If I open the window:

functions "sd_ble_gatts_hvx" returns NRF_ERROR_INVALID_STATE, which without enabled notification is correct value. Does anyone know, what happen in app when I open this window?

Why functions returns NRF_ERROR_SVC_HANDLER_MISSING ?

Characteristic add function:

static uint32_t my_first_char_add(ble_my_service_t * p_my_service, const ble_my_service_init_t * p_my_service_init)
{
	ble_gatts_char_md_t 		char_md;				
	ble_gatts_attr_md_t 		cccd_md;				
	ble_gatts_attr_t    		attr_char_value;		
	ble_gatts_attr_md_t 		attr_md;				
	ble_uuid_t          		ble_uuid;
	ble_my_service_meas_t      	initial_bpm;
	uint8_t             		encoded_sensor[MAX_SENSOR_LEN];

	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_my_service->uuid_type;
	ble_uuid.uuid = BLE_UUID_MY_SERVICE_CHAR_1;																
		
	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  = my_service_measurement_encode(p_my_service, &initial_bpm, encoded_sensor);
	attr_char_value.init_offs = 0;
	attr_char_value.max_len   = MAX_SENSOR_LEN;
	attr_char_value.p_value   = fake_data0;

  return sd_ble_gatts_characteristic_add(p_my_service->service_handle, &char_md, &attr_char_value, &p_my_service->first_char_handles);
}

Best regards

PW

  • FormerMember
    0 FormerMember

    The application wants to send data using ble_first_service_send() no matter the connection state. After the device is connected, the central has to enable notifications before the peripheral can send notifications (sd_ble_gatts_hvx). If not, the error NRF_ERROR_SVC_HANDLER_MISSING is returned.

    When using the central to enable notifications, the error disappears. 

    To understand the concept of notifications, I would recommend you to look at part 1 of this video tutorial.

Related