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()

  • Hi Tried to catch the BLE_GATTS_EVT_HVC event when the android sends the BluetoothGatt: writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb belonging to the charactersitic.

    I suppose the BLE_GATTS_EVT_HVC is sent by the registered callback of softdevice_ble_evt_handler_set(). I lookup in the "ble_event*" p_ble_evt->header.evt_id but did not receive anything, although android confirmed the proper execution..

    Any idea about the problem? Thanks, Armin

Reply
  • Hi Tried to catch the BLE_GATTS_EVT_HVC event when the android sends the BluetoothGatt: writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb belonging to the charactersitic.

    I suppose the BLE_GATTS_EVT_HVC is sent by the registered callback of softdevice_ble_evt_handler_set(). I lookup in the "ble_event*" p_ble_evt->header.evt_id but did not receive anything, although android confirmed the proper execution..

    Any idea about the problem? Thanks, Armin

Children
No Data
Related