GPS PowerSaving 1.4: Added GPS PowerSaving for Seeed T1000e, Heltec Mesh Solar and Heltec Tracker.

Not supported: Mesh Adventurer (unable to off GPS power) and ThinkNode M1 (manual GPS switch).
This commit is contained in:
Kevin Le committed 2026-07-23 23:21:41 +07:00
1 parent a2fe2ea642
commit 0cc580afec
7 files changed
+268 -28

No files matched your search

+61
View File
@@ -133,3 +133,64 @@ Xiao_C6_companion_radio_ble_ \
RAK_4631_companion_radio_ble \
Heltec_t096_companion_radio_ble \
Heltec_t096_companion_radio_ble_femoff
############# GPS PowerSaving #############
export FIRMWARE_VERSION="PowerSaving16.1.1"
sh build.sh build-firmware \
heltec_v4_repeater \
Heltec_t114_repeater \
Heltec_t096_repeater \
WioTrackerL1_repeater \
LilyGo_T-Echo_repeater \
Station_G2_repeater \
Heltec_Wireless_Tracker_repeater \
heltec_tracker_v2_repeater \
Heltec_mesh_solar_repeater \
SenseCap_Solar_repeater
sh build.sh build-firmware \
Heltec_t114_companion_radio_ble \
t1000e_companion_radio_ble \
LilyGo_T-Echo_companion_radio_ble \
WioTrackerL1_companion_radio_ble \
SenseCap_Solar_companion_radio_ble \
Heltec_t096_companion_radio_ble \
Heltec_t096_companion_radio_ble_femoff \
heltec_v4_companion_radio_ble_ps \
heltec_v4_3_companion_radio_ble_ps_femoff \
LilyGo_TBeam_1W_companion_radio_ble_ps \
Heltec_Wireless_Tracker_companion_radio_ble_ps \
heltec_tracker_v2_companion_radio_ble_ps \
T_Beam_S3_Supreme_SX1262 \
Tbeam_SX1262_companion_radio_ble_ps \
heltec_v4_expansionkit_tft_companion_radio_ble_ps
export FIRMWARE_VERSION="PowerSaving16.1.2"
sh build.sh build-firmware \
RAK_4631_repeater \
RAK_3401_repeater \
RAK_WisMesh_Tag_repeater \
GAT562_30S_Mesh_Kit_repeater \
GAT562_Mesh_Tracker_Pro_repeater \
RAK_4631_companion_radio_ble \
RAK_3401_companion_radio_ble \
RAK_WisMesh_Tag_companion_radio_ble
export FIRMWARE_VERSION="PowerSaving16.1.2"
sh build.sh build-firmware \
Tbeam_SX1262_repeater \
T_Beam_S3_Supreme_SX1262_repeater \
LilyGo_TBeam_1W_repeater \
Tbeam_SX1262_companion_radio_ble_ps \
T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps \
LilyGo_TBeam_1W_companion_radio_ble_ps
export FIRMWARE_VERSION="PowerSaving16.1.2"
sh build.sh build-firmware \
t1000e_repeater \
t1000e_companion_radio_ble \
Heltec_mesh_solar_repeater \
Heltec_mesh_solar_companion_radio_ble \
Heltec_Wireless_Tracker_repeater \
Heltec_Wireless_Tracker_companion_radio_ble_ps \
+65 -9
View File
@@ -31,13 +31,28 @@ mesh::LocalIdentity radio_new_identity() {
void SolarSensorManager::start_gps() {
if (!gps_active) {
gps_active = true;
if (powersaving_enabled && _location->isPowerSavingEnabled()) {
gps_wake = true; // gps_active is true
_location->syncTime(); // Clear GPS data and force sync time
_location->setNextSleep(); // Next time to off
}
_location->begin();
}
}
void SolarSensorManager::stop_gps() {
if (gps_active) {
gps_active = false;
if (powersaving_enabled && _location->isPowerSavingEnabled()) {
gps_wake = false; // gps_active is unchanged (true) even the GPS sleep (e.g: off)
_location->stopTimeSync(); // Stop time sync
_location->setNextWake(); // Next time to on
} else {
gps_active = false;
gps_wake = false; // When GPS is off, wake is false to be sure
}
_location->stop();
}
}
@@ -67,16 +82,49 @@ bool SolarSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP&
void SolarSensorManager::loop() {
static long next_gps_update = 0;
_location->loop();
// PowerSaving
if (powersaving_enabled) {
if (gps_detected && _location->isPowerSavingEnabled()) {
if (gps_wake && ((int32_t)(millis() - _location->getNextSleep()) >= 0 ||
!_location->waitingTimeSync())) { // Time to off or GPS set
if ((int32_t)(millis() - _location->getNextSleep()) >= 0) {
POWERSAVING_DEBUG_PRINTLN("GPS wake timeout. Enter sleep");
} else if (!_location->waitingTimeSync()) {
POWERSAVING_DEBUG_PRINTLN("GPS set. Enter sleep early");
}
if (millis() > next_gps_update) {
if (_location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.;
node_altitude = ((double)_location->getAltitude()) / 1000.0;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
stop_gps();
} else if (!gps_wake && ((int32_t)(millis() - _location->getNextWake()) >= 0)) { // Time to on
POWERSAVING_DEBUG_PRINTLN("GPS sleep timeout. Wakeup.");
start_gps();
} else if (!gps_wake && _location->waitingTimeSync()) { // On for "gps sync"
POWERSAVING_DEBUG_PRINTLN("CLI gps sync. Wakeup");
start_gps();
}
}
next_gps_update = millis() + 1000;
}
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
_location->loop();
}
if ((int32_t)(millis() - next_gps_update) >= 0) {
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
if (_location->isValid()) {
node_lat = ((double)_location->getLatitude()) / 1000000.;
node_lon = ((double)_location->getLongitude()) / 1000000.;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
node_altitude = ((double)_location->getAltitude()) / 1000.0;
MESH_DEBUG_PRINTLN("lat %f lon %f alt %f", node_lat, node_lon, node_altitude);
}
// In powersaving mode, GPS is on and off. Only update data when GPS is on
if (powersaving_enabled) next_gps_update = millis() + 1000;
}
if (!powersaving_enabled) next_gps_update = millis() + 1000;
}
}
@@ -98,8 +146,16 @@ const char* SolarSensorManager::getSettingValue(int i) const {
bool SolarSensorManager::setSettingValue(const char* name, const char* value) {
if (gps_detected && strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
if (powersaving_enabled) {
_location->enablePowerSaving(false);
}
stop_gps();
} else {
if (powersaving_enabled) {
_location->enablePowerSaving(true);
}
start_gps();
}
return true;
+1
View File
@@ -15,6 +15,7 @@
class SolarSensorManager : public SensorManager {
bool gps_active = false;
bool gps_detected = false;
bool gps_wake = false; // In PowerSaving, gps_active can have gps_wake true or false
LocationProvider* _location;
void start_gps();
+65 -9
View File
@@ -46,13 +46,28 @@ void HWTSensorManager::start_gps() {
if (!gps_active) {
_location->begin(); // Claims periph_power via RefCountedDigitalPin
gps_active = true;
if (powersaving_enabled && _location->isPowerSavingEnabled()) {
gps_wake = true; // gps_active is true
_location->syncTime(); // Clear GPS data and force sync time
_location->setNextSleep(); // Next time to off
}
Serial1.println("$CFGSYS,h35155*68"); // Configure GPS for all constellations
}
}
void HWTSensorManager::stop_gps() {
if (gps_active) {
gps_active = false;
if (powersaving_enabled && _location->isPowerSavingEnabled()) {
gps_wake = false; // gps_active is unchanged (true) even the GPS sleep (e.g: off)
_location->stopTimeSync(); // Stop time sync
_location->setNextWake(); // Next time to on
} else {
gps_active = false;
gps_wake = false; // When GPS is off, wake is false to be sure
}
_location->stop(); // Releases periph_power via RefCountedDigitalPin
}
}
@@ -73,16 +88,49 @@ bool HWTSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& t
void HWTSensorManager::loop() {
static long next_gps_update = 0;
_location->loop();
// PowerSaving
if (powersaving_enabled) {
if (_location->isPowerSavingEnabled()) {
if (gps_wake && ((int32_t)(millis() - _location->getNextSleep()) >= 0 ||
!_location->waitingTimeSync())) { // Time to off or GPS set
if ((int32_t)(millis() - _location->getNextSleep()) >= 0) {
POWERSAVING_DEBUG_PRINTLN("GPS wake timeout. Enter sleep");
} else if (!_location->waitingTimeSync()) {
POWERSAVING_DEBUG_PRINTLN("GPS set. Enter sleep early");
}
if (millis() > next_gps_update) {
if (gps_active && _location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.;
node_altitude = ((double)_location->getAltitude()) / 1000.0;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
stop_gps();
} else if (!gps_wake && ((int32_t)(millis() - _location->getNextWake()) >= 0)) { // Time to on
POWERSAVING_DEBUG_PRINTLN("GPS sleep timeout. Wakeup.");
start_gps();
} else if (!gps_wake && _location->waitingTimeSync()) { // On for "gps sync"
POWERSAVING_DEBUG_PRINTLN("CLI gps sync. Wakeup");
start_gps();
}
}
next_gps_update = millis() + 1000;
}
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
_location->loop();
}
if ((int32_t)(millis() - next_gps_update) >= 0) {
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
if (_location->isValid()) {
node_lat = ((double)_location->getLatitude()) / 1000000.;
node_lon = ((double)_location->getLongitude()) / 1000000.;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
node_altitude = ((double)_location->getAltitude()) / 1000.0;
MESH_DEBUG_PRINTLN("lat %f lon %f alt %f", node_lat, node_lon, node_altitude);
}
// In powersaving mode, GPS is on and off. Only update data when GPS is on
if (powersaving_enabled) next_gps_update = millis() + 1000;
}
if (!powersaving_enabled) next_gps_update = millis() + 1000;
}
}
@@ -100,8 +148,16 @@ const char* HWTSensorManager::getSettingValue(int i) const {
bool HWTSensorManager::setSettingValue(const char* name, const char* value) {
if (strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
if (powersaving_enabled) {
_location->enablePowerSaving(false);
}
stop_gps();
} else {
if (powersaving_enabled) {
_location->enablePowerSaving(true);
}
start_gps();
}
return true;
+1
View File
@@ -15,6 +15,7 @@
class HWTSensorManager : public SensorManager {
bool gps_active = false;
bool gps_wake = false; // In PowerSaving, gps_active can have gps_wake true or false
LocationProvider * _location;
void start_gps();
+74 -10
View File
@@ -81,6 +81,13 @@ mesh::LocalIdentity radio_new_identity() {
void T1000SensorManager::start_gps() {
gps_active = true;
if (powersaving_enabled && _nmea->isPowerSavingEnabled()) {
gps_wake = true; // gps_active is true
_nmea->syncTime(); // Clear GPS data and force sync time
_nmea->setNextSleep(); // Next time to off
}
//_nmea->begin();
// this init sequence should be better
// comes from seeed examples and deals with all gps pins
@@ -104,7 +111,15 @@ void T1000SensorManager::start_gps() {
}
void T1000SensorManager::sleep_gps() {
gps_active = false;
if (powersaving_enabled && _nmea->isPowerSavingEnabled()) {
gps_wake = false; // gps_active is unchanged (true) even the GPS sleep (e.g: off)
_nmea->stopTimeSync(); // Stop time sync
_nmea->setNextWake(); // Next time to on
} else {
gps_active = false;
gps_wake = false; // When GPS is off, wake is false to be sure
}
digitalWrite(GPS_VRTC_EN, HIGH);
digitalWrite(GPS_EN, LOW);
digitalWrite(GPS_RESET, HIGH);
@@ -116,7 +131,15 @@ void T1000SensorManager::sleep_gps() {
}
void T1000SensorManager::stop_gps() {
gps_active = false;
if (powersaving_enabled && _nmea->isPowerSavingEnabled()) {
gps_wake = false; // gps_active is unchanged (true) even the GPS sleep (e.g: off)
_nmea->stopTimeSync(); // Stop time sync
_nmea->setNextWake(); // Next time to on
} else {
gps_active = false;
gps_wake = false; // When GPS is off, wake is false to be sure
}
digitalWrite(GPS_VRTC_EN, LOW);
digitalWrite(GPS_EN, LOW);
digitalWrite(GPS_RESET, HIGH);
@@ -149,16 +172,49 @@ bool T1000SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP&
void T1000SensorManager::loop() {
static long next_gps_update = 0;
_nmea->loop();
// PowerSaving
if (powersaving_enabled) {
if (_nmea->isPowerSavingEnabled()) {
if (gps_wake && ((int32_t)(millis() - _nmea->getNextSleep()) >= 0 ||
!_nmea->waitingTimeSync())) { // Time to off or GPS set
if ((int32_t)(millis() - _nmea->getNextSleep()) >= 0) {
POWERSAVING_DEBUG_PRINTLN("GPS wake timeout. Enter sleep");
} else if (!_nmea->waitingTimeSync()) {
POWERSAVING_DEBUG_PRINTLN("GPS set. Enter sleep early");
}
if (millis() > next_gps_update) {
if (gps_active && _nmea->isValid()) {
node_lat = ((double)_nmea->getLatitude())/1000000.;
node_lon = ((double)_nmea->getLongitude())/1000000.;
node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
//Serial.printf("lat %f lon %f\r\n", _lat, _lon);
stop_gps();
} else if (!gps_wake && ((int32_t)(millis() - _nmea->getNextWake()) >= 0)) { // Time to on
POWERSAVING_DEBUG_PRINTLN("GPS sleep timeout. Wakeup.");
start_gps();
} else if (!gps_wake && _nmea->waitingTimeSync()) { // On for "gps sync"
POWERSAVING_DEBUG_PRINTLN("CLI gps sync. Wakeup");
start_gps();
}
}
next_gps_update = millis() + 1000;
}
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
_nmea->loop();
}
if ((int32_t)(millis() - next_gps_update) >= 0) {
if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) {
if (_nmea->isValid()) {
node_lat = ((double)_nmea->getLatitude()) / 1000000.;
node_lon = ((double)_nmea->getLongitude()) / 1000000.;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
MESH_DEBUG_PRINTLN("lat %f lon %f alt %f", node_lat, node_lon, node_altitude);
}
// In powersaving mode, GPS is on and off. Only update data when GPS is on
if (powersaving_enabled) next_gps_update = millis() + 1000;
}
if (!powersaving_enabled) next_gps_update = millis() + 1000;
}
}
@@ -176,8 +232,16 @@ const char* T1000SensorManager::getSettingValue(int i) const {
bool T1000SensorManager::setSettingValue(const char* name, const char* value) {
if (strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) {
if (powersaving_enabled) {
_nmea->enablePowerSaving(false);
}
sleep_gps(); // sleep for faster fix !
} else {
if (powersaving_enabled) {
_nmea->enablePowerSaving(true);
}
start_gps();
}
return true;
+1
View File
@@ -14,6 +14,7 @@
class T1000SensorManager: public SensorManager {
bool gps_active = false;
bool gps_wake = false; // In PowerSaving, gps_active can have gps_wake true or false
LocationProvider * _nmea;
void start_gps();