Compare commits

..

3 Commits

Author SHA1 Message Date
bfb19321fd stuff 2024-04-27 19:58:56 +02:00
1fc04a58a0 stuff 2024-04-26 18:52:53 +02:00
d8044b8e34 clippy adjustments 2024-04-25 20:26:58 +02:00
5 changed files with 62 additions and 35 deletions

View File

@ -18918,6 +18918,16 @@
) )
(uuid "491f884a-ca01-4332-91f5-1fdea04f1b4a") (uuid "491f884a-ca01-4332-91f5-1fdea04f1b4a")
) )
(text "Q is low due to reset being on ground -> in the same pot this prevents the charge cycle of another oscilator"
(exclude_from_sim no)
(at 467.106 32.766 0)
(effects
(font
(size 1.27 1.27)
)
)
(uuid "535edc01-7355-4883-adfe-aeb4f4fbc903")
)
(text "Low Power supply" (text "Low Power supply"
(exclude_from_sim no) (exclude_from_sim no)
(at 60.96 703.58 0) (at 60.96 703.58 0)

View File

@ -47,7 +47,6 @@ embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-
[dependencies] [dependencies]
log = { version = "0.4", default-features = false } log = { version = "0.4", default-features = false }
esp-idf-svc = { version = "0.48.0", default-features = false }
serde = { version = "1.0.192", features = ["derive"] } serde = { version = "1.0.192", features = ["derive"] }
average = { version = "0.14.1" , features = ["std"] } average = { version = "0.14.1" , features = ["std"] }
#esp32 = "0.28.0" #esp32 = "0.28.0"
@ -56,6 +55,7 @@ ds18b20 = "0.1.1"
embedded-svc = { version = "0.27.0", features = ["experimental"] } embedded-svc = { version = "0.27.0", features = ["experimental"] }
esp-idf-hal = "0.43.0" esp-idf-hal = "0.43.0"
esp-idf-sys = { version = "0.34.0", features = ["binstart", "native"] } esp-idf-sys = { version = "0.34.0", features = ["binstart", "native"] }
esp-idf-svc = { version = "0.48.0", default-features = false }
esp_idf_build = "0.1.3" esp_idf_build = "0.1.3"
chrono = { version = "0.4.23", default-features = false , features = ["iana-time-zone" , "alloc"] } chrono = { version = "0.4.23", default-features = false , features = ["iana-time-zone" , "alloc"] }
chrono-tz = {version="0.8.0", default-features = false , features = [ "filter-by-regex" ]} chrono-tz = {version="0.8.0", default-features = false , features = [ "filter-by-regex" ]}
@ -69,6 +69,13 @@ strum = { version = "0.26.1", features = ["derive"] }
once_cell = "1.19.0" once_cell = "1.19.0"
measurements = "0.11.0" measurements = "0.11.0"
bq34z100 = "0.2.1" bq34z100 = "0.2.1"
bitbang-hal = "0.3.2"
[patch.crates-io]
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal.git" }
#esp-idf-sys = { git = "https://github.com/empirephoenix/esp-idf-sys.git" }
#esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys.git" }
#esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc.git" }
[build-dependencies] [build-dependencies]
embuild = "0.31.3" embuild = "0.31.3"

View File

@ -1123,24 +1123,24 @@ fn update_plant_state(
} }
} }
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/active", plant + 1).as_str(), format!("/plant{}/active", plant + 1).as_str(),
state.active.to_string().as_bytes(), state.active.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor A", plant + 1).as_str(), format!("/plant{}/Sensor A", plant + 1).as_str(),
option_to_string(state.a).as_bytes(), option_to_string(state.a).as_bytes(),
); );
if plant_config.sensor_b { if plant_config.sensor_b {
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor B", plant + 1).as_str(), format!("/plant{}/Sensor B", plant + 1).as_str(),
option_to_string(state.b).as_bytes(), option_to_string(state.b).as_bytes(),
); );
} else { } else {
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor B", plant + 1).as_str(), format!("/plant{}/Sensor B", plant + 1).as_str(),
"disabled".as_bytes(), "disabled".as_bytes(),
); );
@ -1148,70 +1148,70 @@ fn update_plant_state(
if plant_config.sensor_p { if plant_config.sensor_p {
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor P before", plant + 1).as_str(), format!("/plant{}/Sensor P before", plant + 1).as_str(),
option_to_string(state.p).as_bytes(), option_to_string(state.p).as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor P after", plant + 1).as_str(), format!("/plant{}/Sensor P after", plant + 1).as_str(),
option_to_string(state.after_p).as_bytes(), option_to_string(state.after_p).as_bytes(),
); );
} else { } else {
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor P before", plant + 1).as_str(), format!("/plant{}/Sensor P before", plant + 1).as_str(),
"disabled".as_bytes(), "disabled".as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Sensor P after", plant + 1).as_str(), format!("/plant{}/Sensor P after", plant + 1).as_str(),
"disabled".as_bytes(), "disabled".as_bytes(),
); );
} }
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Should water", plant + 1).as_str(), format!("/plant{}/Should water", plant + 1).as_str(),
state.do_water.to_string().as_bytes(), state.do_water.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Is frozen", plant + 1).as_str(), format!("/plant{}/Is frozen", plant + 1).as_str(),
state.frozen.to_string().as_bytes(), state.frozen.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Is dry", plant + 1).as_str(), format!("/plant{}/Is dry", plant + 1).as_str(),
state.dry.to_string().as_bytes(), state.dry.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Pump Error", plant + 1).as_str(), format!("/plant{}/Pump Error", plant + 1).as_str(),
state.pump_error.to_string().as_bytes(), state.pump_error.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Pump Ineffective", plant + 1).as_str(), format!("/plant{}/Pump Ineffective", plant + 1).as_str(),
state.not_effective.to_string().as_bytes(), state.not_effective.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Is in Cooldown", plant + 1).as_str(), format!("/plant{}/Is in Cooldown", plant + 1).as_str(),
state.cooldown.to_string().as_bytes(), state.cooldown.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/No Water", plant + 1).as_str(), format!("/plant{}/No Water", plant + 1).as_str(),
state.no_water.to_string().as_bytes(), state.no_water.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/Out of Work Hour", plant + 1).as_str(), format!("/plant{}/Out of Work Hour", plant + 1).as_str(),
state.out_of_work_hour.to_string().as_bytes(), state.out_of_work_hour.to_string().as_bytes(),
); );
let _ = board.mqtt_publish( let _ = board.mqtt_publish(
&config, config,
format!("/plant{}/consecutive pump count", plant + 1).as_str(), format!("/plant{}/consecutive pump count", plant + 1).as_str(),
state.consecutive_pump_count.to_string().as_bytes(), state.consecutive_pump_count.to_string().as_bytes(),
); );

View File

@ -42,9 +42,11 @@ use esp_idf_hal::prelude::Peripherals;
use esp_idf_hal::reset::ResetReason; use esp_idf_hal::reset::ResetReason;
use esp_idf_svc::sntp::{self, SyncStatus}; use esp_idf_svc::sntp::{self, SyncStatus};
use esp_idf_svc::systime::EspSystemTime; use esp_idf_svc::systime::EspSystemTime;
use esp_idf_sys::{gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError}; use esp_idf_sys::{esp, gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError};
use one_wire_bus::OneWire; use one_wire_bus::OneWire;
use bitbang_hal;
use crate::config::{self, Config, WifiConfig}; use crate::config::{self, Config, WifiConfig};
use crate::STAY_ALIVE; use crate::STAY_ALIVE;
@ -676,7 +678,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
} }
} }
} }
embedded_svc::mqtt::client::EventPayload::Connected(session_present) => { embedded_svc::mqtt::client::EventPayload::Connected(_) => {
mqtt_connected_event_received_copy mqtt_connected_event_received_copy
.store(true, std::sync::atomic::Ordering::Relaxed); .store(true, std::sync::atomic::Ordering::Relaxed);
mqtt_connected_event_ok_copy mqtt_connected_event_ok_copy
@ -690,7 +692,8 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
.store(false, std::sync::atomic::Ordering::Relaxed); .store(false, std::sync::atomic::Ordering::Relaxed);
println!("Mqtt disconnected"); println!("Mqtt disconnected");
} }
embedded_svc::mqtt::client::EventPayload::Error(espError) => { embedded_svc::mqtt::client::EventPayload::Error(esp_error) => {
println!("EspMqttError reported {:?}", esp_error);
mqtt_connected_event_received_copy mqtt_connected_event_received_copy
.store(true, std::sync::atomic::Ordering::Relaxed); .store(true, std::sync::atomic::Ordering::Relaxed);
mqtt_connected_event_ok_copy mqtt_connected_event_ok_copy
@ -705,7 +708,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
let wait_for_connections_event = 0; let wait_for_connections_event = 0;
while wait_for_connections_event < 100 { while wait_for_connections_event < 100 {
match true { //mqtt_connected_event_received.load(std::sync::atomic::Ordering::Relaxed) { match mqtt_connected_event_received.load(std::sync::atomic::Ordering::Relaxed) {
true => { true => {
println!("Mqtt connection callback received, progressing"); println!("Mqtt connection callback received, progressing");
match mqtt_connected_event_ok.load(std::sync::atomic::Ordering::Relaxed) { match mqtt_connected_event_ok.load(std::sync::atomic::Ordering::Relaxed) {
@ -893,6 +896,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
fn print_battery( fn print_battery(
battery_driver: &mut Bq34z100g1Driver<I2cDriver, Delay>, battery_driver: &mut Bq34z100g1Driver<I2cDriver, Delay>,
) -> Result<(), Bq34Z100Error<I2cError>> { ) -> Result<(), Bq34Z100Error<I2cError>> {
println!("Try communicating with battery");
let fwversion = battery_driver.fw_version().unwrap_or_else(|e| { let fwversion = battery_driver.fw_version().unwrap_or_else(|e| {
println!("Firmeware {:?}", e); println!("Firmeware {:?}", e);
0 0
@ -951,18 +955,24 @@ impl CreatePlantHal<'_> for PlantHal {
fn create() -> Result<Mutex<PlantCtrlBoard<'static>>> { fn create() -> Result<Mutex<PlantCtrlBoard<'static>>> {
let peripherals = Peripherals::take()?; let peripherals = Peripherals::take()?;
let i2c = peripherals.i2c0; let i2c = peripherals.i2c0;
let config = I2cConfig::new() let config = I2cConfig::new()
.scl_enable_pullup(false) .scl_enable_pullup(false)
.sda_enable_pullup(false) .sda_enable_pullup(false)
.baudrate(10_u32.kHz().into()); .baudrate(1_u32.kHz().into())
.timeout(Duration::from_millis(10).into());
let scl = peripherals.pins.gpio19; let scl = peripherals.pins.gpio19;
let sda = peripherals.pins.gpio20; let sda = peripherals.pins.gpio20;
let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap(); let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap();
//let i2c_port = driver.port(); let i2c_port = driver.port();
//esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 2)}).unwrap(); let mut timeout:i32 = 0;
esp!(unsafe { esp_idf_sys::i2c_get_timeout(i2c_port, &mut timeout)}).unwrap();
println!("Default i2c timeout is {}", timeout);
//esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 1)}).unwrap();
let mut battery_driver: Bq34z100g1Driver<I2cDriver, Delay> = Bq34z100g1Driver { let mut battery_driver: Bq34z100g1Driver<I2cDriver, Delay> = Bq34z100g1Driver {
i2c: driver, i2c: driver,
@ -1100,12 +1110,12 @@ impl CreatePlantHal<'_> for PlantHal {
println!("After stuff"); println!("After stuff");
//let status = print_battery(&mut battery_driver); let status = print_battery(&mut battery_driver);
//if status.is_err() { if status.is_err() {
// println!("Error communicating with battery!! {:?}", status.err()); println!("Error communicating with battery!! {:?}", status.err());
//} else { } else {
// println!("Managed to comunnicate with battery"); println!("Managed to comunnicate with battery");
//} }
let rv = Mutex::new(PlantCtrlBoard { let rv = Mutex::new(PlantCtrlBoard {
shift_register, shift_register,
tank_driver, tank_driver,
@ -1120,8 +1130,8 @@ impl CreatePlantHal<'_> for PlantHal {
signal_counter: counter_unit1, signal_counter: counter_unit1,
wifi_driver, wifi_driver,
mqtt_client: None, mqtt_client: None,
battery_driver: None, //battery_driver: None,
//Some(battery_driver), battery_driver: Some(battery_driver)
}); });
Ok(rv) Ok(rv)
} }