Skip to content

Commit

Permalink
Add 30s timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 19, 2023
1 parent 799734e commit e66c6ea
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/states/upload_or_store_measurement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::mem::{self, MaybeUninit};

use alloc::{boxed::Box, vec::Vec};
use embassy_futures::select::{select, Either};
use embassy_net::{
dns::DnsSocket,
tcp::client::{TcpClient, TcpClientState},
Expand Down Expand Up @@ -314,22 +315,43 @@ where

let headers = [("X-Timestamp", timestamp.as_str())];

let mut request = match client.request(Method::POST, &upload_url).await {
Ok(request) => request
let connect = select(
client.request(Method::POST, &upload_url),
Timer::after(Duration::from_secs(30)),
)
.await;

let mut request = match connect {
Either::First(Ok(request)) => request
.headers(&headers) // TODO
.body(samples),
Err(e) => {
warn!("HTTP error: {}", e);
Either::First(Err(e)) => {
warn!("HTTP connect error: {}", e);
return Err(());
}
Either::Second(_) => {
warn!("Timeout");
return Err(());
}
};

if let Err(e) = request.send(rx_buffer).await {
warn!("HTTP error: {:?}", e);
return Err(());
}
let upload = select(
request.send(rx_buffer),
Timer::after(Duration::from_secs(30)),
)
.await;

Ok(())
match upload {
Either::First(Ok(_)) => Ok(()),
Either::First(Err(e)) => {
warn!("HTTP upload error: {}", e);
return Err(());
}
Either::Second(_) => {
warn!("Timeout");
return Err(());
}
}
}

async fn try_store_measurement(board: &mut Board, measurement: &[u8]) -> Result<(), StorageError> {
Expand Down

0 comments on commit e66c6ea

Please sign in to comment.