Send long packets for Android using low MTU sizes

Hi,

In a ble_app_uart example I have problems to send long packets if the Android smartphone only accepts MTU sizes of 20 bytes. I'm using the nRF5_SDK_17.1.0, the S132 over the SES IDE and the nR52-DK board.

The application adjusts the MTU size to the value negotiated by the smartphone and it's set to 20 bytes. However, when I send longer packets the smartphone only receives a part. It looks like the device only send one packet and doesn't manages automatically the division of the full packet for sendidn it in different subpackets.

How could I setup the Softdevice so it could automatically manages this sending of a long packet in subpackets? Excuse me if there is other similar case about this, but I have not been able to find it.

Thank you in advance.

Regards,

Joel

Parents
  • Hi,

    You can see how the ble_app_uart example handles this here:

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ((data_array[index - 1] == '\n') ||
                    (data_array[index - 1] == '\r') ||
                    (index >= m_ble_nus_max_data_len))
                {
                    if (index > 1)
                    {
                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                        do
                        {
                            uint16_t length = (uint16_t)index;
                            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_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_RESOURCES);
                    }
    
                    index = 0;
                }
                break;

    if the phone does only support 20 bytes MTU, then 

    m_ble_nus_max_data_len is 20, and the data you try to send will be split into chunks, where each chunk is max 20 bytes.
Reply
  • Hi,

    You can see how the ble_app_uart example handles this here:

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ((data_array[index - 1] == '\n') ||
                    (data_array[index - 1] == '\r') ||
                    (index >= m_ble_nus_max_data_len))
                {
                    if (index > 1)
                    {
                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                        do
                        {
                            uint16_t length = (uint16_t)index;
                            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_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_RESOURCES);
                    }
    
                    index = 0;
                }
                break;

    if the phone does only support 20 bytes MTU, then 

    m_ble_nus_max_data_len is 20, and the data you try to send will be split into chunks, where each chunk is max 20 bytes.
Children
No Data
Related