diff --git a/Software/MainBoard/rust/src/log/mod.rs b/Software/MainBoard/rust/src/log/mod.rs index 7a25d8e..24604ff 100644 --- a/Software/MainBoard/rust/src/log/mod.rs +++ b/Software/MainBoard/rust/src/log/mod.rs @@ -319,6 +319,8 @@ pub enum LogMessage { Trace, #[strum(serialize = "Parsing error reading message")] UnknownMessage, + #[strum(serialize = "Going to deep sleep for ${number_a} minutes")] + DeepSleep, } #[derive(Serialize)] diff --git a/Software/MainBoard/rust/src/main.rs b/Software/MainBoard/rust/src/main.rs index ec20507..bf26924 100644 --- a/Software/MainBoard/rust/src/main.rs +++ b/Software/MainBoard/rust/src/main.rs @@ -445,7 +445,17 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> { board.board_hal.get_esp().last_pump_time(plant_id); //state.active = true; - pump_info(&mut board, plant_id, true, pump_ineffective, 0, 0, 0, String::new()).await; + pump_info( + &mut board, + plant_id, + true, + pump_ineffective, + 0, + 0, + 0, + String::new(), + ) + .await; let result = do_secure_pump(&mut board, plant_id, plant_config, dry_run).await; match result { @@ -460,7 +470,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> { state.min_current_ma, state.error, ) - .await; + .await; } Err(err) => { pump_info( @@ -473,12 +483,11 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> { 0, format!("{err:?}"), ) - .await; + .await; } } //stop pump regardless of prior result//todo refactor to inner? board.board_hal.pump(plant_id, false).await?; - } else if !state.pump_in_timeout(plant_config, &timezone_time) { // plant does not need to be watered and is not in timeout // -> reset consecutive pump count @@ -490,8 +499,16 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> { } } else { // Pump corrosion protection: pulses each pump once a week for 2s around midday. - let last_check_day = board.board_hal.get_esp().get_last_corrosion_protection_check_day(); - if board.board_hal.get_config().hardware.pump_corrosion_protection { + let last_check_day = board + .board_hal + .get_esp() + .get_last_corrosion_protection_check_day(); + if board + .board_hal + .get_config() + .hardware + .pump_corrosion_protection + { let current_day = timezone_time.weekday().number_from_monday() as i8; let current_hour = timezone_time.hour(); @@ -500,19 +517,32 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> { if last_check_day != current_day { info!("Running pump corrosion protection"); for plant_id in 0..PLANT_COUNT { - let mut plant_config = board.board_hal.get_config().plants[plant_id].clone(); + let mut plant_config = + board.board_hal.get_config().plants[plant_id].clone(); plant_config.pump_time_s = 2; plant_config.pump_limit_ml = 1000; // high limit to ensure it runs for 2s - log(LogMessage::PumpPlant, (plant_id + 1) as u32, 2, "corrosion_prot", ""); + log( + LogMessage::PumpPlant, + (plant_id + 1) as u32, + 2, + "corrosion_prot", + "", + ); let _ = do_secure_pump(&mut board, plant_id, &plant_config, dry_run).await; let _ = board.board_hal.pump(plant_id, false).await; } - board.board_hal.get_esp().set_last_corrosion_protection_check_day(current_day); + board + .board_hal + .get_esp() + .set_last_corrosion_protection_check_day(current_day); } } else if last_check_day != current_day && current_day != 1 { // Reset check day if it's a different day (and not Monday), so it can trigger again next week - board.board_hal.get_esp().set_last_corrosion_protection_check_day(-1); + board + .board_hal + .get_esp() + .set_last_corrosion_protection_check_day(-1); } } } @@ -650,6 +680,13 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> { } } else { //TODO wait for all mqtt publishes? + log( + LogMessage::DeepSleep, + deep_sleep_duration_minutes, + 0, + "", + "", + ); Timer::after_millis(5000).await; board.board_hal.get_esp().set_restart_to_conf(false); @@ -1126,7 +1163,7 @@ async fn wait_infinity( let timezone_time = cur.with_timezone(&timezone); let esp = board.board_hal.get_esp(); - esp.mqtt_publish("/firmware/state", "config").await; + esp.mqtt_publish("/state", "config").await; esp.mqtt_publish("/firmware/last_online", &timezone_time.to_rfc3339()) .await; last_mqtt_update = Some(now);