Add RX watchdog and fix repeater builds

This commit is contained in:
mikecarper committed 2026-07-13 23:42:04 -07:00
1 parent fcfca64cc5
commit a45c43f2b1
8 files changed
+78 -3

No files matched your search

+15
View File
@@ -503,6 +503,21 @@ send text.flood checking ridge link
---
#### Enable or disable the RX inactivity watchdog (Repeater Only)
**Usage:**
- `get rx.watchdog`
- `set rx.watchdog on`
- `set rx.watchdog off`
**Default:** `off`
**Notes:**
- When enabled, the first check is due after a full 12-hour observation window. The repeater then checks roughly every 12 hours and reboots if it has not successfully received a radio packet during the preceding 12 hours.
- Enabling the watchdog starts a new 12-hour observation window. Rebooting also starts a new window, so a quiet mesh can reboot no more often than once every 12 hours.
- The check reuses the radio driver's existing last-receive timestamp. It does not poll, sample, or wake the radio or CPU. A due check waits for the next normal loop/wake, so its actual cadence can drift around the 12-hour target. With RX power saving enabled, packets received during normal listening windows count as activity; the watchdog does not alter the RX/sleep timing.
---
#### View this node's public key
**Usage:** `get public.key`
+46
View File
@@ -104,6 +104,7 @@
#define LOW_BATTERY_STARTUP_DELAY (30ULL * 60ULL * 1000ULL)
#define LOW_BATTERY_CHECK_INTERVAL (30UL * 60UL * 1000UL)
#define LOW_BATTERY_ALERT_INTERVAL (12UL * 60UL * 60UL * 1000UL)
#define RX_INACTIVITY_WATCHDOG_INTERVAL (12UL * 60UL * 60UL * 1000UL)
static uint32_t nextRadioApplyRetryDelay(uint8_t& failure_count) {
uint8_t shift = failure_count < 5 ? failure_count : 5;
@@ -2320,6 +2321,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
uptime_millis = 0;
next_local_advert = next_flood_advert = 0;
next_battery_alert_check = 0;
next_rx_watchdog_check = 0;
next_recent_repeater_sweep = 0;
last_battery_alert_sent = 0;
pending_battery_alert_packet = NULL;
@@ -2771,6 +2773,32 @@ void MyMesh::checkBatteryAlert() {
}
}
void MyMesh::checkRxInactivityWatchdog() {
if (!_prefs.rx_watchdog_enabled) {
next_rx_watchdog_check = 0;
return;
}
if (next_rx_watchdog_check == 0) {
next_rx_watchdog_check = futureMillis(RX_INACTIVITY_WATCHDOG_INTERVAL);
if (next_rx_watchdog_check == 0) next_rx_watchdog_check = 1;
return;
}
if (!millisHasNowPassed(next_rx_watchdog_check)) {
return;
}
next_rx_watchdog_check = futureMillis(RX_INACTIVITY_WATCHDOG_INTERVAL);
if (next_rx_watchdog_check == 0) next_rx_watchdog_check = 1;
const unsigned long now = millis();
const unsigned long last_rx = _radio->getLastRecvMillis();
if (last_rx == 0 || (uint32_t)(now - last_rx) >= RX_INACTIVITY_WATCHDOG_INTERVAL) {
MESH_DEBUG_PRINTLN("RX watchdog: no packet received in 12 hours, rebooting");
_cli.getBoard()->reboot();
}
}
bool MyMesh::applyRadioParams(float freq, float bw, uint8_t sf, uint8_t cr) {
uint32_t rx_us = _prefs.rx_ps_rx_us;
uint32_t sleep_us = _prefs.rx_ps_sleep_us;
@@ -4241,6 +4269,23 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
sprintf(reply, "> %u", (uint32_t)_prefs.battery_alert_low_percent);
} else if (strcmp(command, "get battery.alert.critical") == 0) {
sprintf(reply, "> %u", (uint32_t)_prefs.battery_alert_critical_percent);
} else if (strcmp(command, "get rx.watchdog") == 0) {
sprintf(reply, "> %s", _prefs.rx_watchdog_enabled ? "on" : "off");
} else if (strncmp(command, "set rx.watchdog ", 16) == 0) {
const char* value = command + 16;
if (strcmp(value, "on") == 0) {
_prefs.rx_watchdog_enabled = 1;
next_rx_watchdog_check = 0;
savePrefs();
strcpy(reply, "OK - RX watchdog enabled; first check in 12 hours");
} else if (strcmp(value, "off") == 0) {
_prefs.rx_watchdog_enabled = 0;
next_rx_watchdog_check = 0;
savePrefs();
strcpy(reply, "OK - RX watchdog disabled");
} else {
strcpy(reply, "Err - usage: set rx.watchdog <on|off>");
}
} else if (strncmp(command, "set battery.alert ", 18) == 0) {
const char* value = command + 18;
if (strncmp(value, "on", 2) == 0 && (value[2] == 0 || value[2] == ' ')) {
@@ -4332,6 +4377,7 @@ void MyMesh::loop() {
// Check radio FIRST to ensure we don't miss incoming packets
// MQTT processing runs in a separate FreeRTOS task on Core 0, so we don't call bridge.loop() here
mesh::Mesh::loop();
checkRxInactivityWatchdog();
checkBatteryAlert();
expireRecentRepeatersIfDue();
+2
View File
@@ -136,6 +136,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
uint64_t uptime_millis;
unsigned long next_local_advert, next_flood_advert;
unsigned long next_battery_alert_check;
unsigned long next_rx_watchdog_check;
unsigned long next_recent_repeater_sweep;
uint64_t last_battery_alert_sent;
mesh::Packet* pending_battery_alert_packet;
@@ -270,6 +271,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
bool getBatteryAlertScopeForRegion(const RegionEntry& region, TransportKey& scope);
bool resolveBatteryAlertScope(TransportKey& scope);
void checkBatteryAlert();
void checkRxInactivityWatchdog();
void expireRecentRepeatersIfDue();
void printRecentRepeatersSerial();
+9 -1
View File
@@ -941,6 +941,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
#endif
_prefs->telemetry_access = TELEMETRY_ACCESS_ALL;
_prefs->flood_retry_group_max_path = FLOOD_RETRY_GROUP_MAX_PATH_DEFAULT;
_prefs->rx_watchdog_enabled = 0;
// A remainder larger than the smallest legacy MQTT gap (864) means an old fork
// file with the zero-filled gap; detect and recover it below. Anything smaller
// (upstream/flex 5-byte tails, or the ~384-byte keymind retry tail) takes the
@@ -1192,6 +1193,10 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
file.read((uint8_t *)&_prefs->flood_retry_group_max_path,
sizeof(_prefs->flood_retry_group_max_path));
}
if (file.available() >= (int)sizeof(_prefs->rx_watchdog_enabled)) {
file.read((uint8_t *)&_prefs->rx_watchdog_enabled,
sizeof(_prefs->rx_watchdog_enabled));
}
}
// sanitise bad pref values
@@ -1283,6 +1288,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
if (_prefs->ota_signer_count > 4) _prefs->ota_signer_count = 0; // corrupt count -> drop keys
#endif
_prefs->rx_powersaving_enabled = constrain(_prefs->rx_powersaving_enabled, 0, 1);
_prefs->rx_watchdog_enabled = constrain(_prefs->rx_watchdog_enabled, 0, 1);
_prefs->rx_ps_level = constrain(_prefs->rx_ps_level, 0, 10);
if (_prefs->rx_ps_preamble != 16 && _prefs->rx_ps_preamble != 32) {
_prefs->rx_ps_preamble = 0; // 0 = auto (derive from SF)
@@ -1419,7 +1425,9 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
file.write((uint8_t *)_prefs->battery_alert_region, sizeof(_prefs->battery_alert_region)); // 822
file.write((uint8_t *)&_prefs->flood_retry_group_max_path,
sizeof(_prefs->flood_retry_group_max_path)); // 853
// next: 854
file.write((uint8_t *)&_prefs->rx_watchdog_enabled,
sizeof(_prefs->rx_watchdog_enabled)); // 854
// next: 855
file.close();
}
+1
View File
@@ -217,6 +217,7 @@ struct NodePrefs { // persisted to file
uint8_t rx_ps_preamble; // 0 = auto (derive from SF); else 16 or 32 = explicit override for level calc
char battery_alert_region[31]; // named scope for low-battery floods; empty = no alert scope
uint8_t flood_retry_group_max_path; // PAYLOAD_TYPE_GRP_DATA retry path gate; 0xFF = use only the general gate
uint8_t rx_watchdog_enabled; // repeater RX-inactivity reboot watchdog (boolean)
};
#ifdef WITH_MQTT_BRIDGE
+3 -2
View File
@@ -11,8 +11,9 @@ public:
uint32_t getRngSeed();
void setParams(float freq, float bw, uint8_t sf, uint8_t cr) {
// no-op
bool setParams(float freq, float bw, uint8_t sf, uint8_t cr,
const uint32_t* rx_ps_timings = nullptr) {
return true;
}
void powerOff() { /* no-op */ }
+1
View File
@@ -17,6 +17,7 @@ build_src_filter = ${stm32_base.build_src_filter}
[env:RAK_3x72_repeater]
extends = rak3x72
build_flags = ${rak3x72.build_flags}
-flto
-D ADVERT_NAME='"RAK3x72 Repeater"'
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
+1
View File
@@ -18,6 +18,7 @@ build_src_filter = ${stm32_base.build_src_filter}
[env:wio-e5_repeater]
extends = lora_e5
build_flags = ${lora_e5.build_flags}
-flto
-D LORA_TX_POWER=22
-D ADVERT_NAME='"WIO-E5 Repeater"'
-D ADMIN_PASSWORD='"password"'