Multilink Central/Peripherals ID

Hello everyone,

I am working with the SDK v17.1.0 with the DK nRF52832 with the examples of ble_app_uart and ble_app_uart_c.

I want to have several peripheral boards that send data to a central board.

But I also want to have control over the slave I am questionning, so I want each slave to have its own ID. 

First I looked on 

Thank you everyone!

  • Hello,

    Each peripheral gets assigned a connection handle on connection, and it's then up to the application to keep track of which peripheral each handle belongs to. One way to do this is to map the connection handle to the peripheral's BLE address in the NRF_BLE_SCAN_EVT_CONNECTED event.

    Best regards,

    Vidar

  • Hello, thank you for your answer. 

    Yes, I could put an ID for each handle, but these ID will not represent the slave physically. 

    What I mean is that if Slave 1 is connected, I will attribute the ID 0 and then, Slave 2 will have the ID 1. If I restart the experiment, if Slave 2 is connected first, it wil have the ID 0 and not 1. Same goes with Slave 1. 

    Do you have an idea to identify every slave? 

    Thank you

  • Hello,

    The connection handle ID will only remain valid while connected like you say, but the BLE address you retreive from the NRF_BLE_SCAN_EVT_CONNECTED event will stay the same for a given peripheral (assuming the default static address type is used). So the idea was to map the connection handle to the device address every time a new connection is established.

  • Hello, 

    Indeed, I saw that I can retrieve the MAC address of each peripheral (Which should be unique for each peripherals) as printed in the NRF_BLE_SCAN_EVT_CONNECTED in the ble_app_uart_c.

    For the mapping, I was thinking about creating an 2D array and correspond each column to one handle and a MAC address. 

    However, I am not sure how to retrieve the handler ID as handle ID seems to be defined during a gap event and I am in a scan event. I don't quite understand how the of the handles are managed. 

    Thank you very much! 

  • Hello,

    Yes, an array should be fine. Here is how you can retrieve the connection handle from the NRF_BLE_SCAN_EVT_CONNECTED event:

             case NRF_BLE_SCAN_EVT_CONNECTED:
             {
                  ble_gap_evt_connected_t const * p_connected =
                                   p_scan_evt->params.connected.p_connected;
                  
                 NRF_LOG_INFO("Connection handle 0x%x",
                              p_scan_evt->params.connected.conn_handle);
    
                 // Scan is automatically stopped by the connection.
                 NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x",
                          p_connected->peer_addr.addr[0],
                          p_connected->peer_addr.addr[1],
                          p_connected->peer_addr.addr[2],
                          p_connected->peer_addr.addr[3],
                          p_connected->peer_addr.addr[4],
                          p_connected->peer_addr.addr[5]
                          );
             } break;

    Also, remember to update the array when you get disconnected (BLE_GAP_EVT_DISCONNECTED) from a peripheral.

    Best regards,

    Vidar

Related