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

Change Scan Parameters using NCS

What I'm trying to do, is probably very simple. I hope.

In the following code which works fine.

I want to scan not using Coded PHY

Then change back to using Coded PHY

I'd be grateful if you would show me the proper way to achieve this please.

BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL, NULL, NULL);

void initialise_Coded_PHY_scan(void) {
struct bt_le_scan_param scan_param = {
.type = BT_HCI_LE_SCAN_PASSIVE,
.options = BT_LE_SCAN_OPT_CODED,
// JC .options = BT_LE_SCAN_OPT_CODED, BT_LE_SCAN_OPT_FILTER_DUPLICATE,
.interval = BT_GAP_SCAN_FAST_INTERVAL,
.window = BT_GAP_SCAN_FAST_WINDOW,
};
struct bt_scan_init_param scan_init = {
.connect_if_match = 0,
.scan_param = &scan_param,
.conn_param = NULL
};
int err = 0;
bt_scan_init(&scan_init);
bt_scan_cb_register(&scan_cb);
/* Set Scan filter */
err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, dev_name);
if (err) {
printk("Scanning Name filter cannot be set (err %d)\n", err);
return;
}
// err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_MANUFACTURER_DATA, MANUFACTURER_ID);
// if (err) {
// printk("Scanning filter Manufacturer ID cannot be set (err %d)\n", err);
// return;
// }

/* Apply scan filter */
err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);
// err = bt_scan_filter_enable(BT_SCAN_FILTER_TYPE_MANUFACTURER_DATA, false);
if (err) {
printk("Filters cannot be turned on (err %d)\n", err);
return;
}
/* Start scanning */
bt_scan_start(BT_SCAN_TYPE_SCAN_PASSIVE);
}

Parents Reply
  • Hi,

    Yes, it is possible. You can start scanning in 1Mbit then stop and update the scan parameters for Coded PHY then start scanning again.

    In the example, only coded PHY is enabled. To enable coded PHY:

    .options  = BT_LE_SCAN_OPT_CODED | BT_LE_SCAN_OPT_NO_1M

    Setting BT_LE_SCAN_OPT_NO_1M will disable 1Mbit, NO_1M means 1Mbit Phy disable:

     /**
         * @brief Disable scan on 1M phy.
         *
         * @note Requires @ref BT_LE_SCAN_OPT_CODED.
         */
        BT_LE_SCAN_OPT_NO_1M = BIT(3),

    To use 1M, you can try setting options to NULL.

    To update the scan parameters use the function bt_scan_params_set(). 

Children
No Data
Related