Merge branch 'feature/12v' of https://git.mannheim.ccc.de/C3MA/PlantCtrl into feature/12v

This commit is contained in:
Empire 2024-02-24 16:26:01 +01:00
commit 3110f25d80
6 changed files with 27 additions and 14 deletions

View File

@ -4,8 +4,9 @@ target = "xtensa-esp32-espidf"
[target.xtensa-esp32-espidf]
linker = "ldproxy"
#runner = "espflash flash --monitor --partition-table partitions.csv" # Select this runner for espflash v2.x.x
#runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv" # Select this runner for espflash v2.x.x
runner = "cargo runner"
# runner = espflash erase-parts otadata
runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv" # Select this runner for espflash v2.x.x
#runner = "cargo runner"
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110
[unstable]
@ -16,4 +17,4 @@ MCU="esp32"
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
ESP_IDF_VERSION = "v5.1.1"
CHRONO_TZ_TIMEZONE_FILTER="UTC|Europe/Berlin"
CARGO_WORKSPACE_DIR = { value = "", relative = true }
CARGO_WORKSPACE_DIR = { value = "", relative = true }

View File

@ -76,7 +76,7 @@ serde_json = "1.0.108"
strum = { version = "0.26.1", features = ["derive"] }
once_cell = "1.19.0"
measurements = "0.11.0"
bq34z100 = "0.1.0"
bq34z100 = "0.2.1"
[build-dependencies]
embuild = "0.31.3"

View File

@ -25,7 +25,7 @@ fn main() {
}
Err(_) => {
println!("Assuming build on linux");
let output = Command::new("bash")
let output = Command::new("npx")
.arg("webpack")
.current_dir("./src_webpack")
.output()

View File

@ -236,8 +236,10 @@ fn safe_main() -> anyhow::Result<()> {
};
println!("attempting to connect wifi");
let mut ip_address: Option<String> = None;
match board.wifi(wifi.ssid, wifi.password, 10000) {
Ok(_) => {
Ok(ip_info) => {
ip_address = Some(ip_info.ip.to_string());
online_mode = OnlineMode::Wifi;
}
Err(_) => {
@ -292,6 +294,14 @@ fn safe_main() -> anyhow::Result<()> {
}
if online_mode == OnlineMode::Online {
match ip_address {
Some(add_some) => {
let _ = board.mqtt_publish(&config, "/firmware/address", add_some.as_bytes());
},
None => {
let _ = board.mqtt_publish(&config, "/firmware/address", "N/A?".as_bytes());
},
}
let _ = board.mqtt_publish(&config, "/firmware/githash", git_hash.as_bytes());
let _ = board.mqtt_publish(&config, "/firmware/buildtime", build_timestamp.as_bytes());
let _ = board.mqtt_publish(&config, "/firmware/last_online", europe_time.to_rfc3339().as_bytes());
@ -690,7 +700,7 @@ fn determine_tank_state(
);
})
.and_then(|percent| {
rv.left_ml = (percent * config.tank_useable_ml as f32) as u32;
rv.left_ml = ((percent * config.tank_useable_ml as f32) / 100_f32) as u32;
println!(
"Tank sensor returned mv {} as {}% leaving {} ml useable",
rv.raw, percent as u8, rv.left_ml
@ -702,12 +712,12 @@ fn determine_tank_state(
percent as u8, config.tank_warn_percent
);
}
if config.tank_empty_percent > percent as u8 {
if config.tank_empty_percent < percent as u8 {
println!(
"Empty water, current percent is {}, minimum empty level is {}",
"Enough water, current percent is {}, minimum empty level is {}",
percent as u8, config.tank_empty_percent
);
rv.enough_water = false;
rv.enough_water = true;
}
return Ok(());
});

View File

@ -7,6 +7,7 @@ use embedded_svc::wifi::{
use esp_idf_hal::i2c::{I2cConfig, I2cDriver, I2cError};
use esp_idf_hal::units::FromValueType;
use esp_idf_svc::eventloop::EspSystemEventLoop;
use esp_idf_svc::ipv4::IpInfo;
use esp_idf_svc::mqtt::client::QoS::AtLeastOnce;
use esp_idf_svc::mqtt::client::QoS::ExactlyOnce;
use esp_idf_svc::mqtt::client::{EspMqttClient, LwtConfiguration, MqttClientConfiguration};
@ -94,7 +95,7 @@ pub trait PlantCtrlBoardInteraction {
ssid: heapless::String<32>,
password: Option<heapless::String<64>>,
max_wait: u32,
) -> Result<()>;
) -> Result<IpInfo>;
fn sntp(&mut self, max_wait: u32) -> Result<chrono::DateTime<Utc>>;
fn mount_file_system(&mut self) -> Result<()>;
fn file_system_size(&mut self) -> Result<FileSystemSizeInfo>;
@ -393,7 +394,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
ssid: heapless::String<32>,
password: Option<heapless::String<64>>,
max_wait: u32,
) -> Result<()> {
) -> Result<IpInfo> {
match password {
Some(pw) => {
//TODO expect error due to invalid pw or similar! //call this during configuration and check if works, revert to config mode if not
@ -448,7 +449,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
//update freertos registers ;)
let address = self.wifi_driver.sta_netif().get_ip_info().unwrap();
println!("IP info: {:?}", address);
Ok(())
Ok(address)
}
fn mount_file_system(&mut self) -> Result<()> {
@ -620,6 +621,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
qos: AtLeastOnce,
retain: true,
}),
keep_alive_interval : Some(Duration::from_secs(60*60*2)),
//room for improvement
..Default::default()
};

View File

@ -40,7 +40,7 @@
</div>
<div>
<input type="number" min="1" max="500000" id="tank_warn_percent">
Tank Warn below mL
Tank Warn Percent (mapped in relation to empty and full)
</div>
<div>
<input type="number" min="0" max="100" id="tank_empty_percent">