Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "Records.hpp"
#include "EthernetClient.hpp"
#include "LinUdpGateway.hpp"
#include "esp_system.h"

constexpr uint8_t rib_id = 7;

Expand All @@ -39,19 +40,38 @@ Records records{};
Config config{rib_id, records};
LinUdpGateway linUdpGateway{Serial1, config, records};

const int wdtTimeout = 5000; //time in ms to trigger the watchdog
hw_timer_t *timer = NULL;

void resetModule()
{
// if this happens we need to emit
// console.log("some meningful information") once the settings are restored and system is operational gaain
// to inform the server that we had an unexpected reboot.
// ets_printf("reboot\n");
esp_restart();
}

void setup()
{
Serial.begin(115200);
Serial1.begin(19200);
ethClient.connect(&config);

// set up watchdog
timer = timerBegin(0, 80, true); //timer 0, div 80
timerAttachInterrupt(timer, &resetModule, true); //attach callback
timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
timerAlarmEnable(timer);

// Init configuration
config.init();
}

void loop()
{
// Get configuration from server and send heartbeat
timerWrite(timer, 0); //reset timer (feed watchdog)
config.run();

if (!linUdpGateway.connected())
Expand Down