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

ble_nus_string_send error codes

Hi all,

I'm sending data with ble_nus_string_send() in a loop as shown below. If it returns an error it retries until it gets NRF_SUCCESS. I'm getting an error code 0x0013. Does anyone know what this means or where in the documentation this is stated? Thanks.

			for (int i=0; i<11; i++)
			{
				err = ble_nus_string_send(&m_nus, testData, &testDataLength);
				while (err != NRF_SUCCESS)
				{
					errorCounter++;
					err = ble_nus_string_send(&m_nus, testData, &testDataLength);
					SEGGER_RTT_printf(0, "Error encountered: %04x\n", err);
				}
			}
  • You have all the source code of ble_nus module in the SDK so just traverse the source code down to SD function calls which have good explanation in header files including error codes returned (and some indication why). All NRF error codes are in SD header files like \components\softdevice\s132\headers\nrf_error.h etc.

  • Hi,

    If you are using SDK v14.x.0, and Softdevice s132 v5.0.0, you can find Global Error Codes documentation here.

    The error code 0x0013 (decimal 19) corresponds to NRF_ERROR_RESOURCES. In the source code of ble_nus_string_send(), you can see that the return value is either NRF_ERROR_INVALID_STATE. NRF_ERROR_INVALID_PARAM, or the return value from call to sd_ble_gatts_hvx().

    The documentation give the following reason for the error code:

    NRF_ERROR_RESOURCES Too many notifications queued. Wait for a BLE_GATTS_EVT_HVN_TX_COMPLETE event and retry.

    Best regards,

    Jørgen

  • Hi Jorgen,

    Yes SDK 14 and SD S132 v5.

    Thanks for the tip. I didn't know I had to comb through the source code to find this info...I thought it would be in the online docs somewhere.

    As for the error, is it best to wait for a TX COMPLETE event upon an error? Or is it acceptable to do what I'm doing now and keep calling the function until a NRF_SUCCESS is received? I presume the latter has some undesirable overhead. Or, should we do what the comments say in ble_gatts.h and keep a count of the tx_queue_size and only call ble_nus_string_send() when there is space?

    Thanks for the help. Cheers.

  • Just to add, I actually am already implementing the BLE_GATTS_EVT_HVN_TX_COMPLETE in my handler. I simply increment a counter to check that the number of packets I tried to send have sent regardless of errors. I do see the correct number the way I'm doing it now, but as I said, perhaps there is some unwanted overhead in calling the function so many times.

  • Thanks endnode. I did figure out that it was a resources error from the global error list...but I couldn't find out specifically why that was being returned in relation to the function. I now realize I have to delve into some of the source code to find that out. Thanks!

Related