Skip to content

Commit b329312

Browse files
carlescufinashif
authored andcommitted
samples: bluetooth: central_hr: Fix scanning
Fix scanning so that we always use active scanning in case the UUID we are looking for is in the scan response, and disable duplicate filtering to handle devices that modify their advertising data at runtime, such as smartphones reacting to apps being opened and closed. Signed-off-by: Carles Cufi <[email protected]>
1 parent d0a6f68 commit b329312

File tree

1 file changed

+16
-3
lines changed
  • samples/bluetooth/central_hr/src

1 file changed

+16
-3
lines changed

samples/bluetooth/central_hr/src/main.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ static void device_found(const bt_addr_le_t *addr, s8_t rssi, u8_t type,
180180
}
181181
}
182182

183+
static int scan_start(void)
184+
{
185+
/* Use active scanning and disable duplicate filtering to handle any
186+
* devices that might update their advertising data at runtime. */
187+
struct bt_le_scan_param scan_param = {
188+
.type = BT_HCI_LE_SCAN_ACTIVE,
189+
.filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE,
190+
.interval = BT_GAP_SCAN_FAST_INTERVAL,
191+
.window = BT_GAP_SCAN_FAST_WINDOW,
192+
};
193+
194+
return bt_le_scan_start(&scan_param, device_found);
195+
}
196+
183197
static void disconnected(struct bt_conn *conn, u8_t reason)
184198
{
185199
char addr[BT_ADDR_LE_STR_LEN];
@@ -196,8 +210,7 @@ static void disconnected(struct bt_conn *conn, u8_t reason)
196210
bt_conn_unref(default_conn);
197211
default_conn = NULL;
198212

199-
/* This demo doesn't require active scan */
200-
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
213+
err = scan_start();
201214
if (err) {
202215
printk("Scanning failed to start (err %d)\n", err);
203216
}
@@ -222,7 +235,7 @@ void main(void)
222235

223236
bt_conn_cb_register(&conn_callbacks);
224237

225-
err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, device_found);
238+
err = scan_start();
226239

227240
if (err) {
228241
printk("Scanning failed to start (err %d)\n", err);

0 commit comments

Comments
 (0)