Skip to content

Commit

Permalink
Set up watchdog to restart device if no telemetry is published
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Dec 15, 2024
1 parent 74390ae commit cfcebc9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions main/devices/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions main/kernel/Kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <kernel/I2CManager.hpp>
#include <kernel/PowerManager.hpp>
#include <kernel/StateManager.hpp>
#include <kernel/Watchdog.hpp>
#include <kernel/drivers/LedDriver.hpp>
#include <kernel/drivers/MdnsDriver.hpp>
#include <kernel/drivers/RtcDriver.hpp>
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion main/kernel/Watchdog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ typedef std::function<void(WatchdogState)> 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() {
Expand Down
2 changes: 1 addition & 1 deletion main/peripherals/chicken_door/ChickenDoor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cfcebc9

Please sign in to comment.