From be9a076b335e12c01b7232b9036cc6231212dd7f Mon Sep 17 00:00:00 2001 From: ju6ge Date: Sat, 21 Jun 2025 11:07:10 +0200 Subject: [PATCH 1/5] add configuration options to enable mqtt user login --- rust/src/config.rs | 4 ++++ rust/src/hal/esp.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/rust/src/config.rs b/rust/src/config.rs index 0c37085..5ac1426 100644 --- a/rust/src/config.rs +++ b/rust/src/config.rs @@ -11,6 +11,8 @@ pub struct NetworkConfig { pub password: Option>, pub mqtt_url: Option>, pub base_topic: Option>, + pub mqtt_user: Option>, + pub mqtt_password: Option>, pub max_wait: u32, } impl Default for NetworkConfig { @@ -21,6 +23,8 @@ impl Default for NetworkConfig { password: None, mqtt_url: None, base_topic: None, + mqtt_user: None, + mqtt_password: None, max_wait: 10000, } } diff --git a/rust/src/hal/esp.rs b/rust/src/hal/esp.rs index fe99d5e..72304d7 100644 --- a/rust/src/hal/esp.rs +++ b/rust/src/hal/esp.rs @@ -419,6 +419,8 @@ impl Esp<'_> { }), client_id: Some("plantctrl"), keep_alive_interval: Some(Duration::from_secs(60 * 60 * 2)), + username: network_config.mqtt_user.as_ref().map(|v| &**v), + password: network_config.mqtt_password.as_ref().map(|v| &**v), //room for improvement ..Default::default() }; From e7895577ca4b1f852c2b8363eb522a4c753fedc1 Mon Sep 17 00:00:00 2001 From: ju6ge Date: Sun, 20 Jul 2025 16:09:37 +0200 Subject: [PATCH 2/5] update frontent to include inputs for mqtt auth --- rust/src_webpack/src/api.ts | 2 ++ rust/src_webpack/src/network.html | 14 +++++++++++++- rust/src_webpack/src/network.ts | 12 +++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/rust/src_webpack/src/api.ts b/rust/src_webpack/src/api.ts index e02ed93..3f13702 100644 --- a/rust/src_webpack/src/api.ts +++ b/rust/src_webpack/src/api.ts @@ -29,6 +29,8 @@ export interface NetworkConfig { password: string, mqtt_url: string, base_topic: string, + mqtt_user: string | null, + mqtt_password: string | null, max_wait: number } diff --git a/rust/src_webpack/src/network.html b/rust/src_webpack/src/network.html index 5bdca8d..7d0a56b 100644 --- a/rust/src_webpack/src/network.html +++ b/rust/src_webpack/src/network.html @@ -72,8 +72,20 @@ +
+
+ MQTT User +
+ +
+
+
+ MQTT Password +
+ +
- \ No newline at end of file + diff --git a/rust/src_webpack/src/network.ts b/rust/src_webpack/src/network.ts index df1ffbd..f26b659 100644 --- a/rust/src_webpack/src/network.ts +++ b/rust/src_webpack/src/network.ts @@ -16,6 +16,8 @@ export class NetworkConfigView { private readonly mqtt_url: HTMLInputElement; private readonly base_topic: HTMLInputElement; private readonly max_wait: HTMLInputElement; + private readonly mqtt_user: HTMLInputElement; + private readonly mqtt_password: HTMLInputElement; private readonly ssidlist: HTMLElement; constructor(controller: Controller, publicIp: string) { @@ -37,6 +39,10 @@ export class NetworkConfigView { this.mqtt_url.onchange = controller.configChanged this.base_topic = document.getElementById("base_topic") as HTMLInputElement; this.base_topic.onchange = controller.configChanged + this.mqtt_user = document.getElementById("mqtt_user") as HTMLInputElement; + this.mqtt_user.onchange = controller.configChanged + this.mqtt_password = document.getElementById("mqtt_password") as HTMLInputElement; + this.mqtt_password.onchange = controller.configChanged this.ssidlist = document.getElementById("ssidlist") as HTMLElement @@ -52,6 +58,8 @@ export class NetworkConfigView { this.password.value = network.password; this.mqtt_url.value = network.mqtt_url; this.base_topic.value = network.base_topic; + this.mqtt_user.value = network.mqtt_user ?? ""; + this.mqtt_password.value = network.mqtt_password ?? ""; this.max_wait.value = network.max_wait.toString(); } @@ -62,7 +70,9 @@ export class NetworkConfigView { ssid: this.ssid.value ?? null, password: this.password.value ?? null, mqtt_url: this.mqtt_url.value ?? null, + mqtt_user: this.mqtt_user.value ? this.mqtt_user.value : null, + mqtt_password: this.mqtt_password.value ? this.mqtt_password.value : null, base_topic: this.base_topic.value ?? null } } - } \ No newline at end of file + } From 3a24dcec53e37c9d1d86ea3bb5da119935b6deac Mon Sep 17 00:00:00 2001 From: ju6ge Date: Thu, 11 Sep 2025 19:55:20 +0200 Subject: [PATCH 3/5] add release profile --- rust/Cargo.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 80488db..fcb701f 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -17,6 +17,16 @@ incremental = true opt-level = 2 +[profile.release] +# Explicitly disable LTO which the Xtensa codegen backend has issues +lto = false +strip = true +debug = false +overflow-checks = false +panic = "abort" +incremental = true +opt-level = "z" + [package.metadata.cargo_runner] # The string `$TARGET_FILE` will be replaced with the path from cargo. command = [ From 4fa1a05fc39429061940093108bcea03e787377a Mon Sep 17 00:00:00 2001 From: ju6ge Date: Thu, 11 Sep 2025 20:04:27 +0200 Subject: [PATCH 4/5] remove duplicate import --- rust/src/hal/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rust/src/hal/mod.rs b/rust/src/hal/mod.rs index b8cfb2d..4a413cf 100644 --- a/rust/src/hal/mod.rs +++ b/rust/src/hal/mod.rs @@ -50,7 +50,6 @@ use std::result::Result::Ok as OkStd; use std::sync::Mutex; use std::time::Duration; use esp_idf_hal::can::CAN; -use esp_idf_hal::pcnt::PCNT1; //Only support for 8 right now! pub const PLANT_COUNT: usize = 8; From 4faae86a6b48ceea7736596f1b60fc89de4bd2e0 Mon Sep 17 00:00:00 2001 From: ju6ge Date: Thu, 11 Sep 2025 20:17:18 +0200 Subject: [PATCH 5/5] reduce amount of warnings --- rust/src/hal/mod.rs | 2 +- rust/src/hal/v3_hal.rs | 2 +- rust/src/hal/v4_hal.rs | 8 +++----- rust/src/main.rs | 10 +--------- rust/src/plant_state.rs | 6 +++--- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/rust/src/hal/mod.rs b/rust/src/hal/mod.rs index 4a413cf..6c4e486 100644 --- a/rust/src/hal/mod.rs +++ b/rust/src/hal/mod.rs @@ -113,7 +113,7 @@ pub trait BoardInteraction<'a> { impl dyn BoardInteraction<'_> { //the counter is just some arbitrary number that increases whenever some progress was made, try to keep the updates < 10 per second for ux reasons - fn progress(&mut self, counter: u32) { + fn _progress(&mut self, counter: u32) { let even = counter % 2 == 0; let current = counter / (PLANT_COUNT as u32); for led in 0..PLANT_COUNT { diff --git a/rust/src/hal/v3_hal.rs b/rust/src/hal/v3_hal.rs index bd9063a..3c246ed 100644 --- a/rust/src/hal/v3_hal.rs +++ b/rust/src/hal/v3_hal.rs @@ -210,7 +210,7 @@ impl<'a> BoardInteraction<'a> for V3<'a> { &self.config } - fn get_battery_monitor(&mut self) -> &mut Box<(dyn BatteryInteraction + Send + 'static)> { + fn get_battery_monitor(&mut self) -> &mut Box { &mut self.battery_monitor } diff --git a/rust/src/hal/v4_hal.rs b/rust/src/hal/v4_hal.rs index ee508f4..9833191 100644 --- a/rust/src/hal/v4_hal.rs +++ b/rust/src/hal/v4_hal.rs @@ -13,7 +13,7 @@ use anyhow::bail; use embedded_hal::digital::OutputPin; use embedded_hal_bus::i2c::MutexDevice; use esp_idf_hal::gpio::{AnyInputPin, IOPin, InputOutput, Output, PinDriver, Pull}; -use esp_idf_hal::i2c::{I2cDriver, I2cError}; +use esp_idf_hal::i2c::I2cDriver; use esp_idf_hal::pcnt::{ PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex, }; @@ -23,12 +23,10 @@ use ina219::calibration::UnCalibrated; use ina219::configuration::{Configuration, OperatingMode}; use ina219::SyncIna219; use measurements::{Current, Resistance, Voltage}; -use pca9535::{ExpanderError, GPIOBank, Pca9535Immediate, StandardExpanderInterface}; +use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface}; use std::result::Result::Ok as OkStd; -use embedded_can::nb::Can; use embedded_can::Frame; use embedded_can::StandardId; -use esp_idf_hal::prelude::*; use esp_idf_hal::can; pub enum Charger<'a> { @@ -205,7 +203,7 @@ pub(crate) fn create_v4( println!("Can bus mode "); let timing = can::config::Timing::B25K; let config = can::config::Config::new().timing(timing); - let mut can = can::CanDriver::new(peripherals.can, peripherals.gpio0, peripherals.gpio2, &config).unwrap(); + let can = can::CanDriver::new(peripherals.can, peripherals.gpio0, peripherals.gpio2, &config).unwrap(); let frame = StandardId::new(0x042).unwrap(); diff --git a/rust/src/main.rs b/rust/src/main.rs index c21a625..344947e 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -93,14 +93,6 @@ pub struct PumpResult { pump_time_s: u16, } -#[derive(Serialize, Deserialize, Debug, PartialEq)] -/// humidity sensor error -enum SensorError { - Unknown, - ShortCircuit { hz: f32, max: f32 }, - OpenCircuit { hz: f32, min: f32 }, -} - #[derive(Serialize, Debug, PartialEq)] enum SntpMode { OFFLINE, @@ -867,7 +859,7 @@ fn pump_info( median_current_ma: u16, max_current_ma: u16, min_current_ma: u16, - error: bool, + _error: bool, ) { let pump_info = PumpInfo { enabled: pump_active, diff --git a/rust/src/plant_state.rs b/rust/src/plant_state.rs index ae57373..01cdbf2 100644 --- a/rust/src/plant_state.rs +++ b/rust/src/plant_state.rs @@ -238,7 +238,7 @@ impl PlantState { } PlantWateringMode::MinMoisture => { let (moisture_percent, _) = self.plant_moisture(); - if let Some(moisture_percent) = moisture_percent { + if let Some(_moisture_percent) = moisture_percent { if self.pump_in_timeout(plant_conf, current_time) { false } else if !in_time_range( @@ -247,10 +247,10 @@ impl PlantState { plant_conf.pump_hour_end, ) { false - } else if (true) { + } else if true { //if not cooldown min and below max true - } else if (true) { + } else if true { //if below min disable cooldown min true } else {