This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Connecting to only one central. How to? detailed

Hi, i know this question has been ask before but, i was reading and readind and i could find a way to do it. I got the theory but when i'm going to implement it in my code i get confused.

Starting by symple, i have 2 devices, one of this as central and one of this as peripheral.

I need the peripheral only get connected to this specific central and avoide connection to another.

1-. How i can setup an static address to my central? which part of the code i do that?

2-.I know that it is possible to create a whitelist to save bond info about the connection that has been made but i think i don't need it because i only have 1 central and just want to connect to him. wich part of the code i have to writte to set the address of my central in order to only connect to him? What would be this address, the peer addres or another one?

3-. I have read about directed advertising, what i got was that, you use direct adv when you want to connect to a specific central, but again, where do you specify that?

4-. My peripheral could be scannable but i just want my central could connect not any other device.

Maybe these are newbie question, but how i wrote above, i have read and read and i don't find a good explanation to do that.

Sorry and thanks in advance.

Parents
  • @HungBui: i think i had my code ready, but when the central tries to connect, it gets disconnect..

    This is my central device address:

    image description

    this is my function start_advertising() in main.c

    /**@brief Function for starting advertising.
     */
    static void advertising_start(void)
    {
        uint32_t             err_code;
    ble_gap_adv_params_t adv_params;
    ble_gap_whitelist_t  whitelist;
    ble_gap_addr_t   * p_whitelist_addr[1];
    ble_gap_addr_t        whitelist_addr={BLE_GAP_ADDR_TYPE_RANDOM_STATIC,{0x80,0xA5,0x89,0x68,0xAD,0x48}} ;
    uint8_t addr[6] = {0x80,0xA5,0x89,0x68,0xAD,0x48};  
    uint8_t adv_data[15] = {0x07,0x09,0x4E,0x6F,0x72,0x64,0x69,0x63,0x02,0x01,0x04,0x03,0x03,0x0F,0x18};
    uint8_t adv_data_length = 15;
    
    //Setting up the advertising data with scan response data = Null
    err_code = sd_ble_gap_adv_data_set(adv_data, adv_data_length, NULL, NULL);    
    
    //Configure the advertising parameter and whitelist
    memset(&adv_params, 0, sizeof(adv_params));
    adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
    adv_params.p_peer_addr = NULL;
    adv_params.interval    = 64;
    adv_params.timeout     = 180;
    p_whitelist_addr[0] = &whitelist_addr;
    whitelist.addr_count = 1;
    whitelist.pp_addrs   =  p_whitelist_addr;
    whitelist.pp_irks = NULL;
    whitelist.irk_count =0;
    adv_params.fp          = BLE_GAP_ADV_FP_FILTER_CONNREQ;
    adv_params.p_whitelist = &whitelist;
    err_code = sd_ble_gap_adv_start(&adv_params);
    }
    

    and this is my main.c

    /**@brief Function for application main entry.
     */
    int main(void)
    {
    	  uint32_t err_code;
    	  bool erase_bonds;
    		configurar_puerto();
    	
    //	 leds_init();
    //    timers_init();
    	
    	  // inicializo el timer para mostrar el blinking del advertoising
    	  APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
        err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
        APP_ERROR_CHECK(err_code);
    	
    	  
        buttons_init();
    //	  nrf_delay_ms(50);
    		ble_stack_init();
    	
        device_manager_init(erase_bonds);
    	  gap_params_init();
        services_init();
        advertising_init();
    	  conn_params_init();
    	
    	// Empiezo el advertizing
    //	  err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    //    APP_ERROR_CHECK(err_code);
        advertising_start();
    	
    	// Espero un evento
        for (;;)
        {
            power_manage();
        }
    

    }

    What it could happening?

  • @hungbui: finally i found it, the problem was the endiannes... i found to connect my peripheral with one specific central...

    Now, i think my central device is running with a random address because it change sometime... you told me that i can set a static address in my central with sd_ble_gap_address_set() but, where i have to do that?? in the advetising_init()???

Reply
  • @hungbui: finally i found it, the problem was the endiannes... i found to connect my peripheral with one specific central...

    Now, i think my central device is running with a random address because it change sometime... you told me that i can set a static address in my central with sd_ble_gap_address_set() but, where i have to do that?? in the advetising_init()???

Children
No Data
Related