BLE data loss with nus

Hi,

(nrf52840, custom device, nRF5_SDK_15.3.0_59ac345)

I am working on a BLE project involving one central device and two peripheral devices using BLE NUS. The peripheral devices send data with a maximum size of 230 bytes each time a sensor interrupt occurs, which sometimes results in them sending data simultaneously.

I've observed occasional data loss at the central device, even though the peripherals seem to send data without errors.

For debugging, I'm using a UART driver for logging and not using any UART-related code from NUS. Data loss seems to occur when I enable sensor raw data logging within a loop of the data size. Initially, I thought the logs might just be too extensive for one event and therefore not appearing. However, a review of the data count indicated that the BLE RX handler wasn't receiving any data.

Interestingly, when I disabled the raw data logs, the data loss didn't occur. I attempted to address the issue by increasing the UART RX buffer, FIFO size, and baud rate, but the data loss persisted.

My guess is that the data loss may not be caused by the UART itself, but by the processing time required for the UART operations. I also experimented with various connection intervals, which sometimes improved but also worsened the issue, though data loss still occurred.

Is it possible for data loss to happen when two data packets arrive simultaneously at the central device? Do you have any suggestions on how to resolve this issue?

Thank you in advance

Parents
  • Hi,

    I think the data loss must occur somewhere between receiving the sensor measurement value and the BLE send function (assuming the send function always returns with NRF_SUCCESS). Data that is successfully added to the SoftDevice output queue will be sent to the receiver. If the packet fails to be sent after x retransmissions,  the Softdevice will terminate the link as required by the specification.   

    I've observed occasional data loss at the central device, even though the peripherals seem to send data without errors.

    A notification or indication packet added to the output queue with  sd_ble_gatts_hvx() will be added to the output queue if the return value is NRF_SUCCESS. Does your application verify the return code of this function to detect when a packet failed to be added to the queue?  

    Is it possible for data loss to happen when two data packets arrive simultaneously at the central device?

    This should not happen, and I do not recall seeing any reports of this being a problem. 

    Best regards,

    Vidar

  • Hi Vidar,

    Thanks for the reply! It was a great clue to help me start debugging.

    I’ve checked the BLE data transmission (TX) and reception (RX) on both the peripherals and the central device, and they are working perfectly.

    I discovered a race condition in our custom code during BLE data processing, which occurs when the central receives multiple data packets from the peripherals. I’ve fixed the issue.

    Thank you again!

Reply
  • Hi Vidar,

    Thanks for the reply! It was a great clue to help me start debugging.

    I’ve checked the BLE data transmission (TX) and reception (RX) on both the peripherals and the central device, and they are working perfectly.

    I discovered a race condition in our custom code during BLE data processing, which occurs when the central receives multiple data packets from the peripherals. I’ve fixed the issue.

    Thank you again!

Children
No Data
Related