diff --git a/src/bin/main.rs b/src/bin/main.rs index b168079..20c4123 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -191,7 +191,7 @@ async fn main(spawner: Spawner) { //spawner.must_spawn(renderbug_embassy::tasks::wifi::wifi_connect_task(wifi, stack, motion_bus.dyn_sender())); info!("Launching HTTP telemetry"); - //spawner.must_spawn(renderbug_embassy::tasks::wifi::http_telemetry_task(predictions.dyn_subscriber().unwrap(), stack)); + spawner.must_spawn(renderbug_bike::tasks::wifi::http_telemetry_task(predictions.dyn_subscriber().unwrap(), stack, motion_bus.dyn_sender())); info!("Starting BLE services"); spawner.must_spawn(renderbug_embassy::tasks::ble::ble_task(ble, predictions.dyn_subscriber().unwrap(), spawner)); diff --git a/src/tasks/wifi.rs b/src/tasks/wifi.rs index e9daf8c..b5276d3 100644 --- a/src/tasks/wifi.rs +++ b/src/tasks/wifi.rs @@ -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; } } }