This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is GATT communication with multiple devices possible?

Hello.

I am developing using nrf52832 (S132 v7.0.1, SDK v17.0.0) as a peripheral device.

The question is, is it possible to GATT communicate with each of the multiple central devices while connected?
For example, if you are connected to two central devices and the characteristic is written from both devices, can you tell that it was sent from each device?

If you have any materials on how to manage the data when they are sent at the same time, please let me know.

Best regards.

  • Hello,

    When you receive a write event from a central, this event will contain a conn_handle (connection handle). A connection handle will stick to one connection for the entire connection span. So what you want to do is to store the connection handle when the central connects (that is the only event that contains the connection handle and the BLE address. Then you can look into the events connection handle to distinguish what central that wrote the data in your event.

    If you still struggle to find this connection handle, then let's look at the ble_app_uart as an example. Here you have the nus_data_handler() in main.c that is triggered whenever the central is writing to the RX characteristic. You can check the connection handle by looking at the p_ble_evt pointer:

    /**@brief Function for handling the data from the Nordic UART Service.
     *
     * @details This function will process the data received from the Nordic UART BLE Service and send
     *          it to the UART module.
     *
     * @param[in] p_evt       Nordic UART Service event.
     */
    /**@snippet [Handling the data received over BLE] */
    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint16_t conn_handle = p_evt->conn_handle;
            NRF_LOG_INFO("Received data from connection handle %d", conn_handle);
            ...

    Best regards,

    Edvin

Related