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);
    }
    
    
  • 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?

Reply
  • 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?

Children
No Data
Related