From e4e48b98ea0f20b170ce355bab8c9c8ec8d79e11 Mon Sep 17 00:00:00 2001 From: Axel Chabrerie <114242486+Axel-ex@users.noreply.github.com> Date: Tue, 28 Oct 2025 21:08:42 +0000 Subject: [PATCH] Add watchdog timer for main task --- src/config.rs | 2 +- src/main.rs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5512ff1..14c6bf6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,7 +18,7 @@ pub struct Config { topic: &'static str, #[default(1200)] deep_sleep_dur_secs: u64, - #[default(65)] + #[default(10)] main_task_dur_secs: u64, #[default(60)] task_dur_secs: u64, diff --git a/src/main.rs b/src/main.rs index ebb5377..64d048b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ holding buffers for the duration of a data transfer." )] +use core::time::Duration; + use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice; use embassy_executor::Spawner; use embassy_net::StackResources; @@ -71,6 +73,15 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_rtos::start(timg0.timer0); + let mut timg1 = TimerGroup::new(peripherals.TIMG1); + let mut watchdog = timg1.wdt; + let watchdog_timeout = Duration::from_secs(CONFIG.main_task_dur_secs); + let _ = watchdog.start(watchdog_timeout); + info!( + "Main watchdog configured for {} seconds", + CONFIG.main_task_dur_secs + ); + // Init wifi let radio_init = mk_static!( Controller<'static>, @@ -146,7 +157,12 @@ async fn main(spawner: Spawner) -> ! { spawner.spawn(anemo_task(anemo_pin, sender_anemo)).ok(); spawner.spawn(as5600_task(as_i2c, sender_as5600)).ok(); spawner.spawn(ina210_task(ina_i2c, sender_ina219)).ok(); - Timer::after_secs(CONFIG.main_task_dur_secs).await; + + for _ in 0..CONFIG.main_task_dur_secs as usize { + Timer::after_secs(1).await; + watchdog.feed(); + } + let _ = watchdog.disable(); info!("Going to sleep..."); transistor_pin.set_low();