How does the central distinguish between two devices that are already connected.

I now have two dk's, one as a master and the other as a slave. The slave sends data to the master, and the master forwards the data to the PC. That is, the piece of dk that works as the master is connected to two slave devices at the same time. Is there any way I can tell these two devices apart? Is there perhaps a function already written for use?

Parents
  • Hi Ell_pass, 

    You can use the bt_conn conn object to distinguish between two connections. 

    When a device connected to the central you will receive the connected callback and in the callback you can find the conn as the return argument. 
    Then when you receive BLE activity from a peripheral, you can check the  .conn in the nus_client struct in the callback. 

    Our coworker Matt has made a blog about Multi NUS here. He use conn_txt library to handle different connections but the principle is the same. 

  • Great starting point, but remember that disconnection on that example is not working properly, the bt_context maybe has a bug and it's reported in the issue openend on the branch.

    If you want a way to go out that, I implemented it using a simple array of "nus clients" when calling gatt_discover function.
    then, every element of the array, is a nus client.

    static struct bt_nus_client			  m_connNusClient[CONFIG_BT_MAX_CONN];		///< Nus client array.
    
    
    static void gatt_discover(struct bt_conn *conn)
    {
    	int err;
    
    	err = bt_gatt_dm_start(conn, BT_UUID_NUS_SERVICE, &m_discoveryCb, &m_connNusClient[bt_conn_index(conn)]);
    	if (err)
    	{
    		LOG_ERROR("could not start the discovery procedure, error code: %d\n", err);
    	}
    
    }

    Hope it will help you

Reply
  • Great starting point, but remember that disconnection on that example is not working properly, the bt_context maybe has a bug and it's reported in the issue openend on the branch.

    If you want a way to go out that, I implemented it using a simple array of "nus clients" when calling gatt_discover function.
    then, every element of the array, is a nus client.

    static struct bt_nus_client			  m_connNusClient[CONFIG_BT_MAX_CONN];		///< Nus client array.
    
    
    static void gatt_discover(struct bt_conn *conn)
    {
    	int err;
    
    	err = bt_gatt_dm_start(conn, BT_UUID_NUS_SERVICE, &m_discoveryCb, &m_connNusClient[bt_conn_index(conn)]);
    	if (err)
    	{
    		LOG_ERROR("could not start the discovery procedure, error code: %d\n", err);
    	}
    
    }

    Hope it will help you

Children
No Data
Related