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

Peripheral sends data to Central, want Central to send recieved data to another peripheral over BLE

Hi, I am trying to send data from one peripheral to a central unit and then relay the message to another peripheral unit over BLE. The peripheral already sends the data to the central unit and its processed in the central unit. However, I want to send to a specific peripheral using its conn_handle, is this possible? On the peripheral unit we use a function called ble_nus_data_send() which does exactly this, is there a similar function for the ble_nus_c?

  • Hello,

    By default, the ble_nus_c example only supports one connection, but I will assume you have modified it to support multiple connections, based on the way that you formulated your question.

    The equivalent to ble_nus_data_send() (peripheral) in the ble_app_uart_c example is the ble_nus_c_string_send(), which is implemented in ble_nus_c.c.

    The fact that this is not intended for several connections is shown in that implementation, but you can see that it fetches the conn_handle from p_ble_nus_c, which is an input parameter. 

    I also see that the later SDKs have replaced the sd_ble_gattc_write() with nrf_ble_gq_item_add(). I would recommend changing that back, if you are using one of the later SDKs. Look at the implementation from SDK15.0.0, and check if this uses sd_ble_gattc_write().

    Based on how you have made the application support more connections, you can either take the conn_handle as an extra input parameter in ble_nus_c_string_send(), or fetch the connection handle from p_ble_nus_c, which is an input parameter, but I am not sure what it looks like in your case, if you have changed this to fit more connections. Let me know.

    Best regards,

    Edvin

  • We added support for multiple connections by creating BLE_NUS_C_ARRAY_DEF(m_ble_nus_c, NRF_SDH_BLE_CENTRAL_LINK_COUNT); and increasing the link count in the config file.

    I don't understand how to add an extra input parameter in ble_nus_c_string_send(), I get an error because there are too many parameters. 

    Best regards,

    Sondre

  • You need to modify the function inputs. Do it in the ble_nus_c.c file and in the ble_nus_c.h file.

    uint32_t ble_nus_c_string_send(ble_nus_c_t * p_ble_nus_c, uint8_t * p_string, uint16_t length, uint16_t my_extra_input_variable)
    {
        ...
        return nrf_ble_gq_item_add(p_ble_nus_c->p_gatt_queue, &write_req, my_extra_input_variable);
    }

Related