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

getting adv device name of peripheral in central connection once connected

hai ,

          In my application to connect 5 peripherals with central and here i am connecting with  device names

static char const m_target_periph_name1[] = "Nordic_Blinky1";
static char const m_target_periph_name2[] = "Nordic_Blinky2";

i am able to print the device names in  BLE_GAP_EVT_ADV_REPORT

const ble_gap_evt_adv_report_t *p_adv_report = &p_gap_evt->params.adv_report;
const ble_data_t *data = &p_adv_report->data;

uint8_t *device_name = ble_advdata_parse(data->p_data, data->len, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
// int8_t report = p_ble_evt->evt.gap_evt.params.adv_report.rssi;

if(data->len == 0)
{
printf("nothing\n");
}
else{
printf("%s \r\n",device_name);
}

here my question is ,

i should get the connected name and connection id for every connection  in central 

how to get the connected device name  and  connected ID and also once it disconnected should get name the disconnected device  name and id ??

regards,

sowmiya

  • static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        ret_code_t err_code;
     uint8_array_t adv_data;
        uint8_array_t dev_name;
        // For readability.
        ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
      const ble_gap_evt_adv_report_t *p_adv_report = &p_gap_evt->params.adv_report;
     const ble_data_t *data = &p_adv_report->data;
        switch (p_ble_evt->header.evt_id)
        {   
            case BLE_GAP_EVT_ADV_REPORT:
            {
         
                 ret_code_t err;
    
            
    
    uint8_t *device_name = ble_advdata_parse(data->p_data, data->len, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
        int8_t report = p_ble_evt->evt.gap_evt.params.adv_report.rssi;
    
        if(data->len == 0)
        {
          printf("nothing\n");
        }
        else{
          printf("%s \r\n",device_name);  
        }
        }
         case BLE_GAP_EVT_CONNECTED:
            { 
              
              printf("CONNECTED\n");
                NRF_LOG_INFO("Connected.");
                  NRF_LOG_INFO("connected to %02x,%02x,%02x,%02x,%02x,%02x\n", p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[0],
                                                                           p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[1],
                                                                           p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[2],
                                                                           p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[3],
                                                                           p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[4],
                                                                           p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[5]) 
                                                                           
                                                                           
                                                                           break;
                                                                           }
                                                                           }
                                                                           }

    static char const m_target_periph_name1[] = "Nordic_Blinky1";
    static char const m_target_periph_name2[] = "Nordic_Blinky2";

    For connection , above is my device name

    here my question is ,

    i should get the connected name and connection id for every connection  in central 

    how to get the connected device name  and  connected ID and also once it disconnected should get name the disconnected device  name and id ??

  • Hello Sowmiya,

    I believe this is already answered in your other ticket:

    https://devzone.nordicsemi.com/f/nordic-q-a/63612/connecting-multi-peripherals-in-one-central-with-m_target_periph_name

    You will not get the advertisement name in the connection events every connection interval.

    First of all, your application will only be notified if the connected device does something, such as writing to one of your characteristics. When this happens, this event will only contain the conn_handle:

    p_ble_evt->evt.<event type>.conn_handle;

    For example in the connected event, that would be:

            case BLE_GAP_EVT_CONNECTED:
                NRF_LOG_INFO("Connected to %02x:%02x:%02x:%02x:%02x:%02x", p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[0],
                                                                            p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[1],
                                                                            p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[2],
                                                                            p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[3],
                                                                            p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[4],
                                                                            p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[5]);
                NRF_LOG_INFO("conn_handle: %02x", p_ble_evt->evt.gap_evt.conn_handle);
                ...

    So you need to somehow keep track of this connection handle to know what device the events are coming from.

    If you want to pair this up with the advertising name, you also need to keep track of what the advertising name that belongs to what BLE address from the advertising report event.

    Best regards,

    Edvin

Related