From e1d280ca3963399421c964d2ee27fcd327ec71b8 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Mon, 12 Jan 2026 20:11:54 +0100 Subject: [PATCH 1/5] RadioLibWrappers.cpp: Improve readability of state macros The STATE_* defines are meant to be used as enumerations, except for STATE_INT_READY which describes a single bit flag. Improve the name of the flag to make the difference clearer. While at it also make the enumeration use a continuous increment without gaps. Signed-off-by: Frieder Schrempf --- src/helpers/radiolib/RadioLibWrappers.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/helpers/radiolib/RadioLibWrappers.cpp b/src/helpers/radiolib/RadioLibWrappers.cpp index 2216ca8f39..10044a452d 100644 --- a/src/helpers/radiolib/RadioLibWrappers.cpp +++ b/src/helpers/radiolib/RadioLibWrappers.cpp @@ -4,9 +4,10 @@ #define STATE_IDLE 0 #define STATE_RX 1 -#define STATE_TX_WAIT 3 -#define STATE_TX_DONE 4 -#define STATE_INT_READY 16 +#define STATE_TX_WAIT 2 +#define STATE_TX_DONE 3 + +#define FLAG_INT_READY (1 << 4) #define NUM_NOISE_FLOOR_SAMPLES 64 #define SAMPLING_THRESHOLD 14 @@ -21,7 +22,7 @@ static #endif void setFlag(void) { // we sent a packet, set the flag - state |= STATE_INT_READY; + state |= FLAG_INT_READY; } void RadioLibWrapper::begin() { @@ -59,7 +60,7 @@ void RadioLibWrapper::doResetAGC() { void RadioLibWrapper::resetAGC() { // make sure we're not mid-receive of packet! - if ((state & STATE_INT_READY) != 0 || isReceivingPacket()) return; + if ((state & FLAG_INT_READY) != 0 || isReceivingPacket()) return; doResetAGC(); state = STATE_IDLE; // trigger a startReceive() @@ -103,12 +104,12 @@ void RadioLibWrapper::startRecv() { } bool RadioLibWrapper::isInRecvMode() const { - return (state & ~STATE_INT_READY) == STATE_RX; + return (state & ~FLAG_INT_READY) == STATE_RX; } int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { int len = 0; - if (state & STATE_INT_READY) { + if (state & FLAG_INT_READY) { len = _radio->getPacketLength(); if (len > 0) { if (len > sz) { len = sz; } @@ -154,7 +155,7 @@ bool RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) { } bool RadioLibWrapper::isSendComplete() { - if (state & STATE_INT_READY) { + if (state & FLAG_INT_READY) { state = STATE_IDLE; n_sent++; return true; From 67eb009bc07e75fe5fb0f46e07b74cbc103f2d12 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Tue, 16 Dec 2025 20:36:37 +0100 Subject: [PATCH 2/5] variants: RAK4631: Enable RF module reset pin There is no reason to not use the reset pin as the RAK4630/31 module has it connected internally. Signed-off-by: Frieder Schrempf --- variants/rak4631/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 142d93e91d..38cc88685c 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -147,7 +147,7 @@ extern "C" // LoRa radio module pins for RAK4631 #define P_LORA_DIO_1 (47) #define P_LORA_NSS (42) -#define P_LORA_RESET (-1) +#define P_LORA_RESET (38) #define P_LORA_BUSY (46) #define P_LORA_SCLK (43) #define P_LORA_MISO (45) From 10db48ad0d4a17abb0a630e2a741a21f8d7fad7c Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Fri, 9 Jan 2026 14:55:58 +0100 Subject: [PATCH 3/5] simple_repeater: Include ongoing RX processing in hasPendingWork() If the radio driver state machine is not in receive mode, this means that processing of a packet is still in progress and we are not in an idle state. Signed-off-by: Frieder Schrempf --- examples/simple_repeater/MyMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 24e8894927..d68cd1cd95 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1340,5 +1340,5 @@ bool MyMesh::hasPendingWork() const { #if defined(WITH_BRIDGE) if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep #endif - return _mgr->getOutboundTotal() > 0; + return (_mgr->getOutboundTotal() > 0) || !radio_driver.isInRecvMode(); } From d6ab4467f04782e922a32c771fc9e32028bb2d2d Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 5 Feb 2026 20:54:16 +0100 Subject: [PATCH 4/5] simple_repeater: Use constexpr variables for powersaving timings This makes the code easier to read and allows for easier changing of the hardcoded values. Signed-off-by: Frieder Schrempf --- examples/simple_repeater/main.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index e37078ce5f..f27c5a51b4 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -20,8 +20,12 @@ void halt() { static char command[160]; // For power saving +constexpr unsigned long ACTIVE_TIME_SEC_INUSE = 2 * 60; // 2 minutes +constexpr unsigned long ACTIVE_TIME_SEC_IDLE = 5; // 5 seconds +constexpr unsigned long IDLE_PERIOD_SEC = 30 * 60; // 30 minutes + unsigned long lastActive = 0; // mark last active time -unsigned long nextSleepinSecs = 120; // next sleep in seconds. The first sleep (if enabled) is after 2 minutes from boot +unsigned long nextSleepinSecs = ACTIVE_TIME_SEC_INUSE; // next sleep in seconds #if defined(PIN_USER_BTN) && defined(_SEEED_SENSECAP_SOLAR_H_) static unsigned long userBtnDownAt = 0; @@ -156,14 +160,14 @@ void loop() { if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) { #if defined(NRF52_PLATFORM) - board.sleep(1800); // nrf ignores seconds param, sleeps whenever possible + board.sleep(IDLE_PERIOD_SEC); // nrf ignores seconds param, sleeps whenever possible #else if (the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // To check if it is time to sleep - board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet + board.sleep(IDLE_PERIOD_SEC); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet lastActive = millis(); - nextSleepinSecs = 5; // Default: To work for 5s and sleep again + nextSleepinSecs = ACTIVE_TIME_SEC_IDLE; // Default: To work for 5s and sleep again } else { - nextSleepinSecs += 5; // When there is pending work, to work another 5s + nextSleepinSecs += ACTIVE_TIME_SEC_IDLE; // When there is pending work, to work another 5s } #endif } From db0f10bbdff88eb429c67d5851f1c978f828b2d1 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Fri, 2 Jan 2026 12:00:28 +0100 Subject: [PATCH 5/5] simple_repeater: Extend active interval on serial CLI activity When a CLI command is issued through the serial interface, extend the timeout for going to sleep to give the user more time for issuing more commands. Signed-off-by: Frieder Schrempf --- examples/simple_repeater/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index f27c5a51b4..b3761ac8f5 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -128,6 +128,8 @@ void loop() { Serial.print('\n'); command[len - 1] = 0; // replace newline with C string null terminator char reply[160]; + lastActive = millis(); + nextSleepinSecs = ACTIVE_TIME_SEC_INUSE; the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial! if (reply[0]) { Serial.print(" -> "); Serial.println(reply);