fix tank calculation, update bq34 driver
This commit is contained in:
parent
3e31b4c041
commit
27bde9cc87
@ -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"
|
||||
|
@ -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()
|
||||
|
@ -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());
|
||||
@ -679,7 +689,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
|
||||
@ -691,12 +701,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(());
|
||||
});
|
||||
|
@ -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()
|
||||
};
|
||||
|
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user