PowerSaving for Room Servers

This commit is contained in:
Kevin Le committed 2026-10-18 21:48:46 +07:00
1 parent 0b9b6ec544
commit af23f95041
3 files changed
+63 -1

No files matched your search

+34 -1
View File
@@ -681,8 +681,19 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.rx_boosted_gain = 1; // enabled by default;
#endif
#endif
_prefs.radio_fem_rxgain = 1;
// PowerSaving variant
#ifdef RADIO_FEM_RXGAIN
_prefs.radio_fem_rxgain = RADIO_FEM_RXGAIN;
#else
_prefs.radio_fem_rxgain = 0;
#endif
#ifdef RADIO_FEM_TXGAIN
_prefs.radio_fem_txgain = RADIO_FEM_TXGAIN; // board-specific default for PA
#else
_prefs.radio_fem_txgain = 0;
#endif
next_post_idx = 0;
next_client_idx = 0;
@@ -691,6 +702,15 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_num_posted = _num_post_pushes = 0;
memset(default_scope.key, 0, sizeof(default_scope.key));
// PowerSaving variant
// PowerSaving defaults
_prefs.powersaving_enabled = 1;
// RXPS defaults - Balanced profile
_prefs.rxps.enabled = 1;
_prefs.rxps.level = 6;
_prefs.rxps.preamble = 16;
}
void MyMesh::begin(FILESYSTEM *fs) {
@@ -723,6 +743,8 @@ void MyMesh::begin(FILESYSTEM *fs) {
}
radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
// PowerSaving variant
_prefs.getRadioPrefs()->applyRxPowerSaving(_prefs.sf, _prefs.bw);
radio_driver.setTxPower(_prefs.tx_power_dbm);
radio_driver.setRxBoostedGainMode(_prefs.rx_boosted_gain);
@@ -1057,12 +1079,16 @@ void MyMesh::loop() {
if (set_radio_at && millisHasNowPassed(set_radio_at)) { // apply pending (temporary) radio params
set_radio_at = 0; // clear timer
radio_driver.setParams(pending_freq, pending_bw, pending_sf, pending_cr);
// PowerSaving variant
_prefs.getRadioPrefs()->applyRxPowerSaving(pending_sf, pending_bw);
MESH_DEBUG_PRINTLN("Temp radio params");
}
if (revert_radio_at && millisHasNowPassed(revert_radio_at)) { // revert radio params to orig
revert_radio_at = 0; // clear timer
radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
// PowerSaving variant
_prefs.getRadioPrefs()->applyRxPowerSaving(_prefs.sf, _prefs.bw);
MESH_DEBUG_PRINTLN("Radio params restored");
}
@@ -1079,3 +1105,10 @@ void MyMesh::loop() {
uptime_millis += now - last_millis;
last_millis = now;
}
// PowerSaving variant
// To check if there is pending work
bool MyMesh::hasPendingWork() const {
return _mgr->getOutboundTotal() > 0 || _mgr->getInboundTotal() > 0 || // rxdelay packets wait in the inbound queue
isTransmitting() || _prefs.getRadioPrefs()->isRxPowerSavingCalibrationActive();
}
+4
View File
@@ -229,4 +229,8 @@ public:
void clearStats() override;
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
void loop();
// PowerSaving variant
// To check if there is pending work
bool hasPendingWork() const;
};
+25
View File
@@ -26,6 +26,10 @@ static char command[MAX_POST_TEXT_LEN+1];
static char ethernet_command[MAX_POST_TEXT_LEN+1];
#endif
// PowerSaving variant
// For power saving
unsigned long POWERSAVING_FIRSTSLEEP_SECS = 120; // The first sleep (if enabled) from boot
void setup() {
Serial.begin(115200);
delay(1000);
@@ -83,6 +87,16 @@ void setup() {
ethernet_command[0] = 0;
#endif
// PowerSaving variant
#if ENV_INCLUDE_GPS == 1
// Apply PowerSaving profile for GPS
if (sensors.getLocationProvider() != NULL) {
// GPS on and off duration in seconds
sensors.getLocationProvider()->setPowerSavingProfile(the_mesh.getNodePrefs()->powersaving_enabled, 600,
86400); // Max 10 minutes, 1 day
}
#endif
sensors.begin();
the_mesh.begin(fs);
@@ -166,4 +180,15 @@ void loop() {
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
// PowerSaving variant
if (the_mesh.getNodePrefs()->powersaving_enabled && !the_mesh.hasPendingWork()) {
#if defined(NRF52_PLATFORM)
board.sleep(0); // nrf ignores seconds param, sleeps whenever possible
#else
if (the_mesh.millisHasNowPassed(POWERSAVING_FIRSTSLEEP_SECS * 1000)) { // To check if it is time to sleep
board.sleep(5); // Sleep. Wake up after a while or when receiving a LoRa packet
}
#endif
}
}