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

sd_ble_gatts_hvx() returns NRF_ERROR_INVALID_STATE (error code 8)

Hi

Try to send characteristic notification by invoking sd_ble_gatts_hvx() with the following parameters:

	uint32_t err_code = NRF_SUCCESS;
	ble_gatts_hvx_params_t params;

	memset(&params, 0, sizeof(params));
	params.type = BLE_GATT_HVX_NOTIFICATION;
	params.handle = GetValueHandle();
	params.p_data = pData;
	params.offset = 0;
	params.p_len = &length;

	if (srv::ble::ConnectionHandleInvalid != mrBleInterface.GetConnectionHandle())
	{
		err_code = sd_ble_gatts_hvx(mrBleInterface.GetConnectionHandle(), &params);
		assert(err_code == NRF_SUCCESS);
	}

Unfortunately, the error code 8 NRF_ERROR_INVALID_STATE occurs. The connection is established and bonding is completed. ( checked by the DM_EVT_LINK_SECURED event from the device manager)

Do you have any suggestion what "invalid state" coulde be?

Thanks for your help.

BR Armin

Parents
  • The most likely scenario is that the CCCD has not been enabled by the peer device. This has to be enabled before you are able to transmit notification/indications. The peer would have to subscribe to the characteristic to get notifications from it.

    Another reason is if you receive an invalid connection handle from mrBleInterface.GetConnectionHandle()

  • I enable notification on 7 characteristics on central and I get event BLE_GATTC_EVT_WRITE_RSP for each characteristic. When I get this event I will set my own flag and then I send another flag by sd_ble_gattc_write. I get error 0x3401 when I don't set sd_ble_gatts_sys_attr_set and use sd_ble_gatts_hvx on peripheral device. I have this error NRF_ERROR_INVALID_STATE too after I set err_code = sd_ble_gatts_sys_attr_set(m_conn_handle,NULL,0);

Reply
  • I enable notification on 7 characteristics on central and I get event BLE_GATTC_EVT_WRITE_RSP for each characteristic. When I get this event I will set my own flag and then I send another flag by sd_ble_gattc_write. I get error 0x3401 when I don't set sd_ble_gatts_sys_attr_set and use sd_ble_gatts_hvx on peripheral device. I have this error NRF_ERROR_INVALID_STATE too after I set err_code = sd_ble_gatts_sys_attr_set(m_conn_handle,NULL,0);

Children
No Data
Related