PowerSaving GPS version 1 for repeaters

This commit is contained in:
Kevin Le committed 2026-07-16 18:48:39 +07:00
1 parent 46c729b2e9
commit 16fbf33582
6 files changed
+120 -15

No files matched your search

@@ -621,6 +621,12 @@ static const SensorDef SENSOR_TABLE[] = {
static const size_t SENSOR_TABLE_SIZE = (sizeof(SENSOR_TABLE) / sizeof(SENSOR_TABLE[0])) - 1;
// ============================================================
// Power Saving GPS
// ============================================================
static unsigned long GPS_ON_DURATION_SECS = 600; // 10 minutes
static unsigned long GPS_OFF_DURATION_SECS = 86400; // 1 day
// ============================================================
// begin() — scan the I2C bus, then initialize only what was
// found. A sensor whose address does not ACK during the scan
@@ -730,8 +736,16 @@ bool EnvironmentSensorManager::setSettingValue(const char* name, const char* val
#if ENV_INCLUDE_GPS
if (gps_detected && strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
if (powersaving_enabled) {
_location->setGPSPowerSaving(false);
}
stop_gps();
} else {
if (powersaving_enabled) {
_location->setGPSPowerSaving(true);
}
start_gps();
}
return true;
@@ -883,11 +897,22 @@ void EnvironmentSensorManager::start_gps() {
#ifndef PIN_GPS_EN
MESH_DEBUG_PRINTLN("Start GPS is N/A on this board. Actual GPS state unchanged");
#endif
if (powersaving_enabled && _location->getGPSPowerSaving()) {
_location->syncTime(); // Clear GPS data and force sync time
_location->setNextGPSOff(millis() + GPS_ON_DURATION_SECS * 1000UL); // Next time to off
}
}
void EnvironmentSensorManager::stop_gps() {
gps_active = false;
#ifdef RAK_WISBLOCK_GPS
if (powersaving_enabled && _location->getGPSPowerSaving()) {
_location->stopTimeSync(); // Stop time sync
_location->setNextGPSOn(millis() + GPS_OFF_DURATION_SECS * 1000UL); // Next time to on
}
#ifdef RAK_WISBLOCK_GPS
pinMode(gpsResetPin, OUTPUT);
digitalWrite(gpsResetPin, LOW);
return;
@@ -906,11 +931,39 @@ void EnvironmentSensorManager::loop() {
#if ENV_INCLUDE_GPS
static long next_gps_update = 0;
// PowerSaving
if (powersaving_enabled) {
if (gps_detected && _location->getGPSPowerSaving()) {
if (gps_active && ((int32_t)(millis() - _location->getNextGPSOff()) >= 0 ||
!_location->waitingTimeSync())) { // Time to off or GPS set
// --- TO REMOVE
if ((int32_t)(millis() - _location->getNextGPSOff()) >= 0) Serial.println("Timeout, off");
else if (!_location->waitingTimeSync()) Serial.println("GPS set, off early");
// --- TO REMOVE
stop_gps();
} else if (!gps_active && ((int32_t)(millis() - _location->getNextGPSOn()) >= 0)) { // Time to on
// --- TO REMOVE
Serial.println("Timeout, on");
// --- TO REMOVE
start_gps();
} else if (!gps_active && _location->waitingTimeSync()) { // On for "gps sync"
// --- TO REMOVE
Serial.println("gps sync CLI, on");
// --- TO REMOVE
start_gps();
}
}
}
if (gps_active) {
_location->loop();
}
if (millis() > next_gps_update) {
if ((int32_t)(millis() - next_gps_update) >= 0) {
if(gps_active){
#ifdef RAK_WISBLOCK_GPS
if ((i2cGPSFlag || serialGPSFlag) && _location->isValid()) {
@@ -929,8 +982,12 @@ void EnvironmentSensorManager::loop() {
MESH_DEBUG_PRINTLN("lat %f lon %f alt %f", node_lat, node_lon, node_altitude);
}
#endif
// In powersaving mode, GPS is on and off. Only update data when GPS is on
if(powersaving_enabled) next_gps_update = millis() + (gps_update_interval_sec * 1000);
}
next_gps_update = millis() + (gps_update_interval_sec * 1000);
if(!powersaving_enabled) next_gps_update = millis() + (gps_update_interval_sec * 1000);
}
#endif
#if ENV_INCLUDE_BME680_BSEC