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

Related