Hey there!
I´m developing an small wearable sensor based on the NRF52840 (SDK 15.0.0, S140 6.0.0) on a custom board. The sensor will log data on an external NAND flash and the data shall be read out later with an Android App.
To maximize throughput I´m sending notifications using sd_ble_gatts_hvx(). However after only a few calls I receive the error code 0x13 which should relate to NRF_ERROR_TIMEOUT from what I got out of the documentation.
/*... * @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection. */ SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const *p_hvx_params));
Why does this error occur and how should it be handled?
For sending ble packets I´m using a code snipped from the ble_uart_example and the Nordic NUS service for now:
do { err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle); if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) && (err_code != NRF_ERROR_NOT_FOUND) ) { APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_BUSY);
Using this snipped I receive a "Fatal error" after a bunch of packages sent.
I played around a little bit and tried to just ignore the error similar to the NRF_ERROR_BUSY and retry sending the package:
do { err_code = ble_serial_send(data, length); if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) && (err_code != NRF_ERROR_NOT_FOUND) && (err_code != NRF_ERROR_TIMEOUT)) { APP_ERROR_CHECK(err_code); } } while (err_code);
Using the following connection parameters and a Samsung Galaxy S8 I´m able to achive a quite decent throughput of around 85 kByte/s:
// from sdk_config.h #define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247 #define NRF_SDH_BLE_GAP_DATA_LENGTH 251 #define NRF_SDH_BLE_GAP_EVENT_LENGTH 400 // in main.c #define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */ #define SLAVE_LATENCY 0 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
sd_ble_gatts_hvx() will sometimes return with error code 0x13 but for now I just ignored this as described above. So far everything is running somewhat fine.
However the whole transmission is very "unstable". Sometimes after just some seconds, sometimes after some minutes or sometimes only after an hour the call of sd_ble_gatts_hvx() will return every time with error 0x13 and sending of any more data is not possible anymore.
My question now is how to handle this error and make the sending of data stable? Why does this "GATT procedure timeout" happen at all? I´m not sure how to handle this error.
I´m really stuck with this problem for more than 2 weeks now. I would be happy for every tipp or support to point me in the right direction here.
Thank you!