Skip to content

Commit 1dfb6d7

Browse files
committed
simple_repeater: Allow to idle the CPU for powersaving
Use the idle.interval parameter to stall the loop to save power. The loop is halted for the given amount of seconds before continuing the processing. Only receiving packets will cause an interruption of the idling. Unfortunately it's not easily possible to interrupt the idling on user input such as CLI activity or user button inputs as those things are currently not interrupt-driven. Therefore the UI and the CLI will remain unresponsive during sleep. After booting the CLI will be available for three minutes before the first sleep interval and if a CLI command is issued this period will be extended for another three minutes. On a RAK4631 repeater this can reduce the power consumption during RX mode from around 12 mA to around 7.5 mA. Signed-off-by: Frieder Schrempf <[email protected]>
1 parent 0ea376f commit 1dfb6d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

examples/simple_repeater/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ void halt() {
1919

2020
static char command[160];
2121

22+
constexpr unsigned long ACTIVE_TIME_MS_INUSE = 3 * 60 * 1000; // 3 minutes
23+
constexpr unsigned long ACTIVE_TIME_MS_IDLE = 5 * 1000; // 5 seconds
24+
25+
unsigned long active_timestamp;
26+
unsigned long active_time_ms = ACTIVE_TIME_MS_INUSE;
27+
2228
void setup() {
2329
Serial.begin(115200);
2430
delay(1000);
@@ -82,6 +88,7 @@ void setup() {
8288

8389
// send out initial Advertisement to the mesh
8490
the_mesh.sendSelfAdvertisement(16000);
91+
active_timestamp = millis();
8592
}
8693

8794
void loop() {
@@ -103,6 +110,8 @@ void loop() {
103110
Serial.print('\n');
104111
command[len - 1] = 0; // replace newline with C string null terminator
105112
char reply[160];
113+
active_timestamp = millis();
114+
active_time_ms = ACTIVE_TIME_MS_INUSE;
106115
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
107116
if (reply[0]) {
108117
Serial.print(" -> "); Serial.println(reply);
@@ -117,4 +126,11 @@ void loop() {
117126
ui_task.loop();
118127
#endif
119128
rtc_clock.tick();
129+
130+
if (the_mesh.getIdleInterval() && ((millis() - active_timestamp) > active_time_ms) &&
131+
!the_mesh.hasOutboundPackets()) {
132+
radio_driver.blockTaskUntilRXEvent(the_mesh.getIdleInterval() * 1000);
133+
active_timestamp = millis();
134+
active_time_ms = ACTIVE_TIME_MS_IDLE;
135+
}
120136
}

0 commit comments

Comments
 (0)