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

[nRF51822] Connectable Indirected advertising after pairing was done.

Hi sir In Desktop 2, before BTLE pairing, nRF51 uses Connectable Indirected advertising. After BTLE pairing with BTLE host, nRF51 will select Directed advertsing for saving connection time. Could nRF51use Connection Indirected advertising type to the BTLE host which was already paired with it? Then, like mouse or keyboard device, can they still work well?

Regards, Jeffery

Parents
  • Yes, this is most definitely possible, it's just a matter of editing the code used when starting advertising. If you already have a bond, and does not want to initiate a new one, I'd recommend you to use advertising with whitelisting.

    When using the bond manager, you can get hold of a whitelist by calling the ble_bondmngr_whitelist_get() function. The following two code snippets should show what's needed:

    
    static void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
        static ble_gap_whitelist_t whitelist;
        
        ble_uuid_t adv_uuids[] = 
        {
            {BLE_UUID_GLUCOSE_SERVICE,            BLE_UUID_TYPE_BLE},
            {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE}, 
            {BLE_UUID_DEVICE_INFORMATION_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      = false;
        advdata.flags.size              = sizeof(flags);
        advdata.flags.p_data            = &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)
        err_code = ble_bondmngr_whitelist_get(&whitelist);
        APP_ERROR_CHECK(err_code);
        
        memset(&m_adv_params, 0, sizeof(m_adv_params));
        
        m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
        m_adv_params.p_peer_addr = NULL;                           // Undirected advertisement
        
        if ((whitelist.addr_count > 0) || (whitelist.irk_count > 0))
        {
            m_adv_params.fp          = BLE_GAP_ADV_FP_FILTER_BOTH;
            m_adv_params.p_whitelist = &whitelist;
        }
        else
        {
            m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
        }
        m_adv_params.interval    = APP_ADV_INTERVAL;
        m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
    }
    
    ...
    
    static void advertising_start(void)
    {
        uint32_t err_code;
        
        err_code = sd_ble_gap_adv_start(&m_adv_params);
        APP_ERROR_CHECK(err_code);
        
        nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
    }
    
    
Reply
  • Yes, this is most definitely possible, it's just a matter of editing the code used when starting advertising. If you already have a bond, and does not want to initiate a new one, I'd recommend you to use advertising with whitelisting.

    When using the bond manager, you can get hold of a whitelist by calling the ble_bondmngr_whitelist_get() function. The following two code snippets should show what's needed:

    
    static void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
        static ble_gap_whitelist_t whitelist;
        
        ble_uuid_t adv_uuids[] = 
        {
            {BLE_UUID_GLUCOSE_SERVICE,            BLE_UUID_TYPE_BLE},
            {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE}, 
            {BLE_UUID_DEVICE_INFORMATION_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      = false;
        advdata.flags.size              = sizeof(flags);
        advdata.flags.p_data            = &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)
        err_code = ble_bondmngr_whitelist_get(&whitelist);
        APP_ERROR_CHECK(err_code);
        
        memset(&m_adv_params, 0, sizeof(m_adv_params));
        
        m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
        m_adv_params.p_peer_addr = NULL;                           // Undirected advertisement
        
        if ((whitelist.addr_count > 0) || (whitelist.irk_count > 0))
        {
            m_adv_params.fp          = BLE_GAP_ADV_FP_FILTER_BOTH;
            m_adv_params.p_whitelist = &whitelist;
        }
        else
        {
            m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
        }
        m_adv_params.interval    = APP_ADV_INTERVAL;
        m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
    }
    
    ...
    
    static void advertising_start(void)
    {
        uint32_t err_code;
        
        err_code = sd_ble_gap_adv_start(&m_adv_params);
        APP_ERROR_CHECK(err_code);
        
        nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
    }
    
    
Children
No Data
Related