diff --git a/Cargo.lock b/Cargo.lock index d608cde..973f903 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,6 +175,7 @@ dependencies = [ "base64", "log", "serialport", + "strum", "tokio", ] @@ -232,6 +233,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -688,6 +695,28 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "syn" version = "2.0.39" diff --git a/Cargo.toml b/Cargo.toml index db21efe..e0c5214 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ axum = "0.6.20" base64 = "0.21.5" log = "0.4.20" serialport = "4.2.2" +strum = { version = "0.25.0", features = ["derive"] } tokio = { version = "1.34.0", features = ["full"] } diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..518ecf1 --- /dev/null +++ b/src/index.html @@ -0,0 +1,43 @@ + + + +
+ + + + +Temperatur: {0} °C
+Temperatur Min: {1} °C
+Temperatur Max: {2} °C
+Solltemperatur Solar: {3} °C
+Solltemperatur Netz: {4} °C
+ +Spannung: {5} V
+Strom: {6} A
+Leistung: {7} kW
+ +Solarenergie Heute: {8} kWh
+Solarenergie Gesamt: {9} kWh
+Netzenergie Heute: {10} kWh
+ +Isolationsmessung: {11}
+Gerätetemperatur: {12}
+Status: {13}
+DC Trenner: {14}
+DC Relais: {15}
+AC Relais: {16}
+ +Betriebstag: {17}
+Firmware: {18}
+Seriennummer: {19}
+ + \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 349387e..582b75d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,60 +1,155 @@ -use axum::{routing::get, Router}; +use axum::{response::Html, routing::get, Router}; +use strum::{EnumIter, IntoEnumIterator}; -const STATUS_KEYS: &'static [&str] = &[ - "dummy0", - "firmware", - "Betriebstag", - "Status", - "DcTrenner", - "DcRelais", - "AcRelais", - "Wassertemp", - "WassertempMin", - "WassertempMax", - "SolltempSolar", - "SolltempNetz", - "GeraeteTemp", - "IsoMessung", - "Solarspannung", - "dummy5", - "Solarstrom", - "Solarleistung", - "SolarenergieHeute", - "SolarenergieGesammt", - "Netzernergie", - "dummy6", - "dummy7", - "dummy8", - "dummy9", - "dummy10", - "dummy11", - "dummy12", - "Seriennummer", - "dummy13", -]; +#[derive(EnumIter, Debug)] +enum StatusTag { + Dummy0, + Firmware, + Betriebstag, + Status, + DcTrenner, + DcRelais, + AcRelais, + Wassertemp, + WassertempMin, + WassertempMax, + SolltempSolar, + SolltempNetz, + GeraeteTemp, + IsoMessung, + Solarspannung, + Dummy5, + Solarstrom, + Solarleistung, + SolarenergieHeute, + SolarenergieGesamt, + NetzenergieHeute, + Dummy6, + Dummy7, + Dummy8, + Dummy9, + Dummy10, + Dummy11, + Dummy12, + Seriennummer, + Dummy13, +} + +#[derive(Default, Debug)] +struct Status<'a> { + // Wasser + wassertemp: f32, + wassertemp_min: f32, + wassertemp_max: f32, + solltemp_solar: f32, + solltemp_netz: f32, + + // Solar aktuell + solarspannung: f32, + solarstrom: f32, + solarleistung: f32, + + // Historie + solarenergie_heute: f32, + solarenergie_gesamt: f32, + netzenergie_heute: f32, + + // Zustand + iso_messung: u32, + geraetetemp: u32, + status: u32, + dc_trenner: bool, + dc_relais: bool, + ac_relais: bool, + + // Misc + betriebstag: u32, + firmware: &'a str, + seriennummer: &'a str, +} #[tokio::main] async fn main() { let app = Router::new().route("/", get(handler)); - axum::Server::bind(&"0.0.0.0:3001".parse().unwrap()) + axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) .serve(app.into_make_service()) .await .unwrap(); } -async fn handler() -> String { +async fn handler() -> Html