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

Connect with Autoconnect on Central

Hello,

On a BLE Central, how can I enable connect with auto connect to a peripheral with previously saved bonding information.

Once paired and bonded, I can recall bonding address information on boot. I use this address to configure the scanning filters on the central but I cannot get the central to connect from a directed advertisement. On boot and on disconnect I add the last connected address to the queue and only attempt direct advertising until reconnected. The peripheral is configured to only reconnect via direct advertisement with the following code taken from the SDK examples. 

if (!k_msgq_get(&bonds_queue, &addr, K_NO_WAIT)) {
	char addr_buf[BT_ADDR_LE_STR_LEN];

	adv_param = *BT_LE_ADV_CONN_DIR(&addr);
	adv_param.options |= BT_LE_ADV_OPT_DIR_ADDR_RPA;

	err = bt_le_adv_start(&adv_param, NULL, 0, NULL, 0);

	if (err) {
		LOG_ERR("Directed advertising failed to start");
		return;
	}

	bt_addr_le_to_str(&addr, addr_buf, BT_ADDR_LE_STR_LEN);

	LOG_DBG("Direct advertising to %s started", log_strdup(addr_buf));
}

When testing the same peripheral but replacing the central with the nRF Connect app and selecting "Connect with autoconnect" the peripheral works as intended. When attempting to do the same on an embedded central scanning for the address and connecting to a match I cannot connect to a directed advertisement. However, I can get the central scanning in address filtered mode to connect to a peripheral advertising in regular mode that uses the following advertisement:

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

static const struct bt_data sd[] = {
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_CUSTOM_VAL),
};

....

adv_param = *BT_LE_ADV_CONN;
adv_param.options |= BT_LE_ADV_OPT_ONE_TIME;

err = bt_le_adv_start(BT_LE_ADV_CONN,
		      ad, ARRAY_SIZE(ad),
		      sd, ARRAY_SIZE(sd));

....

How can I fix this? The code used on central for scanning is the following:

bt_scan_stop();
bt_scan_filter_remove_all();
bt_scan_filter_disable();

err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_ADDR, addr);
if (err) {
	LOG_ERR("Set filter on last device address error: %d", err);
	return err;
}
	
LOG_DBG("Enabling bonded address filters");

err = bt_scan_filter_enable(BT_SCAN_ADDR_FILTER, false);
if (err) {
	LOG_ERR("Scanning filters cannot be set (%d)", err);
	return err;
}

err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
if (err) {
	LOG_ERR("Scanning failed to start (%d)", err);
	return err;
}

LOG_DBG("Scanning started");

Parents
  • Hi, 

    When attempting to do the same on an embedded central scanning for the address and connecting to a match I cannot connect to a directed advertisement. However, I can get the central scanning in address filtered mode to connect to a peripheral advertising in regular mode that uses the following advertisement:

    This post might help.  

    Regards,
    Amanda

  • Hello,

    I've added the config option CONFIG_BT_EXT_ADV to my peripheral prj.conf added CONFIG_BT_CTLR_ADV_EXT=y to child_image/hci_rpmsg.conf

    I have also tried adding BT_LE_ADV_OPT_EXT_ADV to the options which caused an -EINVAL error which was strange since when the config option is enabled, bt_le_adv_start_ext is always called not bt_le_adv_start_legacy.

    I traced this error back to bt_le_adv_start_ext calling valid_adv_param instead of valid_adv_ext_param which seems like a bug. Therefore I also applied the following patch which fixes the -EINVAL error.

    diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c
    index ecd0de3371..df35e5d6f6 100644
    --- a/subsys/bluetooth/host/adv.c
    +++ b/subsys/bluetooth/host/adv.c
    @@ -1223,7 +1223,7 @@ int bt_le_adv_start_ext(struct bt_le_ext_adv *adv,
     		return -EAGAIN;
     	}
     
    -	if (!valid_adv_param(param)) {
    +	if (!valid_adv_ext_param(param)) {
     		return -EINVAL;
     	}
     

    When testing this configuration with the mobile app, I cannot find the device listed. Only when I remove BT_LE_ADV_OPT_EXT_ADV and use the following as a adv does it show up during scan.

    adv_param = *BT_LE_ADV_CONN;
    adv_param.options |= BT_LE_ADV_OPT_ONE_TIME;
    
    err = bt_le_adv_start(adv_param,
    		      ad, ARRAY_SIZE(ad),
    		      sd, ARRAY_SIZE(sd));

    However now it seem the issue is when connecting, a bus fault is generated in the kernel work.c flag_clear() function. This also occurs without the patch.

  • Hi, 

    I would try to use bt_le_ext_adv_start. Take a look at the example in this post

    -Amanda

  • I am still not able to get extended advertising to work but I was able to get it to work using bt_le_filter_accept_list_add on both the central and peripheral bond addresses to filter connectable addresses.

    On the central I was then able to use bt_conn_le_create_auto to create an automatic reconnect connection.

Reply
  • I am still not able to get extended advertising to work but I was able to get it to work using bt_le_filter_accept_list_add on both the central and peripheral bond addresses to filter connectable addresses.

    On the central I was then able to use bt_conn_le_create_auto to create an automatic reconnect connection.

Children
No Data
Related