Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions examples/companion_radio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ void setup() {

board.begin();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif

#ifdef DISPLAY_CLASS
DisplayDriver* disp = NULL;
if (display.begin()) {
Expand Down Expand Up @@ -229,4 +233,7 @@ void loop() {
ui_task.loop();
#endif
rtc_clock.tick();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
}
25 changes: 22 additions & 3 deletions examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void setup() {

board.begin();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif

#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
// give some extra time for serial to settle so
// boot debug messages can be seen on terminal
Expand Down Expand Up @@ -154,17 +158,32 @@ void loop() {
#endif
rtc_clock.tick();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) {
#if defined(NRF52_PLATFORM)
#if defined(NRF52_PLATFORM)
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.feed();
uint32_t sleep_interval = external_watchdog.getIntervalMs() / 1000;
board.sleep((sleep_interval > 1800) ? 1800 : sleep_interval); // nrf ignores seconds param, sleeps whenever possible
#else
board.sleep(1800); // nrf ignores seconds param, sleeps whenever possible
#else
#endif
#else
if (the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // To check if it is time to sleep
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.feed();
uint32_t sleep_interval = external_watchdog.getIntervalMs() / 1000;
board.sleep((sleep_interval > 1800) ? 1800 : sleep_interval); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
#else
board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
#endif
lastActive = millis();
nextSleepinSecs = 5; // Default: To work for 5s and sleep again
} else {
nextSleepinSecs += 5; // When there is pending work, to work another 5s
}
#endif
#endif
}
}
7 changes: 7 additions & 0 deletions examples/simple_room_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ void setup() {

board.begin();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif

#ifdef DISPLAY_CLASS
if (display.begin()) {
display.startFrame();
Expand Down Expand Up @@ -113,4 +117,7 @@ void loop() {
ui_task.loop();
#endif
rtc_clock.tick();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
}
7 changes: 7 additions & 0 deletions examples/simple_secure_chat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ void setup() {

board.begin();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif

if (!radio_init()) { halt(); }

fast_rng.begin(radio_driver.getRngSeed());
Expand Down Expand Up @@ -591,4 +595,7 @@ void setup() {
void loop() {
the_mesh.loop();
rtc_clock.tick();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
}
7 changes: 7 additions & 0 deletions examples/simple_sensor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void setup() {

board.begin();

#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif

#ifdef DISPLAY_CLASS
if (display.begin()) {
display.startFrame();
Expand Down Expand Up @@ -147,4 +151,7 @@ void loop() {
ui_task.loop();
#endif
rtc_clock.tick();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
}
12 changes: 12 additions & 0 deletions src/helpers/ExternalWatchdogManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

class ExternalWatchdogManager {
protected:
unsigned long last_feed_watchdog;
public:
ExternalWatchdogManager() { last_feed_watchdog = 0; }
virtual bool begin() { return false; }
virtual void loop() { }
virtual unsigned long getIntervalMs() const { return 0; }
virtual void feed() { }
};
5 changes: 5 additions & 0 deletions variants/heltec_mesh_solar/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ build_flags = ${nrf52_base.build_flags}
-D LORA_TX_POWER=22
-D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D HAS_EXTERNAL_WATCHDOG
-D EXTERNAL_WATCHDOG_DONE_PIN=9
-D EXTERNAL_WATCHDOG_WAKE_PIN=10
-D EXTERNAL_WATCHDOG_FEED_INTERVAL_MS=480000 ; 8 minute feed interval, safely inside the hardware watchdog timeout

build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<../variants/heltec_mesh_solar>
Expand Down
32 changes: 32 additions & 0 deletions variants/heltec_mesh_solar/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ VolatileRTCClock fallback_clock;
AutoDiscoverRTCClock rtc_clock(fallback_clock);
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
SolarSensorManager sensors = SolarSensorManager(nmea);
SolarExternalWatchdog external_watchdog;

#ifdef DISPLAY_CLASS
DISPLAY_CLASS display;
Expand Down Expand Up @@ -106,3 +107,34 @@ bool SolarSensorManager::setSettingValue(const char* name, const char* value) {
}
return false; // not supported
}

bool SolarExternalWatchdog::begin() {
last_feed_watchdog = 0;
pinMode(EXTERNAL_WATCHDOG_WAKE_PIN, INPUT);
pinMode(EXTERNAL_WATCHDOG_DONE_PIN, OUTPUT);
delay(1);
digitalWrite(EXTERNAL_WATCHDOG_DONE_PIN, LOW);
delay(1);
feed();
return true;
}
void SolarExternalWatchdog::loop() {
if (millis() - last_feed_watchdog >= EXTERNAL_WATCHDOG_FEED_INTERVAL_MS) {
feed();
}
}

unsigned long SolarExternalWatchdog::getIntervalMs() const {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this right, this is the remaining time left until next feed() ?
Or should this be whatever the fixed interval is?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the time remaining until the next feed(), not a fixed time interval.

unsigned long elapsed_ms = millis() - last_feed_watchdog;
if (elapsed_ms >= EXTERNAL_WATCHDOG_FEED_INTERVAL_MS) {
return 0;
}
return EXTERNAL_WATCHDOG_FEED_INTERVAL_MS - elapsed_ms;
}

void SolarExternalWatchdog::feed() {
digitalWrite(EXTERNAL_WATCHDOG_DONE_PIN, HIGH);
delay(1);
digitalWrite(EXTERNAL_WATCHDOG_DONE_PIN, LOW);
last_feed_watchdog = millis();
}
11 changes: 11 additions & 0 deletions variants/heltec_mesh_solar/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h>
#include <helpers/sensors/LocationProvider.h>
#include <helpers/ExternalWatchdogManager.h>
#ifdef DISPLAY_CLASS
#include <helpers/ui/ST7789Display.h>
#endif
Expand All @@ -30,10 +31,20 @@ class SolarSensorManager : public SensorManager {
bool setSettingValue(const char* name, const char* value) override;
};

class SolarExternalWatchdog : public ExternalWatchdogManager {
public:
SolarExternalWatchdog() {}
bool begin() override;
void loop() override;
unsigned long getIntervalMs() const override;
void feed() override;
};

extern MeshSolarBoard board;
extern WRAPPER_CLASS radio_driver;
extern AutoDiscoverRTCClock rtc_clock;
extern SolarSensorManager sensors;
extern SolarExternalWatchdog external_watchdog;

#ifdef DISPLAY_CLASS
extern DISPLAY_CLASS display;
Expand Down
4 changes: 2 additions & 2 deletions variants/heltec_mesh_solar/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#define PIN_SERIAL1_RX (37)
#define PIN_SERIAL1_TX (39)

#define PIN_SERIAL2_RX (9)
#define PIN_SERIAL2_TX (10)
#define PIN_SERIAL2_RX (-1)
#define PIN_SERIAL2_TX (-1)

////////////////////////////////////////////////////////////////////////////////
// I2C pin definition
Expand Down