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