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

  • For the first part on how to differentiate between writes: devzone.nordicsemi.com/.../

    For the second part: This explains how the flow control is different for notifications and indications. For notifications you can send as many as you have TX buffers available, for indications you can only send a new one once the peer have acknowledged the last one you sent and that you receive the BLE_GATTS_EVT_HVC instead of a BLE_EVT_TX_COMPLETE

  • I have a similar issue as this. Using the Master Control Panel application on my Android device to connect to my nRF51822 module (acting as the GATT server), I have implemented the Device Manager onto my BLE module and am able to bond the phone and device. I then set notifications enabled onto my custom service through the phone, and start sending notifications from my module by pressing a key on my keyboard (UART communication). This works fine but once I disconnect with the phone and try to reconnect, it shows on the Master Control Panel that notifications are still enabled and that I don't have to write and set the CCCD value of the same characteristic value I was notifying before disconnection. However when I start sending notifications, it is displayed on my terminal that I am getting the NRF_ERROR_INVALID_STATE event. If the device manager is suppose to manage bonds, how come the CCCD value is set back to 0 on my module?

  • Have you tried reading the CCCD value manually from the control panel? If you disconnect and connect it does not automatically read back all the values again. If you call the sd_ble_gatts_sys_attr_set, then you need to provide the values you received from the sd_ble_gatts_sys_attr_get when disconnecting.

  • 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);

Related