Skip to content

Commit

Permalink
samples: Bluetooth: Option to have scanning in peripheral
Browse files Browse the repository at this point in the history
Option to have continous scanning simultaneously while
advertising and multiple peripheral role is active.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
  • Loading branch information
cvinayak authored and cfriedt committed Jul 21, 2021
1 parent 529bb8d commit ac82fbf
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions samples/bluetooth/peripheral_identity/src/peripheral_identity.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ static struct bt_conn_cb conn_callbacks = {
#endif /* CONFIG_BT_SMP */
};

#if defined(CONFIG_BT_OBSERVER)
#define BT_LE_SCAN_PASSIVE_ALLOW_DUPILCATES \
BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_PASSIVE, \
BT_LE_SCAN_OPT_NONE, \
BT_GAP_SCAN_FAST_INTERVAL, \
BT_GAP_SCAN_FAST_INTERVAL)

static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
struct net_buf_simple *ad)
{
char addr_str[BT_ADDR_LE_STR_LEN];

bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
printk("Device found: %s (RSSI %d)\n", addr_str, rssi);
}
#endif /* CONFIG_BT_OBSERVER */

int init_peripheral(void)
{
size_t id_count;
Expand All @@ -182,6 +199,17 @@ int init_peripheral(void)

printk("Bluetooth initialized\n");

#if defined(CONFIG_BT_OBSERVER)
printk("Start continuous passive scanning...");
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE_ALLOW_DUPILCATES,
device_found);
if (err) {
printk("Scan start failed (%d).\n", err);
return err;
}
printk("success.\n");
#endif /* CONFIG_BT_OBSERVER */

k_work_init(&work_adv_start, adv_start);
k_work_submit(&work_adv_start);

Expand Down

0 comments on commit ac82fbf

Please sign in to comment.