tasks: wifi: report cloud connectivity status in the http telemetry task
This commit is contained in:
@@ -74,7 +74,7 @@ pub async fn wifi_connect_task(mut wifi: WifiController<'static>, stack: Stack<'
|
||||
|
||||
// TODO: Wifi task needs to know when there is data to upload, so it only connects when needed.
|
||||
#[embassy_executor::task]
|
||||
pub async fn http_telemetry_task(mut predictions: DynSubscriber<'static, Prediction>, stack: Stack<'static>) {
|
||||
pub async fn http_telemetry_task(mut predictions: DynSubscriber<'static, Prediction>, stack: Stack<'static>, motion: DynamicSender<'static, Measurement>) {
|
||||
// TODO: should wait for wifi disconnect event somehow and use that to restart sending the wifi around
|
||||
|
||||
let seed = Rng::new().random() as i32;
|
||||
@@ -98,18 +98,24 @@ pub async fn http_telemetry_task(mut predictions: DynSubscriber<'static, Predict
|
||||
|
||||
loop {
|
||||
if let Prediction::Location(coords) = predictions.next_message_pure().await {
|
||||
|
||||
if stack.is_config_up() {
|
||||
// Only push to HTTP if we have an ip config etc
|
||||
if last_push.elapsed().as_secs() >= 5 || gps_to_local_meters_haversine(&last_location, &coords).norm() >= 10.0 {
|
||||
last_location = coords;
|
||||
last_push = Instant::now();
|
||||
if let Err(e) = Backoff::from_secs(3).attempt(async || {
|
||||
motion.send(Measurement::SensorHardwareStatus(SensorSource::Cloud, SensorState::AcquiringFix)).await;
|
||||
push_location(&mut client, coords, Instant::now().as_millis()).await
|
||||
}).await {
|
||||
motion.send(Measurement::SensorHardwareStatus(SensorSource::Cloud, SensorState::Offline)).await;
|
||||
warn!("Could not submit location! {e:?}");
|
||||
} else {
|
||||
info!("Location published");
|
||||
motion.send(Measurement::SensorHardwareStatus(SensorSource::Cloud, SensorState::Online)).await;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
motion.send(Measurement::SensorHardwareStatus(SensorSource::Cloud, SensorState::Offline)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user