cleanup reboot logic, fix json upload

This commit is contained in:
2025-01-04 00:04:40 +01:00
parent 0f77ac163a
commit c070e68349
5 changed files with 196 additions and 92 deletions

View File

@@ -10,7 +10,17 @@ use chrono_tz::{Europe::Berlin, Tz};
use config::Mode;
use esp_idf_hal::delay::Delay;
use esp_idf_sys::{
esp_deep_sleep, esp_ota_get_app_partition_count, esp_ota_get_running_partition, esp_ota_get_state_partition, esp_ota_img_states_t, esp_ota_img_states_t_ESP_OTA_IMG_ABORTED, esp_ota_img_states_t_ESP_OTA_IMG_INVALID, esp_ota_img_states_t_ESP_OTA_IMG_NEW, esp_ota_img_states_t_ESP_OTA_IMG_PENDING_VERIFY, esp_ota_img_states_t_ESP_OTA_IMG_UNDEFINED, esp_ota_img_states_t_ESP_OTA_IMG_VALID, esp_restart, esp_sleep_enable_ext1_wakeup, esp_sleep_ext1_wakeup_mode_t_ESP_EXT1_WAKEUP_ANY_LOW, vTaskDelay, CONFIG_FREERTOS_HZ
esp_ota_get_app_partition_count,
esp_ota_get_running_partition,
esp_ota_get_state_partition,
esp_ota_img_states_t,
esp_ota_img_states_t_ESP_OTA_IMG_ABORTED,
esp_ota_img_states_t_ESP_OTA_IMG_INVALID,
esp_ota_img_states_t_ESP_OTA_IMG_NEW,
esp_ota_img_states_t_ESP_OTA_IMG_PENDING_VERIFY,
esp_ota_img_states_t_ESP_OTA_IMG_UNDEFINED,
esp_ota_img_states_t_ESP_OTA_IMG_VALID,
vTaskDelay
};
use log::error;
use once_cell::sync::Lazy;
@@ -460,8 +470,7 @@ fn safe_main() -> anyhow::Result<()> {
board.last_pump_time(plant);
state.active = true;
for _ in 0..plant_config.pump_time_s {
unsafe { vTaskDelay(CONFIG_FREERTOS_HZ) };
//info message or something?
Delay::new_default().delay_ms(1000);
}
board.pump(plant, false)?;
@@ -557,10 +566,7 @@ fn safe_main() -> anyhow::Result<()> {
let _webserver = httpd(reboot_now.clone());
wait_infinity(WaitType::MqttConfig, reboot_now.clone());
}
unsafe {
esp_sleep_enable_ext1_wakeup(0b10u64, esp_sleep_ext1_wakeup_mode_t_ESP_EXT1_WAKEUP_ANY_LOW);
esp_deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64)
};
board.deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64);
}
fn publish_battery_state(
@@ -949,8 +955,7 @@ fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
}
}
if reboot_now.load(std::sync::atomic::Ordering::Relaxed) {
println!("Rebooting");
esp_restart();
BOARD_ACCESS.lock().unwrap().deep_sleep( 1);
}
}
}
@@ -961,7 +966,7 @@ fn main() {
match result {
Ok(_) => {
println!("Main app finished, restarting");
unsafe { esp_restart() };
BOARD_ACCESS.lock().unwrap().deep_sleep(1);
}
Err(err) => {
println!("Failed main {}", err);