Skip to content

Commit

Permalink
samples: Bluetooth: update scanning_while_connecting
Browse files Browse the repository at this point in the history
Move flag that protects application from establishing
a new connection when there is already a connection
establishment process pending. This is moved to after
the if to check that we have established all connections.
Otherwise, we get in the scan_recv call back an attempt
to establish a connection when we have used all
connection objects before we stop scanning in main.

Signed-off-by: Henrik Lander <[email protected]>
  • Loading branch information
henrla authored and jukkar committed Dec 5, 2024
1 parent 97093b5 commit 7eb5555
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion samples/bluetooth/scanning_while_connecting/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)

static void connected(struct bt_conn *conn, uint8_t err)
{
connection_establishment_ongoing = false;
char addr_str[BT_ADDR_LE_STR_LEN];

bt_addr_le_to_str(bt_conn_get_dst(conn), addr_str, sizeof(addr_str));
Expand All @@ -182,6 +181,8 @@ static void connected(struct bt_conn *conn, uint8_t err)
}
}

connection_establishment_ongoing = false;

struct bt_le_conn_param conn_param = {
.interval_min = 500, /* Minimum Connection Interval (interval_min * 1.25 ms) */
.interval_max = 500, /* Maximum Connection Interval (interval_max * 1.25 ms) */
Expand All @@ -201,6 +202,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
if (active_conn_establishment_mode == SEQUENTIAL_SCAN_AND_CONNECT) {
scan_start();
}

}

static void try_connect(void)
Expand Down Expand Up @@ -434,6 +436,7 @@ int main(void)
active_conn_establishment_mode = conn_establishment_modes[i];

num_connections = 0;
connection_establishment_ongoing = false;
ring_buf_reset(&connectable_peers_ring_buf);

print_conn_establishment_mode(active_conn_establishment_mode);
Expand Down

0 comments on commit 7eb5555

Please sign in to comment.