Skip to content

Commit

Permalink
Improve example to allow another connection after disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Aug 24, 2024
1 parent c51bbb8 commit 4375d5a
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions examples/src/bin/wifi_embassy_trouble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,31 @@ async fn main(_s: Spawner) {
},
// Advertise our presence to the world.
async {
let mut advertiser = ble
.advertise(
&Default::default(),
Advertisement::ConnectableScannableUndirected {
adv_data: &adv_data[..],
scan_data: &[],
},
)
.await
.unwrap();
let conn = advertiser.accept().await.unwrap();
// Keep connection alive and notify with value change
let mut tick: u8 = 0;
loop {
Timer::after(Duration::from_secs(10)).await;
tick += 1;
server
.notify(bat_level_handle, &conn, &[tick])
let mut advertiser = ble
.advertise(
&Default::default(),
Advertisement::ConnectableScannableUndirected {
adv_data: &adv_data[..],
scan_data: &[],
},
)
.await
.unwrap();
let conn = advertiser.accept().await.unwrap();
// Keep connection alive and notify with value change
let mut tick: u8 = 0;
loop {
if !conn.is_connected() {
break;
}
Timer::after(Duration::from_secs(1)).await;
tick = tick.wrapping_add(1);
server
.notify(bat_level_handle, &conn, &[tick])
.await
.unwrap();
}
}
},
)
Expand Down

0 comments on commit 4375d5a

Please sign in to comment.