Skip to content

Commit

Permalink
Print message while waiting for DNS and connection
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 9, 2023
1 parent 391b8c7 commit 760f328
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/board/wifi/sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use embassy_sync::{
mutex::{Mutex, MutexGuard},
signal::Signal,
};
use embassy_time::{Duration, Ticker, Timer};
use embassy_time::{Duration, Timer};
use embedded_svc::wifi::{AccessPointInfo, ClientConfiguration, Configuration, Wifi as _};
use esp_wifi::{
wifi::{WifiController, WifiDevice, WifiEvent, WifiMode},
Expand Down Expand Up @@ -178,10 +178,9 @@ impl Sta {
}
},
async {
let mut ticker = Ticker::every(Duration::from_millis(100));
loop {
// A message is displayed for at least 300ms so we don't need to wait here.
display_message(board, "Connecting...").await;
ticker.next().await;
}
},
)
Expand Down
19 changes: 15 additions & 4 deletions src/states/throughput.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use embassy_futures::select::{select, Either};
use embassy_time::{Duration, Instant};
use embedded_io::asynch::Read;
use reqwless::{request::Method, response::Status};
Expand Down Expand Up @@ -80,8 +81,6 @@ async fn run_test(board: &mut Board) -> TestResult {
};
let mut client = client_resources.client();

display_message(board, "Connecting...").await;

let mut url = heapless::String::<128>::new();
if uwrite!(
&mut url,
Expand All @@ -98,8 +97,20 @@ async fn run_test(board: &mut Board) -> TestResult {

debug!("Testing throughput using {}", url.as_str());

let mut request = match Timeout::with(CONNECT_TIMEOUT, client.request(Method::GET, &url)).await
{
let connect = Timeout::with(CONNECT_TIMEOUT, async {
let futures = select(client.request(Method::GET, &url), async {
loop {
// A message is displayed for at least 300ms so we don't need to wait here.
display_message(board, "Connecting to server...").await;
}
});
match futures.await {
Either::First(request) => request,
Either::Second(_) => unreachable!(),
}
});

let mut request = match connect.await {
Some(Ok(request)) => request,
Some(Err(e)) => {
warn!("HTTP connect error: {}", e);
Expand Down

0 comments on commit 760f328

Please sign in to comment.