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

  • Whitelisting and directed advertising are the methods that the Core Specification sets up for this use case, and as far as we've seen internally, this mostly works correctly. There is unfortunately a bug with the current release of the softdevice, which could cause whitelist to not be applied, but this should happen only rarely. In that case, even a non-whitelisted device may be able to connect.

    Several of our SDK examples implement whitelisting (for example ble_app_proximity), and some also directed advertising (ble_app_hids_keyboard). Have you tested them as is?

    With your own code, in what way exactly can you not get it working? Could you please share your code?

  • 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

    If you are doing it in this order, then you should make sure you are not trying to connect to the peripheral with the Master Emulator (depending on how you are using it), might as well shut it down. And if it is a smartphone, then you could either turn off the Bluetooth on it, or delete the bond information if you have no intention in retaining it.

  • 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.

  • Your code looks reasonable. When you see your device in Master Control Panel, what kind of flags does it advertise with? Could it be that some of the functions you call return an error, ending up in app_error_handler(), which does a reset by default?

    Also, if you've based your code on for example the proximity example in the SDK, this will time out after a while, and go from advertising with whitelist to advertising without whitelist, could that be the problem?

    Finally, as is stated in the release notes for S110 version 5.2.1, there is a known issue which could cause non-whitelisted devices to connect, but if this is the problem you're hitting, you should not see this very often. Are you able to reproduce this each and every time you try?

Related