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!

Parents Reply
  • Hoan Hoang,

    Sending is limited to 20 bytes. If you look at the implementation of ble_nus_string_send() in ble_nus.c (nRF5_SDK_11.0.0_89a8197), if the length is >20, it returns error.

    uint32_t ble_nus_string_send(ble_nus_t * p_nus, uint8_t * p_string, uint16_t length)
    

    { ble_gatts_hvx_params_t hvx_params;

    VERIFY_PARAM_NOT_NULL(p_nus);
    
    if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
    {
        return NRF_ERROR_INVALID_STATE;
    }
    
    if (length > BLE_NUS_MAX_DATA_LEN)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    

    ...

Children
No Data
Related