Clarification for restarting scanning with NCS

Hi

We built an application that bases on the sample application "central_and_peripheral_hr" with NCS v2.7.0 and nRF54L15.

In this application, I tried to manually start, stop and re-start the BLE scanning with the following code:

	scan_init();
	err = scan_start();
	if (err) {
		return 0;
	}

	printk("Scanning started\n");

	k_sleep(K_MSEC(1000));

	err = bt_scan_stop();
	if (err) {
		printk("Scanning failed to start (err %d)\n", err);
	}
	printk("Scanning stopped\n");

	k_sleep(K_MSEC(1000));

	// scan_init();
	err = scan_start();
	if (err) {
		return 0;
	}

	printk("Scanning started\n");

	k_sleep(K_MSEC(1000));

	err = bt_scan_stop();
	if (err) {
		printk("Scanning failed to start (err %d)\n", err);
	}
	printk("Scanning stopped\n");

This works when the function scan_init() is only called once. But when I execute the scan_init() function again before the scanning is re-started (see line 19 in code above), the application got stuck somewhere in the Bluetooth RX thread after the scanning has been started.

So, my question is if the functions bt_scan_init(&param) and bt_scan_cb_register(&scan_cb) are only allowed to be called once during runtime?

Many thanks in advance.

Best regards

Remo

Parents
  • Hi Remo,

    It does not appear to be explicitly stated in the documentation that you can't reinitialize the scanner module, nor are there any attempts to guard against it. However, it should be redundant to do so, as the scanning library includes APIs to start/stop scanning and APIs to update the configuration parameters if needed.

    So, my question is if the functions bt_scan_init(&param) and bt_scan_cb_register(&scan_cb) are only allowed to be called once during runtime?

    Yes. There is no _uninit() or _unregister() function. From what I can tell from the code, calling bt_scan_cb_register() multiple times will cause multiple callbacks to be appended to the callback list.

    Best regards,

    Vidar

Reply
  • Hi Remo,

    It does not appear to be explicitly stated in the documentation that you can't reinitialize the scanner module, nor are there any attempts to guard against it. However, it should be redundant to do so, as the scanning library includes APIs to start/stop scanning and APIs to update the configuration parameters if needed.

    So, my question is if the functions bt_scan_init(&param) and bt_scan_cb_register(&scan_cb) are only allowed to be called once during runtime?

    Yes. There is no _uninit() or _unregister() function. From what I can tell from the code, calling bt_scan_cb_register() multiple times will cause multiple callbacks to be appended to the callback list.

    Best regards,

    Vidar

Children
No Data
Related