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

ble scan error

Hi Everyone,

I'm not able to start ble scan. I've followed following example...

Developing Bluetooth Low Energy products using nRF Connect SDK

 https://www.youtube.com/watch?v=hY_tDext6zA

I was able to advertise from my custom device. Now I want to add Bluetooth Central to this project.

I have added 

CONFIG_BT_CENTRAL=y
 

 to the existing .conf file.

now coming to scan part...I have made this call in my bluetooth_init function, then I got the error as shown in screenshot. Is there any more setting I need to take care of?

and What is right way to start ble_scan?

  err = bt_le_scan_start(BT_LE_SCAN_ACTIVE,  remote_callbacks.scan_callback);   

Parents
  • Hi

    I would suggest checking out I.E. the central_uart example and specifically the scan_init function we use. Then you can add a 

    bt_scan_start() function afterwards to start scanning for bluetooth-devices.

    BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL,
    		scan_connecting_error, scan_connecting);
    
    static int scan_init(void)
    {
    	int err;
    	struct bt_scan_init_param scan_init = {
    		.connect_if_match = 1,
    	};
    
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_NUS_SERVICE);
    	if (err) {
    		LOG_ERR("Scanning filters cannot be set (err %d)", err);
    		return err;
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
    	if (err) {
    		LOG_ERR("Filters cannot be turned on (err %d)", err);
    		return err;
    	}
    
    	LOG_INF("Scan module initialized");
    	return err;
    }

    Best regards,

    Simon

Reply
  • Hi

    I would suggest checking out I.E. the central_uart example and specifically the scan_init function we use. Then you can add a 

    bt_scan_start() function afterwards to start scanning for bluetooth-devices.

    BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL,
    		scan_connecting_error, scan_connecting);
    
    static int scan_init(void)
    {
    	int err;
    	struct bt_scan_init_param scan_init = {
    		.connect_if_match = 1,
    	};
    
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_NUS_SERVICE);
    	if (err) {
    		LOG_ERR("Scanning filters cannot be set (err %d)", err);
    		return err;
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
    	if (err) {
    		LOG_ERR("Filters cannot be turned on (err %d)", err);
    		return err;
    	}
    
    	LOG_INF("Scan module initialized");
    	return err;
    }

    Best regards,

    Simon

Children
Related