I have to switch between several different scanning modes.
I scan in passive mode to get all sensors' advertisements (no connection).
I scan in active mode to get a specific sensor's name (no connection).
I need also to scan and connect to a specific sensor.
Only in the bt_scan_init() function is the bt_scan.connect_if_match flag settable.
But I can't call the bt_scan_init() function twice in the program since there is a local static bt_le_scan_cb scan_cb variable which is never unregistered and no way to do so.
I have resolved this by adding an unregister statement before it registers as seen in my code snippet.
Is there a better way?
static struct bt_le_scan_cb scan_cb; void bt_scan_init(const struct bt_scan_init_param *init) { // ?!? below bt_le_scan_cb_unregister(&scan_cb); // ?!? above bt_le_scan_cb_register(&scan_cb); /* Disable all scanning filters. */ memset(&bt_scan.scan_filters, 0, sizeof(bt_scan.scan_filters));
Thanks David