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!

Parents Reply Children
  • 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

  • Hello, thank you for the answer. 

    I am having trouble to built the array. In one hand, I have the conn_handle which is a hexadecimal value  that I need to put on the first line of the array and on the other hand, I have the MAC address of 6 bytes that I need to put on the second line of the array. 

    I tried to create my own type based on a char but I only print nonsense

    Hee is the code I tried:

    #define MAX_MAC_HANDLE_MAP_LENGTH 100
    typedef char addr;
    static addr mac_handle_map[2][MAX_MAC_HANDLE_MAP_LENGTH] = {"0"}; /**< Array of MAC address corresponding with connection handle
    with 20 devices max */

    static addr mac_addr_str[6], conn_handle_str[6];
    sprintf(mac_addr_str, "%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]
    );
    sprintf(conn_handle_str, "%x", p_scan_evt->params.connected.conn_handle);
    //NRF_LOG_INFO("%s\n\n\n", conn_handle_str);
    //NRF_LOG_INFO("%s\n\n\n", mac_addr_str);

    mac_handle_map[0][p_scan_evt->params.connected.conn_handle] = conn_handle_str;
    mac_handle_map[1][p_scan_evt->params.connected.conn_handle] = mac_addr_str;

    NRF_LOG_INFO("Handler %s with MAC address %s\n\n\n",
    mac_handle_map[0][p_scan_evt->params.connected.conn_handle],
    mac_handle_map[1][p_scan_evt->params.connected.conn_handle]);

Related