diff --git a/rust/src/hal/initial_hal.rs b/rust/src/hal/initial_hal.rs index 3a944b2..2325e5e 100644 --- a/rust/src/hal/initial_hal.rs +++ b/rust/src/hal/initial_hal.rs @@ -117,4 +117,10 @@ impl<'a> BoardInteraction<'a> for Initial<'a> { fn test(&mut self) -> Result<()> { bail!("Please configure board revision") } + + fn set_config(&mut self, config: PlantControllerConfig) -> anyhow::Result<()> { + self.config = config; + self.esp.save_config(&self.config)?; + anyhow::Ok(()) + } } diff --git a/rust/src/hal/mod.rs b/rust/src/hal/mod.rs index c05b9e4..a70ba24 100644 --- a/rust/src/hal/mod.rs +++ b/rust/src/hal/mod.rs @@ -137,6 +137,7 @@ pub trait BoardInteraction<'a> { fn set_rtc_time(&mut self, time: &DateTime) -> Result<()>; fn test_pump(&mut self, plant: usize) -> Result<()>; fn test(&mut self) -> Result<()>; + fn set_config(&mut self, config: PlantControllerConfig) -> Result<()>; } pub struct FreePeripherals { diff --git a/rust/src/hal/v3_hal.rs b/rust/src/hal/v3_hal.rs index 968a066..1a32f24 100644 --- a/rust/src/hal/v3_hal.rs +++ b/rust/src/hal/v3_hal.rs @@ -629,4 +629,10 @@ impl<'a> BoardInteraction<'a> for V3<'a> { self.esp.delay.delay_ms(10); Ok(()) } + + fn set_config(&mut self, config: PlantControllerConfig) -> anyhow::Result<()> { + self.config = config; + self.esp.save_config(&self.config)?; + anyhow::Ok(()) + } } diff --git a/rust/src/hal/v4_hal.rs b/rust/src/hal/v4_hal.rs index 8fcf1bf..11b81da 100644 --- a/rust/src/hal/v4_hal.rs +++ b/rust/src/hal/v4_hal.rs @@ -543,4 +543,10 @@ impl<'a> BoardInteraction<'a> for V4<'a> { self.esp.delay.delay_ms(10); anyhow::Ok(()) } + + fn set_config(&mut self, config: PlantControllerConfig) -> anyhow::Result<()> { + self.config = config; + self.esp.save_config(&self.config)?; + anyhow::Ok(()) + } } diff --git a/rust/src/main.rs b/rust/src/main.rs index 8012341..8a0be13 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -208,7 +208,7 @@ fn safe_main() -> anyhow::Result<()> { } } - if board.board_hal.get_config().hardware.board == INITIAL { + if board.board_hal.get_config().hardware.board == INITIAL && board.board_hal.get_config().network.ssid.is_none(){ let _ = board.board_hal.get_esp().wifi_ap(); drop(board); let reboot_now = Arc::new(AtomicBool::new(false)); diff --git a/rust/src/webserver/webserver.rs b/rust/src/webserver/webserver.rs index f4bb27c..1bf0a45 100644 --- a/rust/src/webserver/webserver.rs +++ b/rust/src/webserver/webserver.rs @@ -219,9 +219,7 @@ fn set_config( let config: PlantControllerConfig = serde_json::from_slice(&all)?; let mut board = BOARD_ACCESS.lock().expect("board access"); - board.board_hal.get_esp().save_config(&config)?; - -//TODO fixme board.config = config; + board.board_hal.set_config(config); anyhow::Ok(Some("saved".to_owned())) }