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

nrf52-ble-app-uart-c-multilink-master with multiple ble_app_uart - bi-directional communication?

In a system based on one nrf52-ble-app-uart-c-multilink-master and multiple ble_app_uart, the data from any entity is sent to all devices.

i.e. each ble_app_uart is sending data to the master.

But any other device in the network that is connected to the master, is getting this data as well.

Is it possible to avoid it? since it is causing high traffic 

Top Replies

Parents Reply Children
  • "There is no such thing as broadcast in BLE" 

    But every byte that is sent from  nrf52-ble-app-uart-c-multilink-master, is sent to all connected devices?

    Isn't it?

  • In the master code, I found the echo part and will remove it.

    Probably this is the reason got all the data that each of the devices got what a single device transmitted 

    if (ECHOBACK_BLE_UART_DATA)
    {
    for(int c = 0; c < NRF_SDH_BLE_CENTRAL_LINK_COUNT; c++)
    {
    // Send data back to the peripheral.
    do
    {
    ret_val = ble_nus_c_string_send(&m_ble_nus_c[c], p_data, data_len);
    if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY) && (ret_val != NRF_ERROR_INVALID_STATE))
    {
    NRF_LOG_ERROR("Failed sending NUS message. Error 0x%x. ", ret_val);
    APP_ERROR_CHECK(ret_val);
    }
    } while (ret_val == NRF_ERROR_BUSY);
    }
    }

  • As I said, if that is happening, then it must be the application code that's doing it - it is not an inherent BLE thing.

    nrf52-ble-app-uart-c-multilink-master

    You mean this: https://github.com/NordicPlayground/nrf52-ble-app-uart-c-multilink/blob/master/main.c ?

    It looks like the repeated sending is happening here:

    /**@brief Function for handling characters received by the Nordic UART Service (NUS).
     *
     * @details This function takes a list of characters of length data_len and prints the characters out on UART.
     *          If @ref ECHOBACK_BLE_UART_DATA is set, the data is sent back to sender.
     */
    static void ble_nus_chars_received_uart_print(uint8_t * p_data, uint16_t data_len)
    {
        ret_code_t ret_val;
    
        NRF_LOG_DEBUG("Receiving data.");
        NRF_LOG_HEXDUMP_DEBUG(p_data, data_len);
    
        for (uint32_t i = 0; i < data_len; i++)
        {
            do
            {
                ret_val = app_uart_put(p_data[i]);
                if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR("app_uart_put failed for index 0x%04x.", i);
                    APP_ERROR_CHECK(ret_val);
                }
            } while (ret_val == NRF_ERROR_BUSY);
        }
        if (p_data[data_len-1] == '\r')
        {
            while (app_uart_put('\n') == NRF_ERROR_BUSY);
        }
        if (ECHOBACK_BLE_UART_DATA)
        {
            for(int c = 0; c < NRF_SDH_BLE_CENTRAL_LINK_COUNT; c++)
            {
                // Send data back to the peripheral.
                do
                {
                    ret_val = ble_nus_c_string_send(&m_ble_nus_c[c], p_data, data_len);
                    if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY) && (ret_val != NRF_ERROR_INVALID_STATE))
                    {
                        NRF_LOG_ERROR("Failed sending NUS message. Error 0x%x. ", ret_val);
                        APP_ERROR_CHECK(ret_val);
                    }
                } while (ret_val == NRF_ERROR_BUSY);
            }
        }
    }

    specifically:

        if (ECHOBACK_BLE_UART_DATA)
        {
            for(int c = 0; c < NRF_SDH_BLE_CENTRAL_LINK_COUNT; c++)
            {
                // Send data back to the peripheral.
                do
                {
                    ret_val = ble_nus_c_string_send(&m_ble_nus_c[c], p_data, data_len);
                    if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY) && (ret_val != NRF_ERROR_INVALID_STATE))
                    {
                        NRF_LOG_ERROR("Failed sending NUS message. Error 0x%x. ", ret_val);
                        APP_ERROR_CHECK(ret_val);
                    }
                } while (ret_val == NRF_ERROR_BUSY);
            }
        }
    

    So, if that's not the behaviour you want, change that code to do whatever you do want.

Related