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

Best way to send larger chunks of data through BLE UART?

Right now i have based myself on the BLE UART example where it is UART over BLE.

So naturally I use ble_nus_string_send to send data. After some digging I saw that this takes max 20 bytes of data. Also there seems to be a fixed queue size, so anything after a filled queue will be disregarded with an error returned from this function. The qeue size by the looks of it is 6, right?

So, how do I send bigger chunks (all the data is one big chunk which is treated as one entity)? First I tried to just retry if ble_nus_string_send returned an error with a nrf_delay_ms(20) in a loop with 100 retries. It does work, but it can't be an elegant solution. Also on the 2nd chunk of data sent over, it seems to struggle a lot more when sent over. It comes in small portions of 3 chunks over time. I am testing on android with the NRF UART app.

Thanks!

  • On my application, I organize my data in a way that it has a structured way in each 20 bytes chunk. Then, I have a state machine, which just en-queue packets until the buffer is full. After that it just keeps retrying until all my data is sent.

    Is something like this:

    -> Init (send a "data init" packet)
    -> Data loop (keep sending data until the end)
    -> End (send a "data end" packet)

    On the receiving side, I receive everything in order, and just have to reorganize it and parse.

  • You can initialize the FIFO with bigger buffer. Sending is not limited to 20 bytes. The softdevice takes care breaking it down. On the other, on iOS, I get full packet. Don't know about Android though.

  • @Emil: You can do what you are doing, try to queue the notification packets as long as the buffer is not full, and try again after you receive BLE_EVT_TX_COMPLETE event (meaning there are packet sent in the last connection event).

    Or you can declare your characteristics with bigger size than 20byte (max 510 bytes) and let the central to use long read to retreive the value. I don't think notification is supported to send long characteristic.

  • Cool! How is the buffer adjusted?

  • Thanks! How do I know when the queue buffer is full before sending? And is it hard to change the BLE UART to a pure GATT server?

1 2 3