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

How to connect to one specific master

Hi,

I´m using nRF51822 with my own application and I want to connect just to one specific master device (for example smartphone) after this one is bonded:

  1. nRF51822 wakes up and clears all bonded master
  2. start adervertising
  3. bonding to master
  4. disconnect and store master information ...

How can I make sure that there is no other master device (for example master emulator) is connecting to my device when I´m advertising to my first master device. I´ve also tried direct advertising and advertising with whitelist but it doesn´t work.

Thanks Marcel

Parents
  • Hi, thanks for your reply. I use a iPhone and the master emulator for testing. I try to explain it more detailed:

    1. nRF51822 wakes up and all master are cleared

    2. nRF51822 starts advertising

    3. connect nRF51822 to the iPhone (got the demand of pairing)

    4. disconnect iPhone from nRF51822

    5. force sleep mode to nRF51822

    6. wake up nRF51822

    7. nRF51822 starts advertising with whitelist

    8. start master emulator and discovery mode

    9. master emulator connects to nRF51822

    What I´ve noticed: It takes a few seconds between point 8 & 9 until the nRF51822 appears into the master emulator screen. Is there a special timeout for advertising with whitelist?

    Here´s my source code (based of hid keyboard example):

    
    static void _advertising_init(uint8_t adv_flags)
    {
      uint32_t      err_code;
      ble_advdata_t advdata;
    
      ble_uuid_t adv_uuids[] = { { BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE, BLE_UUID_TYPE_BLE } };
    
      // Build and set advertising data
      memset(&advdata, 0, sizeof(advdata));
    
      advdata.name_type               = BLE_ADVDATA_FULL_NAME;
      advdata.include_appearance      = true;
      advdata.flags.size              = sizeof(adv_flags);
      advdata.flags.p_data            = &adv_flags;
      advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
      advdata.uuids_complete.p_uuids  = adv_uuids;
    
      err_code = ble_advdata_set(&advdata, NULL);
      APP_ERROR_CHECK(err_code);
    
      // Initialise advertising parameters (used when starting advertising)
      memset(&adv_params, 0, sizeof(adv_params));
    
      adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
      adv_params.p_peer_addr = NULL;                           // Undirected advertisement
      adv_params.fp          = BLE_GAP_ADV_FP_ANY;
      adv_params.p_whitelist = NULL;
      adv_params.interval    = APP_ADV_INTERVAL;
      adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
    
      advertising_mode = BLE_NO_ADV;
    }
    
    
    static void _advertising_start(void)
    {
      uint32_t             err_code;
      ble_gap_whitelist_t  whitelist;
      ble_gap_addr_t       peer_address;
      char str[6];
    
      err_code = ble_bondmngr_whitelist_get(&whitelist);
      APP_ERROR_CHECK(err_code);
    
      if (ble_bondmngr_master_addr_get(last_connected_master, &peer_address) == NRF_SUCCESS) {
        adv_params.p_peer_addr = &peer_address;
        debug_print_array_hex(peer_address.addr, BLE_GAP_ADDR_LEN);
        debug_uart_putstring("");
        advertising_mode = BLE_DIRECTED_ADV;
      } else if ((whitelist.addr_count != 0) || (whitelist.irk_count != 0)) {
        _advertising_init(BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED);
    		adv_params.fp          = BLE_GAP_ADV_FP_FILTER_BOTH;
    		adv_params.p_whitelist = &whitelist;
    		advertising_mode = BLE_ADV_WHITELIST;
      } else {
      	advertising_mode = BLE_ADV;
      }
    
      debug_fmt_u32(str, advertising_mode);
    	debug_uart_putstring(str);
    	debug_uart_new_line();
    
      err_code = sd_ble_gap_adv_start(&adv_params);
      APP_ERROR_CHECK(err_code);
    }
    
    
  • Based on what your APP_ADV_INTERVAL is and what the scan interval is on the master emulator, it can take some time before the adv interval actually hits the scan interval of the master. To improve this you can increase the scan window to be less than or equal to scan interval on the master device, this would make the master list the devices quicker. If the APP_ADV_INTERVAL is 1 second, then it might be that it would take at least one second to find it, if it is not able to hit the first possible adv event in the scan window. RF noise in the environment as other advertising devices could also impact the time for the Master Emulator to locate your peripheral.

    There should not be any significant delays when advertising with whitelist.

Reply
  • Based on what your APP_ADV_INTERVAL is and what the scan interval is on the master emulator, it can take some time before the adv interval actually hits the scan interval of the master. To improve this you can increase the scan window to be less than or equal to scan interval on the master device, this would make the master list the devices quicker. If the APP_ADV_INTERVAL is 1 second, then it might be that it would take at least one second to find it, if it is not able to hit the first possible adv event in the scan window. RF noise in the environment as other advertising devices could also impact the time for the Master Emulator to locate your peripheral.

    There should not be any significant delays when advertising with whitelist.

Children
No Data
Related