diff --git a/main/devices/Device.hpp b/main/devices/Device.hpp index e421797b..ad2d4b07 100644 --- a/main/devices/Device.hpp +++ b/main/devices/Device.hpp @@ -503,6 +503,10 @@ class Device { Task::loop("telemetry", 8192, [this](Task& task) { publishTelemetry(); + + // Signal that we are still alive + // kernel.watchdog.restart(); + // TODO Configure these telemetry intervals // Publishing interval const auto interval = 1min; diff --git a/main/kernel/Kernel.hpp b/main/kernel/Kernel.hpp index 13de1f6b..694188f6 100644 --- a/main/kernel/Kernel.hpp +++ b/main/kernel/Kernel.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -303,6 +304,13 @@ class Kernel { TDeviceConfiguration& deviceConfig; public: + Watchdog watchdog { "watchdog", 10s, true, [](WatchdogState state) { + if (state == WatchdogState::TimedOut) { + LOGE("Watchdog timed out"); + esp_system_abort("Watchdog timed out"); + } + } }; + PowerManager powerManager { deviceConfig.sleepWhenIdle.get() }; private: diff --git a/main/kernel/Watchdog.hpp b/main/kernel/Watchdog.hpp index e2041822..0ecb1ae1 100644 --- a/main/kernel/Watchdog.hpp +++ b/main/kernel/Watchdog.hpp @@ -18,10 +18,13 @@ typedef std::function WatchdogCallback; class Watchdog { public: - Watchdog(const String& name, const ticks timeout, WatchdogCallback callback) + Watchdog(const String& name, const ticks timeout, bool startImmediately, WatchdogCallback callback) : name(name) , timeout(timeout) , callback(callback) { + if (startImmediately) { + restart(); + } } void restart() { diff --git a/main/peripherals/chicken_door/ChickenDoor.hpp b/main/peripherals/chicken_door/ChickenDoor.hpp index 839a8128..a48c1f50 100644 --- a/main/peripherals/chicken_door/ChickenDoor.hpp +++ b/main/peripherals/chicken_door/ChickenDoor.hpp @@ -112,7 +112,7 @@ class ChickenDoorComponent SwitchMode::PullUp, [this](const Switch&) { updateState(); }, [this](const Switch&, milliseconds) { updateState(); })) - , watchdog(name + ":watchdog", movementTimeout, [this](WatchdogState state) { + , watchdog(name + ":watchdog", movementTimeout, false, [this](WatchdogState state) { handleWatchdogEvent(state); }) , publishTelemetry(publishTelemetry)