This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is bt_nus_send blocking?

I am using bt_nus_send to send data via BLE every 1ms. I've noticed that when connection is bad, this function takes a couple of milliseconds to execute, while when connection is good it is only ~100us.

I am not sure if this function is blocking until it sends the data, or it puts the data into some buffer (I see that at some point net_buf_put is called) end exits. Why do I get different execution times?

  • Hello,

    No, the function is not blocking. The function actually only queues data in the SoftDevice controller's FIFO for transmission in the next connection event. The connection events occur every time the connection interval has occurred, which is configured as part of your connection parameters.
    The lowest possible connection interval in BLE is 7.5 ms, so even though you queue data for transfer every 1 ms, it will not actually be sent until the next connection event.

    The fluctuations in transmission time from bt_nus_send call to received packet is likely due to some packets being scheduled immediately before an upcoming, or immediately after one.
    In the case of a packet loss due to a poor connection the device will re-transmit the failed packet until it is successful or the connection is terminated. Thus, you will see a delay between your scheduling of a packet to its arrival whenever a packet is lost or corrupted.

    Best regards,
    Karl

Related