Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ATT_MTU throughput example: data received by responder?

Hello, I'm running the nRF5 SDK's ATT_MTU throughput example and I want to check that the data sent by the 'tester' (nRF52832 in my case) is effectively received by the 'responder' (nRF52840 in my case).

I can check the data sent by the tester but don't see where the data received by the responder can be found in the code.

Anyone that can help me, or tell what I need to do to find it? Thank you very much!

  • Hi

    Most likely there are no more than 3 buffers available in the Bluetooth stack, and when you try to send more the notify call will block. That said, it should send more packets eventually, once the packets in the buffers are sent over the air and the buffers clear up. 

    From where in the code are you trying to send the data?

    The notify call will block the execution when the buffers are full, and it is a good idea to set up a separate thread that can send data over Bluetooth without impacting the main thread.  

    Best regards
    Torbjørn

  • You're right, I didn't thought to clear the buffer. 

    About what you asked me

    From where in the code are you trying to send the data?

    is there:

    #define DATA_SIZE 1024   
    #define PACKET_SIZE (NRF_SDH_BLE_GATT_MAX_MTU_SIZE - 3)
    
    static void uart_send_data(uint8_t *data, uint16_t length)
    {
        uint32_t err_code;
    
        // Send data with NUS service
        while (length > 0)
        {
            uint16_t packet_length = (length > PACKET_SIZE) ? PACKET_SIZE : length;
            err_code = ble_nus_data_send(&m_nus, data, &packet_length, m_conn_handle);
            if (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_RESOURCES)
            {
                //Waiting for avaible resources
                while (ble_nus_data_send(&m_nus, NULL, &packet_length, m_conn_handle) == NRF_ERROR_RESOURCES)
                {
                    // Process logs to keep the system responsive
                    NRF_LOG_FLUSH();
                }
            }
            else
            {
                APP_ERROR_CHECK(err_code);
                NRF_LOG_INFO("Data sent: %d byte", packet_length);
                bsp_board_led_on(BSP_BOARD_LED_2);  
                bsp_board_led_off(BSP_BOARD_LED_2);
                data += packet_length;
                length -= packet_length;
                NRF_LOG_INFO("Data to send: %d byte", length);
            }
        }
    }
    

    And also, I add a case in the bsp_event_handler:

    case BSP_EVENT_KEY_1:
                
                for (uint32_t i = 0; i < DATA_SIZE; i++)
                {
                  data_to_send[i] = (uint8_t)(i % 244);
                }
                
                for(uint32_t i = 0; i < 243; i++)
                {
                   NRF_LOG_INFO("Byte %d: %d\n", i, data_to_send[i]);
                }
                uart_send_data(data_to_send, DATA_SIZE);
                break;

    Thanks

  • Could you advise me a thread about clearing up the buffer please?

  • Hi 

    I forgot you were using the nRF5 SDK, so please ignore my earlier comment regarding threads. 

    A couple of comments to your code: 

    1) I would not recommend calling uart_send_data from the BSP callback directly. You would be much better of either using the app_scheduler library to schedule this activity to be run from the main context, or by simply set a bool flag in the callback that you can later check in the main loop. 

    2) I would recommend implementing a better way to handle the NRF_ERROR_RESOURCES error code (which signals that the SoftDevice buffers are full). Rather than calling the function over and over in a loop you should wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event to occur, which signals that one or more of the buffers have freed up. 

    I discuss this in more detail here

    Best regards
    Torbjørn

  • Hi,

    Following this thread, I'm trying to understand:

    1) How the data sent is created?

    2) Can I managre data sent? In the sense that I want decide what the board is sending to the other device

    Thanks for the support, 

    Best regards. 

Related