get log to work, make time accessible
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use crate::config::{NetworkConfig, PlantControllerConfig};
|
||||
use crate::hal::{GW_IP_ADDR_ENV, PLANT_COUNT};
|
||||
use crate::log::{log, LogMessage};
|
||||
use crate::hal::{GW_IP_ADDR_ENV, PLANT_COUNT, TIME_ACCESS};
|
||||
use crate::log::{ LogArray, LogMessage, LOG_ACCESS};
|
||||
use crate::STAY_ALIVE;
|
||||
use anyhow::{anyhow, bail, Context};
|
||||
use chrono::{DateTime, Utc};
|
||||
use chrono::{DateTime, FixedOffset, Utc};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::hal::little_fs2storage_adapter::LittleFs2Filesystem;
|
||||
@@ -13,12 +13,10 @@ use alloc::{format, string::String, vec::Vec};
|
||||
use core::marker::PhantomData;
|
||||
use core::net::{IpAddr, Ipv4Addr};
|
||||
use core::str::FromStr;
|
||||
use embassy_executor::{SendSpawner, Spawner};
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{IpListenEndpoint, Ipv4Cidr, Runner, Stack, StackResources, StaticConfigV4};
|
||||
use embassy_executor::{Spawner};
|
||||
use embassy_net::{Ipv4Cidr, Runner, Stack, StackResources, StaticConfigV4};
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::mutex::Mutex;
|
||||
use embassy_sync::rwlock::TryLockError;
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use embedded_storage::nor_flash::ReadNorFlash;
|
||||
use embedded_storage::Storage;
|
||||
@@ -26,25 +24,27 @@ use esp_bootloader_esp_idf::ota::{Ota, OtaImageState, Slot};
|
||||
use esp_bootloader_esp_idf::partitions::{Error, FlashRegion, PartitionEntry, PartitionTable};
|
||||
use esp_hal::gpio::Input;
|
||||
use esp_hal::rng::Rng;
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
use esp_hal::rtc_cntl::sleep::RtcSleepConfig;
|
||||
use esp_println::{print, println};
|
||||
use esp_hal::system::software_reset;
|
||||
use esp_println::{println};
|
||||
use esp_storage::FlashStorage;
|
||||
use esp_wifi::wifi::{
|
||||
AccessPointConfiguration, AccessPointInfo, Configuration, Interfaces, ScanConfig,
|
||||
ScanTypeConfig, WifiController, WifiDevice, WifiEvent, WifiState,
|
||||
ScanTypeConfig, WifiController, WifiDevice,
|
||||
};
|
||||
use littlefs2::fs::Filesystem;
|
||||
use littlefs2_core::{DynFile, FileType, OpenSeekFrom, Path, PathBuf, SeekFrom};
|
||||
use log::{info, warn};
|
||||
use littlefs2_core::{DynFile, FileType, PathBuf, SeekFrom};
|
||||
use log::{info};
|
||||
|
||||
#[link_section = ".rtc.data"]
|
||||
#[esp_hal::ram(rtc_fast, persistent)]
|
||||
static mut LAST_WATERING_TIMESTAMP: [i64; PLANT_COUNT] = [0; PLANT_COUNT];
|
||||
#[link_section = ".rtc.data"]
|
||||
#[esp_hal::ram(rtc_fast, persistent)]
|
||||
static mut CONSECUTIVE_WATERING_PLANT: [u32; PLANT_COUNT] = [0; PLANT_COUNT];
|
||||
#[link_section = ".rtc.data"]
|
||||
static mut LOW_VOLTAGE_DETECTED: bool = false;
|
||||
#[link_section = ".rtc.data"]
|
||||
static mut RESTART_TO_CONF: bool = false;
|
||||
#[esp_hal::ram(rtc_fast, persistent)]
|
||||
static mut LOW_VOLTAGE_DETECTED: i8 = 0;
|
||||
#[esp_hal::ram(rtc_fast, persistent)]
|
||||
static mut RESTART_TO_CONF: i8 = 0;
|
||||
|
||||
static CONFIG_FILE: &str = "config.json";
|
||||
|
||||
@@ -239,10 +239,6 @@ impl Esp<'_> {
|
||||
bail!("not implemented")
|
||||
}
|
||||
|
||||
pub(crate) fn time(&mut self) -> DateTime<Utc> {
|
||||
let wall_clock = Instant::now().as_millis() + self.wall_clock_offset;
|
||||
DateTime::from_timestamp_millis(wall_clock as i64).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) async fn wifi_scan(&mut self) -> anyhow::Result<Vec<AccessPointInfo>> {
|
||||
info!("start wifi scan");
|
||||
@@ -277,17 +273,17 @@ impl Esp<'_> {
|
||||
}
|
||||
pub(crate) fn set_low_voltage_in_cycle(&mut self) {
|
||||
unsafe {
|
||||
LOW_VOLTAGE_DETECTED = true;
|
||||
LOW_VOLTAGE_DETECTED = 1;
|
||||
}
|
||||
}
|
||||
pub(crate) fn clear_low_voltage_in_cycle(&mut self) {
|
||||
unsafe {
|
||||
LOW_VOLTAGE_DETECTED = false;
|
||||
LOW_VOLTAGE_DETECTED = 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn low_voltage_in_cycle(&mut self) -> bool {
|
||||
unsafe { LOW_VOLTAGE_DETECTED }
|
||||
unsafe { LOW_VOLTAGE_DETECTED == 1 }
|
||||
}
|
||||
pub(crate) fn store_consecutive_pump_count(&mut self, plant: usize, count: u32) {
|
||||
unsafe {
|
||||
@@ -298,11 +294,15 @@ impl Esp<'_> {
|
||||
unsafe { CONSECUTIVE_WATERING_PLANT[plant] }
|
||||
}
|
||||
pub(crate) fn get_restart_to_conf(&mut self) -> bool {
|
||||
unsafe { RESTART_TO_CONF }
|
||||
unsafe { RESTART_TO_CONF == 1}
|
||||
}
|
||||
pub(crate) fn set_restart_to_conf(&mut self, to_conf: bool) {
|
||||
unsafe {
|
||||
RESTART_TO_CONF = to_conf;
|
||||
if to_conf {
|
||||
RESTART_TO_CONF = 1;
|
||||
} else {
|
||||
RESTART_TO_CONF = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,10 +374,9 @@ impl Esp<'_> {
|
||||
//unsafe {
|
||||
// //allow early wakeup by pressing the boot button
|
||||
if duration_in_ms == 0 {
|
||||
loop {
|
||||
info!("todo reboot")
|
||||
}
|
||||
software_reset();
|
||||
} else {
|
||||
|
||||
loop {
|
||||
info!("todo deepsleep")
|
||||
}
|
||||
@@ -547,31 +546,34 @@ impl Esp<'_> {
|
||||
unsafe {
|
||||
LAST_WATERING_TIMESTAMP = [0; PLANT_COUNT];
|
||||
CONSECUTIVE_WATERING_PLANT = [0; PLANT_COUNT];
|
||||
LOW_VOLTAGE_DETECTED = false;
|
||||
crate::log::init().await;
|
||||
RESTART_TO_CONF = to_config_mode;
|
||||
LOW_VOLTAGE_DETECTED = 0;
|
||||
if to_config_mode {
|
||||
RESTART_TO_CONF = 1
|
||||
} else {
|
||||
RESTART_TO_CONF = 0;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
unsafe {
|
||||
if to_config_mode {
|
||||
RESTART_TO_CONF = true;
|
||||
RESTART_TO_CONF = 1;
|
||||
}
|
||||
log(
|
||||
LOG_ACCESS.lock().await.log(
|
||||
LogMessage::RestartToConfig,
|
||||
RESTART_TO_CONF as u32,
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.await;
|
||||
log(
|
||||
).await
|
||||
;
|
||||
LOG_ACCESS.lock().await.log(
|
||||
LogMessage::LowVoltage,
|
||||
LOW_VOLTAGE_DETECTED as u32,
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.await;
|
||||
).await
|
||||
;
|
||||
for i in 0..PLANT_COUNT {
|
||||
log::info!(
|
||||
"LAST_WATERING_TIMESTAMP[{}] = UTC {}",
|
||||
|
Reference in New Issue
Block a user