From 7f4a88072047f16cc473d8d953d797ea8bb54752 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Fri, 26 Jan 2024 09:04:06 +1100 Subject: [PATCH] webui shutoff voltage + better start/stop requests --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/server/mod.rs | 50 ++++++++++++++++++++++++-------- src/tesla_charge_rate.rs | 1 + webapp/index.html | 1 + webapp/script.js | 60 +++++++++++++++++++++++++++++++++++++-- webapp/shutoff/index.html | 29 +++++++++++++++++++ 7 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 webapp/shutoff/index.html diff --git a/Cargo.lock b/Cargo.lock index c7dbdd4..423c60e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2633,7 +2633,7 @@ dependencies = [ [[package]] name = "tesla-charge-controller" -version = "1.0.29" +version = "1.0.30" dependencies = [ "chrono", "clap 4.4.11", diff --git a/Cargo.toml b/Cargo.toml index 6645351..21cc1e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tesla-charge-controller" -version = "1.0.29" +version = "1.0.30" edition = "2021" license = "MITNFA" description = "Controls Tesla charge rate based on solar charge data" diff --git a/src/server/mod.rs b/src/server/mod.rs index 34b8e94..e8dfaad 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -62,6 +62,9 @@ fn rocket(state: ServerState) -> rocket::Rocket { flash, disable_control, enable_control, + set_shutoff, + set_shutoff_time, + shutoff_status, set_max, set_min, set_proportional_gain, @@ -125,27 +128,50 @@ async fn flash(state: &State, remote_addr: std::net::IpAddr) { #[post("/disable-control")] async fn disable_control(state: &State, remote_addr: std::net::IpAddr) { log::warn!("disabling control: {remote_addr:?}"); - match state - .tcrc_requests - .send(TcrcRequest::DisableAutomaticControl) - { - Ok(_) => {} - Err(e) => log::error!("Error sending stop control request: {e:?}"), + match state.tcrc_state.write() { + Ok(mut handle) => handle.control_enable = false, + Err(e) => log::error!("Error disabling control: {e:?}"), } } #[post("/enable-control")] async fn enable_control(state: &State, remote_addr: std::net::IpAddr) { log::warn!("enabling control: {remote_addr:?}"); - match state - .tcrc_requests - .send(TcrcRequest::EnableAutomaticControl) - { - Ok(_) => {} - Err(e) => log::error!("Error sending stop control request: {e:?}"), + match state.tcrc_state.write() { + Ok(mut handle) => handle.control_enable = true, + Err(e) => log::error!("Error enabling control: {e:?}"), } } +#[post("/shutoff/voltage/")] +async fn set_shutoff(voltage: f64, remote_addr: std::net::IpAddr) { + log::warn!("setting shutoff voltage: {remote_addr:?}"); + let voltage = voltage.clamp(40., 60.); + write_to_config().shutoff_voltage = voltage; +} + +#[post("/shutoff/time/