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

Identification of peripheral devices connected to central

Hello Everyone. 

                       I am a newbie in NRF52840 development. I have one NRF52840 device as a central device and many peripherals are getting connected to it (Max 6). Lets say 6 peripherals are connected to one central. I am not understanding how to identify the different peripheral devices on central side. There is p_gap_evt->conn_handle and &p_gap_evt->params.adv_report.peer_addr but I am not understanding how to use this to identify events from different peripherals??? Can anyone please help me on this? 

  • If i get a connection from BLE_GAP_EVT_CONNECTED and later I get data from a particular event in a different handle,then how to identify device. At that time i wont be having the same conn_handle I guess.?? My problem is I am getting event in a different handle and inside that I want to identify from which device i got the data.

  • sne_333 said:
    If i get a connection from BLE_GAP_EVT_CONNECTED and later I get data from a particular event in a different handle,then how to identify device

    You always get a connect handle with every event. You do not get all information with every event, though. So if you for instance need to map conn_handle to address later, you need to keep track of that.

    sne_333 said:
    At that time i wont be having the same conn_handle I guess.

    The conn handle is valid for the duration of the connection. And when the connection is established again, you know the address.

    Note that if the peer is a phone or something that use privacy, then you cannot map addresses over time, as it changes regularly. In that case, you will need to bond with the device in order to recognize it (using the IRK. This is handled for you by the peer manager library in that case, though.,

    sne_333 said:
    My problem is I am getting event in a different handle and inside that I want to identify from which device i got the data.

    That is exactly why all connection related events have the conn_handle. That is what you should use here.

  • Thank you so much...

    Ok so if I use "ble_evt_t const *p_ble_evt;" and "p_gap_evt->conn_handle" on other event handler, I will get the same handle number as well as the peer address right?

  • You only get the peer address on the connected event. But then you can store a map of conn_handle and address yourself if you need to keep that mapping later.

Related