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

connecting multi peripherals in one central with m_target_periph_name

hai ,

   i my application i should connect 5 more peripherals with one central .

at first i  connected with peripherals mac id , mac id hard coded in central 

in central with the  scan report ,when scanned peer address equals with stored mac id  then i connected with below api . i can able to connect  two more peripherals at same time

static uint8_t m_first_relay[BLE_GAP_ADDR_LEN] = {0x4B, 0x28, 0x21, 0x9D, 0x3F, 0xD0};
static uint8_t m_relay_addr2[BLE_GAP_ADDR_LEN] = {0x26 ,0x76, 0x05, 0x6B, 0x23, 0xCC};

if(p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0] == 0x4B  || p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr[0]== 0x26) {

sd_ble_gap_scan_stop();
err = sd_ble_gap_connect(&p_ble_evt->evt.gap_evt.params.adv_report.peer_addr, &m_scan.scan_params, &m_scan.conn_params, APP_BLE_CONN_CFG_TAG);
}

now i need to connect with  m_target_periph_name[] 

how to connect with more peripherals in central with using device name??

static char const m_target_periph_name[] = "Nordic_Blinky"; /**< Name of the device to try to connect to. This name is searched for in the scanning report data. */

same name with peripheral device name , mow i can be able to connect

but for multiple connections tried like this,

static char* const m_target_periph_name[2] = {"Nordic_Blinky", "Nordic_Blinky1"};

if i used as above no connection is getting connected ,

could you please tell me how to connect with multiple peripherals on central using device name??

Regards,

sowmiya

  • Hello,

    Are you sure that this implementation works the way you think? first, you probably need to call nrf_ble_scan_filter_set() twice, with each of the names you want to use. I suggest you study the nrf_ble_scan_on_adv_report in nrf_ble_scan.c to see how these filters work. Then sort out how the line:

    static char* const m_target_periph_name[2] = {"Nordic_Blinky", "Nordic_Blinky1"};

    behaves. Do you really get an array with two names? (I have not tested due to short staffing because of summer holidays in Norway. I can test it next week if I get the time).

    Perhaps just do something like this:

    // in main.c:
    static char const m_target_periph_name1[] = "Nordic_Blinky1";
    static char const m_target_periph_name2[] = "Nordic_Blinky2";
    
    
    ...
    
    
    static void scan_init(void)
    {
        ...
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name1);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name2);
        APP_ERROR_CHECK(err_code);
        ...
    }
    
    ...

    Best regards,

    Edvin

  • thanks for your quick reply ,

    now with above filter set is working fine 

    and after each peripheral connected with central  , i should  get the connected device and connection id 

    how can i get connection id and advertising name ??

  • When you are connected you should get the BLE_GAP_EVT_CONNECTED event. This event does not contain the advertising name. Only the BLE address of the device that you have connected to, and a connection handle. Please note that in the later events (while you are connected), you will only have the connection handle (no BLE address either). So if you want to keep track of the advertising names throughout the connection, you need to store the advertising address from the adv_report, together with the advertising name. Then in the connected event, you also need to store the connection handle. Then you will know that all the events containing that connection handle will be linked to that advertising name.

    The connection handle doesn't change during a connection, but if the device is disconnected and re connected, then it may be assigned a new connection handle.

    All of this is possible, but check whether you actually need to know the advertising name during the connection. Perhaps it is enough with the BLE address, or even the connection handle itself.

    Best regards,

    Edvin

Related