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

sending data to a particular peripheral in multi connection in central

hai ,

  i am connecting 5 peripherals in one central (used ble_central example modified like multilink central)

i referred this link for sending particular data...

https://devzone.nordicsemi.com/f/nordic-q-a/47745/multi-link-central-uart-with-multiple-peripheral/190997#190997

i can able to get connection handle for each link count ,i need to match a mac id of the device and connection handle

now my question is ,

how to send data to particular peripheral and where to choose the connection handle and mac id to send data ??

if you have any sample code on this kindly share the code

regards,

Sowmiya

  • Hi,

    Peer address can be found in connection event data passed along with BLE_GAP_EVT_CONNECTED event. You can create a map that will store connection handle and corresponding peer address for each connection.

    if (evt->header.evt_id == BLE_GAP_EVT_CONNECTED) {
        uint16_t handle = evt->evt.gap_evt.conn_handle;
        uint8_t *addr = evt->evt.gap_evt.params.connected.peer_addr.addr;
        // add handle:addr pair to the map
    }

  • yes ,thank you ..i can able to get evt->evt.gap_evt.conn_handle and evt->evt.gap_evt.params.connected.peer_addr.addr

     for every connection.

    but in my application after 5 connections of peripheral to one central , i will send data along with anyone of the connected peripheral peer address that time,

     1.how can i choose in central to send data to a particular peripheral  ??

     2 .how can i map the peer address with that id ??

    for (uint32_t i = 0; i< NRF_SDH_BLE_CENTRAL_LINK_COUNT; i++)
    {
    err_code = ble_lbs_led_status_send(&m_lbs_c[i], 0);
    if (err_code != NRF_SUCCESS &&
    err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
    err_code != NRF_ERROR_INVALID_STATE)
    {
    return err_code;
    }

    if i used like above function , its sending data to all peripherals , here how can i differentiate the one peripheral and that connection id???

  • ble_lbs_c_t structure has conn_handle field, you can call ble_lbs_led_status_send() only in case m_lbs_c[i].conn_handle matches the handle for required peer address in your map.

  • yes found that but  to passing a conn_handle for only particular peripheral ,

    i m strucked at the place of mapping in c code  when connected ?? 

    if u have any code based on this mapping kindly share the code ..it would be grateful for me

    regards,

    sowmiya

  • If you're asking about an implementation of mapping algorithm - sorry, I don't have a ready solution, but it's quite simple: an array of structures containing two fields (handle and address), and a function that walks through this array, comparing each address with that you want to send data to, and returning corresponding handle field. In case of 5 entres there's even no need to worry about optimization.

Related