From a7a4e52947b3f077547fd49016a79ea2a1d8f70b Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Mon, 20 Jul 2026 16:19:27 +0700 Subject: [PATCH 01/21] GPS PowerSaving v1.1: Added support for BLE companions --- examples/companion_radio/main.cpp | 12 ++++ examples/simple_repeater/main.cpp | 12 ++++ src/MeshCore.h | 9 +++ src/helpers/CommonCLI.cpp | 6 +- .../sensors/EnvironmentSensorManager.cpp | 64 +++++++++---------- .../sensors/EnvironmentSensorManager.h | 1 + src/helpers/sensors/LocationProvider.h | 26 +++++--- 7 files changed, 85 insertions(+), 45 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index f10cb1702..364a5bb5b 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -234,6 +234,18 @@ void setup() { #error "need to define filesystem" #endif +#if ENV_INCLUDE_GPS == 1 + // Apply PowerSaving profile for GPS + if(sensors.getLocationProvider() != NULL) { + // Enable by default + sensors.powersaving_enabled = true; + sensors.getLocationProvider()->enablePowerSaving(true); + + // Set GPS on and off duration in seconds + sensors.getLocationProvider()->setPowerSavingProfile(600, 300); // Max 10 minutes, 5 minutes + } +#endif + sensors.begin(); #if ENV_INCLUDE_GPS == 1 diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 82e2a2121..b2c3d0566 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -87,6 +87,18 @@ void setup() { command[0] = 0; +#if ENV_INCLUDE_GPS == 1 + // Apply PowerSaving profile for GPS + if (sensors.getLocationProvider() != NULL) { + // Let CLI "gps on" call setSettingValue to enable the PowerSaving mode + // sensors.powersaving_enabled = true; + // sensors.getLocationProvider()->enablePowerSaving(true); + + // GPS on and off duration in seconds + sensors.getLocationProvider()->setPowerSavingProfile(600, 86400); // Max 10 minutes, 1 day + } +#endif + sensors.begin(); the_mesh.begin(fs); diff --git a/src/MeshCore.h b/src/MeshCore.h index 4c23b415f..c3f417a49 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -37,6 +37,15 @@ #define BRIDGE_DEBUG_PRINTLN(...) {} #endif +#if POWERSAVING_DEBUG && ARDUINO + #include + #define POWERSAVING_DEBUG_PRINT(F, ...) Serial.printf("POWERSAVING: " F, ##__VA_ARGS__) + #define POWERSAVING_DEBUG_PRINTLN(F, ...) Serial.printf("POWERSAVING: " F "\n", ##__VA_ARGS__) +#else + #define POWERSAVING_DEBUG_PRINT(...) {} + #define POWERSAVING_DEBUG_PRINTLN(...) {} +#endif + namespace mesh { #define BD_STARTUP_NORMAL 0 // getStartupReason() codes diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 77f7a13d3..5e5cddb4a 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -436,9 +436,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re int sats = l->satellitesCount(); bool active = !strcmp(_sensors->getSettingByKey("gps"), "1"); - if (_prefs->powersaving_enabled && l->getGPSPowerSaving()) { // GPS Power Saving + if (_prefs->powersaving_enabled && l->isPowerSavingEnabled()) { // GPS Power Saving if (enabled) { - unsigned long mins = (l->getNextGPSOff() - millis()) / 60000UL; + unsigned long mins = (l->getNextSleep() - millis()) / 60000UL; sprintf(reply, "on (powersaving, sleep in %luh %lum), %s, %s, %d sats", mins / 60UL, mins % 60UL, @@ -446,7 +446,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re fix ? "fix" : "no fix", sats); } else { - unsigned long mins = (l->getNextGPSOn() - millis()) / 60000UL; + unsigned long mins = (l->getNextWake() - millis()) / 60000UL; sprintf(reply, "off (powersaving, wake in %luh %lum)", mins / 60UL, mins % 60UL); diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index fc66651a5..12f196b96 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -621,12 +621,6 @@ 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 @@ -737,13 +731,13 @@ bool EnvironmentSensorManager::setSettingValue(const char* name, const char* val if (gps_detected && strcmp(name, "gps") == 0) { if (strcmp(value, "0") == 0) { if (powersaving_enabled) { - _location->setGPSPowerSaving(false); + _location->enablePowerSaving(false); } stop_gps(); } else { if (powersaving_enabled) { - _location->setGPSPowerSaving(true); + _location->enablePowerSaving(true); } start_gps(); @@ -885,6 +879,13 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ void EnvironmentSensorManager::start_gps() { 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 + } + #ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, HIGH); @@ -897,22 +898,19 @@ 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; - - if (powersaving_enabled && _location->getGPSPowerSaving()) { + 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->setNextGPSOn(millis() + GPS_OFF_DURATION_SECS * 1000UL); // Next time to on + _location->setNextWake(); // Next time to on + } else { + gps_active = false; + gps_wake = false; // When GPS is off, wake is false to be sure } -#ifdef RAK_WISBLOCK_GPS + #ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, LOW); return; @@ -934,37 +932,35 @@ void EnvironmentSensorManager::loop() { // PowerSaving if (powersaving_enabled) { - if (gps_detected && _location->getGPSPowerSaving()) { - if (gps_active && ((int32_t)(millis() - _location->getNextGPSOff()) >= 0 || + if (gps_detected && _location->isPowerSavingEnabled()) { + if (gps_wake && ((int32_t)(millis() - _location->getNextSleep()) >= 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 + 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"); + } stop_gps(); - } else if (!gps_active && ((int32_t)(millis() - _location->getNextGPSOn()) >= 0)) { // Time to on - // --- TO REMOVE - Serial.println("Timeout, on"); - // --- TO REMOVE + } 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_active && _location->waitingTimeSync()) { // On for "gps sync" - // --- TO REMOVE - Serial.println("gps sync CLI, on"); - // --- TO REMOVE + } else if (!gps_wake && _location->waitingTimeSync()) { // On for "gps sync" + POWERSAVING_DEBUG_PRINTLN("CLI gps sync. Wakeup"); start_gps(); } } } - if (gps_active) { + if ((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)) { _location->loop(); } if ((int32_t)(millis() - next_gps_update) >= 0) { - if(gps_active){ + if((!powersaving_enabled && gps_active) || (powersaving_enabled && gps_wake)){ #ifdef RAK_WISBLOCK_GPS if ((i2cGPSFlag || serialGPSFlag) && _location->isValid()) { node_lat = ((double)_location->getLatitude())/1000000.; diff --git a/src/helpers/sensors/EnvironmentSensorManager.h b/src/helpers/sensors/EnvironmentSensorManager.h index 29147c896..40c44e908 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.h +++ b/src/helpers/sensors/EnvironmentSensorManager.h @@ -21,6 +21,7 @@ protected: bool gps_detected = false; bool gps_active = false; + bool gps_wake = false; // In PowerSaving, gps_active can have gps_wake true or false uint32_t gps_update_interval_sec = 1; #if ENV_INCLUDE_GPS diff --git a/src/helpers/sensors/LocationProvider.h b/src/helpers/sensors/LocationProvider.h index 34c2fc2e3..810750409 100644 --- a/src/helpers/sensors/LocationProvider.h +++ b/src/helpers/sensors/LocationProvider.h @@ -6,22 +6,32 @@ class LocationProvider { protected: bool _time_sync_needed = true; + bool powersaving_enabled = false; - unsigned long _next_gps_off = 0; - unsigned long _next_gps_on = 0; + unsigned long _wake_duration_secs = 86400; // Full day + unsigned long _sleep_duration_secs = 0; // No off + unsigned long _next_wake = 0; + unsigned long _next_sleep = 0; unsigned long _last_valid_time_sync = 0; public: virtual void syncTime() { _time_sync_needed = true; } virtual bool waitingTimeSync() { return _time_sync_needed; } virtual void stopTimeSync() { _time_sync_needed = false; } - virtual void setGPSPowerSaving(bool enabled) { powersaving_enabled = enabled; _next_gps_off = 0; _next_gps_on = 0; } - virtual bool getGPSPowerSaving() { return powersaving_enabled; } - virtual void setNextGPSOff(unsigned long _millis) { _next_gps_off = _millis; } - virtual unsigned long getNextGPSOff() { return _next_gps_off; } - virtual void setNextGPSOn(unsigned long _millis) { _next_gps_on = _millis; } - virtual unsigned long getNextGPSOn() { return _next_gps_on; } + + virtual void setPowerSavingProfile(unsigned long wake_duration_secs, unsigned long sleep_duration_secs) { + _wake_duration_secs = wake_duration_secs; + _sleep_duration_secs = sleep_duration_secs; + } + + virtual void enablePowerSaving(bool enabled) { powersaving_enabled = enabled; _next_wake = 0; _next_sleep = 0; } + virtual bool isPowerSavingEnabled() { return powersaving_enabled; } + virtual void setNextWake() { _next_wake = millis() + _sleep_duration_secs * 1000UL; } + virtual unsigned long getNextWake() { return _next_wake; } + virtual void setNextSleep() { _next_sleep = millis() + _wake_duration_secs * 1000UL; } + virtual unsigned long getNextSleep() { return _next_sleep; } virtual unsigned long getLastValidTimeSync() { return _last_valid_time_sync; } + virtual long getLatitude() = 0; virtual long getLongitude() = 0; virtual long getAltitude() = 0; From 75cc95f17fd6599402dd07c0bbd86addabef7857 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Mon, 20 Jul 2026 22:47:27 +0700 Subject: [PATCH 02/21] GPS PowerSaving 1.2: Fix gps on / off for RAK boards --- .../sensors/EnvironmentSensorManager.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 12f196b96..18ec7dad1 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -798,6 +798,7 @@ void EnvironmentSensorManager::initBasicGPS() { // gps code for rak might be moved to MicroNMEALoactionProvider // or make a new location provider ... #ifdef RAK_WISBLOCK_GPS +static int8_t RAK_GPS_EN = -1; void EnvironmentSensorManager::rakGPSInit(){ Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX); @@ -809,13 +810,13 @@ void EnvironmentSensorManager::rakGPSInit(){ #endif //search for the correct IO standby pin depending on socket used - if(gpsIsAwake(WB_IO2)){ - } - else if(gpsIsAwake(WB_IO4)){ - } - else if(gpsIsAwake(WB_IO5)){ - } - else{ + if (gpsIsAwake(WB_IO2)) { + RAK_GPS_EN = WB_IO2; + } else if (gpsIsAwake(WB_IO4)) { + RAK_GPS_EN = WB_IO4; + } else if (gpsIsAwake(WB_IO5)) { + RAK_GPS_EN = WB_IO5; + } else { MESH_DEBUG_PRINTLN("No GPS found"); gps_active = false; gps_detected = false; @@ -889,6 +890,7 @@ void EnvironmentSensorManager::start_gps() { #ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, HIGH); + gpsIsAwake(RAK_GPS_EN); // Turn on UART L76K for RAK12500 or I2C for RAK12501 return; #endif @@ -913,6 +915,7 @@ void EnvironmentSensorManager::stop_gps() { #ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, LOW); + digitalWrite(RAK_GPS_EN, LOW); // Cut off power return; #endif From d16843d5ea0b3a2d075bb7e0811714d4c222cb01 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Wed, 22 Jul 2026 12:07:27 +0700 Subject: [PATCH 03/21] GPS PowerSaving v1.3: Supported dynamic GPS_EN for RAK boards --- .../sensors/EnvironmentSensorManager.cpp | 56 +++++++++---------- src/helpers/sensors/LocationProvider.h | 2 + .../sensors/MicroNMEALocationProvider.h | 8 +++ 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 18ec7dad1..0156a03a8 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -185,6 +185,7 @@ class RAK12500LocationProvider : public LocationProvider { int _sats = 0; long _epoch = 0; bool _fix = false; + int _pin_en = -1; public: long getLatitude() override { return _lat; } long getLongitude() override { return _lng; } @@ -209,6 +210,8 @@ public: _epoch = ublox_GNSS.getUnixEpoch(2); } bool isEnabled() override { return true; } + void setPinEn(int pin_en) override { _pin_en = pin_en; } + int getPinEn() override { return _pin_en; } }; static RAK12500LocationProvider RAK12500_provider; @@ -798,24 +801,22 @@ void EnvironmentSensorManager::initBasicGPS() { // gps code for rak might be moved to MicroNMEALoactionProvider // or make a new location provider ... #ifdef RAK_WISBLOCK_GPS -static int8_t RAK_GPS_EN = -1; -void EnvironmentSensorManager::rakGPSInit(){ - +void EnvironmentSensorManager::rakGPSInit() { Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX); - #ifdef GPS_BAUD_RATE +#ifdef GPS_BAUD_RATE Serial1.begin(GPS_BAUD_RATE); - #else +#else Serial1.begin(9600); - #endif +#endif - //search for the correct IO standby pin depending on socket used + // search for the correct IO standby pin depending on socket used if (gpsIsAwake(WB_IO2)) { - RAK_GPS_EN = WB_IO2; + _location->setPinEn(WB_IO2); } else if (gpsIsAwake(WB_IO4)) { - RAK_GPS_EN = WB_IO4; + _location->setPinEn(WB_IO4); } else if (gpsIsAwake(WB_IO5)) { - RAK_GPS_EN = WB_IO5; + _location->setPinEn(WB_IO5); } else { MESH_DEBUG_PRINTLN("No GPS found"); gps_active = false; @@ -824,24 +825,23 @@ void EnvironmentSensorManager::rakGPSInit(){ return; } - #ifndef FORCE_GPS_ALIVE // for use with repeaters, until GPS toggle is implimented - //Now that GPS is found and set up, set to sleep for initial state +#ifndef FORCE_GPS_ALIVE // for use with repeaters, until GPS toggle is implimented + // Now that GPS is found and set up, set to sleep for initial state stop_gps(); - #endif +#endif } -bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ - - //set initial waking state - pinMode(ioPin,OUTPUT); - digitalWrite(ioPin,LOW); +bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin) { + // set initial waking state + pinMode(ioPin, OUTPUT); + digitalWrite(ioPin, LOW); delay(500); - digitalWrite(ioPin,HIGH); + digitalWrite(ioPin, HIGH); delay(500); - //Try to init RAK12500 on I2C - if (ublox_GNSS.begin(Wire) == true){ - MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i",ioPin); + // Try to init RAK12500 on I2C + if (ublox_GNSS.begin(Wire) == true) { + MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i", ioPin); ublox_GNSS.setI2COutput(COM_TYPE_UBX); ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GPS); ublox_GNSS.enableGNSS(true, SFE_UBLOX_GNSS_ID_GALILEO); @@ -859,10 +859,10 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){ _location = &RAK12500_provider; return true; - } else if (Serial1.available()) { + } else if (Serial1.available()) { // RAK12501 (L76K) on UART MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on"); #ifdef PIN_GPS_EN - if(PIN_GPS_EN){ + if (PIN_GPS_EN) { gpsResetPin = PIN_GPS_EN; } #endif @@ -887,12 +887,12 @@ void EnvironmentSensorManager::start_gps() { _location->setNextSleep(); // Next time to off } - #ifdef RAK_WISBLOCK_GPS +#ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, HIGH); - gpsIsAwake(RAK_GPS_EN); // Turn on UART L76K for RAK12500 or I2C for RAK12501 + gpsIsAwake(_location->getPinEn()); // Turn on UART L76K for RAK12500 or I2C for RAK12501 return; - #endif +#endif _location->begin(); _location->reset(); @@ -915,7 +915,7 @@ void EnvironmentSensorManager::stop_gps() { #ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, LOW); - digitalWrite(RAK_GPS_EN, LOW); // Cut off power + digitalWrite(_location->getPinEn(), LOW); // Cut off power return; #endif diff --git a/src/helpers/sensors/LocationProvider.h b/src/helpers/sensors/LocationProvider.h index 810750409..c9204373e 100644 --- a/src/helpers/sensors/LocationProvider.h +++ b/src/helpers/sensors/LocationProvider.h @@ -44,4 +44,6 @@ public: virtual void stop() = 0; virtual void loop() = 0; virtual bool isEnabled() = 0; + virtual void setPinEn(int pin_en) = 0; + virtual int getPinEn() = 0; }; diff --git a/src/helpers/sensors/MicroNMEALocationProvider.h b/src/helpers/sensors/MicroNMEALocationProvider.h index a670b4427..dd569062b 100644 --- a/src/helpers/sensors/MicroNMEALocationProvider.h +++ b/src/helpers/sensors/MicroNMEALocationProvider.h @@ -111,6 +111,14 @@ public : } } + void setPinEn(int pin_en) override { + _pin_en = pin_en; + } + + int getPinEn() override { + return _pin_en; + } + void syncTime() override { nmea.clear(); LocationProvider::syncTime(); } long getLatitude() override { return nmea.getLatitude(); } long getLongitude() override { return nmea.getLongitude(); } From d6c61af7c7ed2e402525fe653f65ebc7ed45f1d6 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Wed, 22 Jul 2026 16:19:54 +0700 Subject: [PATCH 04/21] Added POWERSAVING_DEBUG=1 --- variants/heltec_t096/platformio.ini | 2 ++ variants/heltec_t114/platformio.ini | 2 ++ variants/rak4631/platformio.ini | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/variants/heltec_t096/platformio.ini b/variants/heltec_t096/platformio.ini index 5f17436ad..1961b3747 100644 --- a/variants/heltec_t096/platformio.ini +++ b/variants/heltec_t096/platformio.ini @@ -69,6 +69,7 @@ build_flags = -D MAX_NEIGHBOURS=50 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +; -D POWERSAVING_DEBUG=1 [env:Heltec_t096_repeater_bridge_rs232] extends = Heltec_t096 @@ -135,6 +136,7 @@ build_flags = -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +; -D POWERSAVING_DEBUG=1 build_src_filter = ${Heltec_t096.build_src_filter} + +<../examples/companion_radio/*.cpp> diff --git a/variants/heltec_t114/platformio.ini b/variants/heltec_t114/platformio.ini index e808d6c28..9817bc72c 100644 --- a/variants/heltec_t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -170,6 +170,7 @@ build_flags = -D MAX_NEIGHBOURS=50 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +; -D POWERSAVING_DEBUG=1 [env:Heltec_t114_repeater_bridge_rs232] extends = Heltec_t114 @@ -219,6 +220,7 @@ build_flags = -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +; -D POWERSAVING_DEBUG=1 build_src_filter = ${Heltec_t114_with_display.build_src_filter} + +<../examples/companion_radio/*.cpp> diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 8f72999af..bcaacc47e 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -50,6 +50,7 @@ build_flags = -D MAX_NEIGHBOURS=50 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +; -D POWERSAVING_DEBUG=1 build_src_filter = ${rak4631.build_src_filter} + +<../examples/simple_repeater> @@ -150,10 +151,11 @@ build_flags = -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 - -D BLE_DEBUG_LOGGING=1 +; -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 +; -D POWERSAVING_DEBUG=1 build_src_filter = ${rak4631.build_src_filter} + +<../examples/companion_radio/*.cpp> From 0843c7c5aef0aedf04cd712c0281821693641946 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Thu, 23 Jul 2026 12:26:31 +0700 Subject: [PATCH 05/21] Fix blank OLED on T-Beam Supreme V3 (I2C bus init + 0x3D address) https://github.com/meshcore-dev/MeshCore/pull/2815 --- src/helpers/esp32/TBeamBoard.cpp | 10 ++++++++++ src/helpers/ui/SH1106Display.cpp | 5 ++++- variants/lilygo_tbeam_supreme_SX1262/platformio.ini | 5 +---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/helpers/esp32/TBeamBoard.cpp b/src/helpers/esp32/TBeamBoard.cpp index 5f708d71d..d9f6e0227 100644 --- a/src/helpers/esp32/TBeamBoard.cpp +++ b/src/helpers/esp32/TBeamBoard.cpp @@ -16,6 +16,16 @@ void TBeamBoard::begin() { ESP32Board::begin(); +#ifdef TBEAM_SUPREME_SX1262 + // On the T-Beam S3 Supreme the PMU + RTC sit on Wire1 (GPIO 42/41, brought + // up by XPowersLib), while the SH1106 OLED and the BME280/QMC6310 sensors + // sit on the primary bus, Wire (GPIO PIN_BOARD_SDA/PIN_BOARD_SCL). Nothing + // else initialises Wire on this board, so the display driver would + // otherwise talk on the wrong (default) pins and display.begin() fails, + // leaving the screen blank. Bring the OLED bus up here. + Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL); +#endif + power_init(); //Configure user button diff --git a/src/helpers/ui/SH1106Display.cpp b/src/helpers/ui/SH1106Display.cpp index f383bb005..57ccfc2e4 100644 --- a/src/helpers/ui/SH1106Display.cpp +++ b/src/helpers/ui/SH1106Display.cpp @@ -11,7 +11,10 @@ bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr) bool SH1106Display::begin() { - return display.begin(DISPLAY_ADDRESS, true) && i2c_probe(Wire, DISPLAY_ADDRESS); + // Wire must already be initialised by board.begin() before this is called. + // Boards with non-standard SH1106 addresses should define DISPLAY_ADDRESS + // in their variant/platformio configuration. + return i2c_probe(Wire, DISPLAY_ADDRESS) && display.begin(DISPLAY_ADDRESS, true); } void SH1106Display::turnOn() diff --git a/variants/lilygo_tbeam_supreme_SX1262/platformio.ini b/variants/lilygo_tbeam_supreme_SX1262/platformio.ini index b930a25b9..8bfc4093a 100644 --- a/variants/lilygo_tbeam_supreme_SX1262/platformio.ini +++ b/variants/lilygo_tbeam_supreme_SX1262/platformio.ini @@ -18,6 +18,7 @@ build_flags = -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D DISPLAY_CLASS=SH1106Display + -D DISPLAY_ADDRESS=0x3D -D LORA_TX_POWER=22 -D P_LORA_TX_LED=6 -D PIN_BOARD_SDA=17 @@ -142,10 +143,6 @@ lib_deps = ${T_Beam_S3_Supreme_SX1262.lib_deps} densaugeo/base64 @ ~1.4.0 -[env:T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps] -extends = env:T_Beam_S3_Supreme_SX1262_companion_radio_ble -platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 - [env:T_Beam_S3_Supreme_SX1262_companion_radio_wifi] extends = T_Beam_S3_Supreme_SX1262 build_flags = From a2fe2ea642ad07c7adaa9c45d8ab247907431beb Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Thu, 23 Jul 2026 12:35:43 +0700 Subject: [PATCH 06/21] Added T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps --- variants/lilygo_tbeam_supreme_SX1262/platformio.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/variants/lilygo_tbeam_supreme_SX1262/platformio.ini b/variants/lilygo_tbeam_supreme_SX1262/platformio.ini index 8bfc4093a..2801b8d6e 100644 --- a/variants/lilygo_tbeam_supreme_SX1262/platformio.ini +++ b/variants/lilygo_tbeam_supreme_SX1262/platformio.ini @@ -143,6 +143,10 @@ lib_deps = ${T_Beam_S3_Supreme_SX1262.lib_deps} densaugeo/base64 @ ~1.4.0 +[env:T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps] +extends = env:T_Beam_S3_Supreme_SX1262_companion_radio_ble +platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 + [env:T_Beam_S3_Supreme_SX1262_companion_radio_wifi] extends = T_Beam_S3_Supreme_SX1262 build_flags = From 0cc580afec363aab20608528abd847afb271285b Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Thu, 23 Jul 2026 23:21:41 +0700 Subject: [PATCH 07/21] 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). --- build-iotthinks.sh | 61 +++++++++++++++++++ variants/heltec_mesh_solar/target.cpp | 74 ++++++++++++++++++++--- variants/heltec_mesh_solar/target.h | 1 + variants/heltec_tracker/target.cpp | 74 ++++++++++++++++++++--- variants/heltec_tracker/target.h | 1 + variants/t1000-e/target.cpp | 84 +++++++++++++++++++++++---- variants/t1000-e/target.h | 1 + 7 files changed, 268 insertions(+), 28 deletions(-) diff --git a/build-iotthinks.sh b/build-iotthinks.sh index 613789d08..535c202a2 100644 --- a/build-iotthinks.sh +++ b/build-iotthinks.sh @@ -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 \ + diff --git a/variants/heltec_mesh_solar/target.cpp b/variants/heltec_mesh_solar/target.cpp index d140864cd..256b70a7c 100644 --- a/variants/heltec_mesh_solar/target.cpp +++ b/variants/heltec_mesh_solar/target.cpp @@ -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; diff --git a/variants/heltec_mesh_solar/target.h b/variants/heltec_mesh_solar/target.h index 1956f50eb..13c7a55c3 100644 --- a/variants/heltec_mesh_solar/target.h +++ b/variants/heltec_mesh_solar/target.h @@ -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(); diff --git a/variants/heltec_tracker/target.cpp b/variants/heltec_tracker/target.cpp index f32c41ff4..c51da013c 100644 --- a/variants/heltec_tracker/target.cpp +++ b/variants/heltec_tracker/target.cpp @@ -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; diff --git a/variants/heltec_tracker/target.h b/variants/heltec_tracker/target.h index 2931eda81..0fe3d0251 100644 --- a/variants/heltec_tracker/target.h +++ b/variants/heltec_tracker/target.h @@ -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(); diff --git a/variants/t1000-e/target.cpp b/variants/t1000-e/target.cpp index 425328270..99c9be29a 100644 --- a/variants/t1000-e/target.cpp +++ b/variants/t1000-e/target.cpp @@ -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; diff --git a/variants/t1000-e/target.h b/variants/t1000-e/target.h index db003cc5f..cd91ceec9 100644 --- a/variants/t1000-e/target.h +++ b/variants/t1000-e/target.h @@ -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(); From a54ef6e7cc5247c5b2d266d687f496798e4aa8e9 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Fri, 31 Jul 2026 11:57:02 +0700 Subject: [PATCH 08/21] Added universal fix to support OLED for all versions of T-Beam Supreme --- src/helpers/ui/SH1106Display.cpp | 16 ++++++++++++++-- .../lilygo_tbeam_supreme_SX1262/platformio.ini | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/helpers/ui/SH1106Display.cpp b/src/helpers/ui/SH1106Display.cpp index 57ccfc2e4..868305615 100644 --- a/src/helpers/ui/SH1106Display.cpp +++ b/src/helpers/ui/SH1106Display.cpp @@ -13,8 +13,20 @@ bool SH1106Display::begin() { // Wire must already be initialised by board.begin() before this is called. // Boards with non-standard SH1106 addresses should define DISPLAY_ADDRESS - // in their variant/platformio configuration. - return i2c_probe(Wire, DISPLAY_ADDRESS) && display.begin(DISPLAY_ADDRESS, true); + // in their variant/platformio configuration. Some board revisions may have + // different solder-bridge address configurations, so variants can also + // provide DISPLAY_ADDRESS_ALT as a fallback. + if (i2c_probe(Wire, DISPLAY_ADDRESS) && display.begin(DISPLAY_ADDRESS, true)) { + return true; + } +#ifdef DISPLAY_ADDRESS_ALT + if (DISPLAY_ADDRESS_ALT != DISPLAY_ADDRESS && + i2c_probe(Wire, DISPLAY_ADDRESS_ALT) && + display.begin(DISPLAY_ADDRESS_ALT, true)) { + return true; + } +#endif + return false; } void SH1106Display::turnOn() diff --git a/variants/lilygo_tbeam_supreme_SX1262/platformio.ini b/variants/lilygo_tbeam_supreme_SX1262/platformio.ini index 2801b8d6e..d2573f144 100644 --- a/variants/lilygo_tbeam_supreme_SX1262/platformio.ini +++ b/variants/lilygo_tbeam_supreme_SX1262/platformio.ini @@ -19,6 +19,7 @@ build_flags = -D WRAPPER_CLASS=CustomSX1262Wrapper -D DISPLAY_CLASS=SH1106Display -D DISPLAY_ADDRESS=0x3D + -D DISPLAY_ADDRESS_ALT=0x3C -D LORA_TX_POWER=22 -D P_LORA_TX_LED=6 -D PIN_BOARD_SDA=17 From 07172b7c54e875bb508687e6203e4f177d09e364 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Fri, 31 Jul 2026 20:57:22 +0700 Subject: [PATCH 09/21] Added battery voltage and Powersaving status to repeater OLED --- examples/simple_repeater/UITask.cpp | 13 ++++++++++++- examples/simple_repeater/UITask.h | 3 ++- examples/simple_repeater/main.cpp | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/simple_repeater/UITask.cpp b/examples/simple_repeater/UITask.cpp index 6a8514388..544d7884d 100644 --- a/examples/simple_repeater/UITask.cpp +++ b/examples/simple_repeater/UITask.cpp @@ -26,10 +26,11 @@ static const uint8_t meshcore_logo [] PROGMEM = { 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, }; -void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) { +void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, mesh::MainBoard* board) { _prevBtnState = HIGH; _auto_off = millis() + AUTO_OFF_MILLIS; _node_prefs = node_prefs; + _board = board; _display->turnOn(); // strip off dash and commit hash by changing dash to null terminator @@ -89,6 +90,16 @@ void UITask::renderCurrScreen() { _display->setCursor(0, 30); sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr); _display->print(tmp); + + // Battery + _display->setCursor(0, 40); + sprintf(tmp, "BAT: %.2fV", _board->getBattMilliVolts() / 1000.0); + _display->print(tmp); + + // PowerSaving + _display->setCursor(0, 50); + sprintf(tmp, "PowerSaving: %s", _node_prefs->powersaving_enabled? "ON" : "off"); + _display->print(tmp); } } diff --git a/examples/simple_repeater/UITask.h b/examples/simple_repeater/UITask.h index a27259f11..106c56c3d 100644 --- a/examples/simple_repeater/UITask.h +++ b/examples/simple_repeater/UITask.h @@ -9,11 +9,12 @@ class UITask { int _prevBtnState; NodePrefs* _node_prefs; char _version_info[32]; + mesh::MainBoard* _board; void renderCurrScreen(); public: UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; } - void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version); + void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, mesh::MainBoard* board); void loop(); }; \ No newline at end of file diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index b2c3d0566..f135f20af 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -104,7 +104,7 @@ void setup() { the_mesh.begin(fs); #ifdef DISPLAY_CLASS - ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); + ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION, &board); #endif // send out initial zero hop Advertisement to the mesh From e90b5dc87d21a828a752e5b48c59f70afd44aafb Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Fri, 31 Jul 2026 20:58:20 +0700 Subject: [PATCH 10/21] Fixed GPS for M6 and disabled log --- variants/thinknode_m6/platformio.ini | 6 +++--- variants/thinknode_m6/variant.cpp | 6 ++++-- variants/thinknode_m6/variant.h | 6 +++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/variants/thinknode_m6/platformio.ini b/variants/thinknode_m6/platformio.ini index 6fe904366..7d6d951fe 100644 --- a/variants/thinknode_m6/platformio.ini +++ b/variants/thinknode_m6/platformio.ini @@ -48,8 +48,8 @@ build_flags = -D ADMIN_PASSWORD='"password"' -D MAX_NEIGHBOURS=50 ; -D MESH_PACKET_LOGGING=1 - -D MESH_DEBUG=1 - -D GPS_NMEA_DEBUG=1 +; -D MESH_DEBUG=1 +; -D GPS_NMEA_DEBUG=1 build_src_filter = ${ThinkNode_M6.build_src_filter} +<../examples/simple_repeater/*.cpp> lib_deps = @@ -81,7 +81,7 @@ build_flags = -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 - -D BLE_DEBUG_LOGGING=1 +; -D BLE_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 -D AUTO_SHUTDOWN_MILLIVOLTS=3300 -D QSPIFLASH=1 diff --git a/variants/thinknode_m6/variant.cpp b/variants/thinknode_m6/variant.cpp index c88f387db..ba10fe02b 100644 --- a/variants/thinknode_m6/variant.cpp +++ b/variants/thinknode_m6/variant.cpp @@ -30,6 +30,8 @@ void initVariant() { digitalWrite(PIN_GPS_STANDBY, HIGH); pinMode(PIN_GPS_EN, OUTPUT); digitalWrite(PIN_GPS_EN, HIGH); - pinMode(PIN_GPS_RESET, OUTPUT); - digitalWrite(PIN_GPS_RESET, HIGH); + // PIN_GPS_RESET (pin 29 / REINIT) is intentionally left floating (input). + // Driving it HIGH holds the L76K silent, so it never streams NMEA and the + // firmware reports "no GPS". Letting it float lets the module run. + // See GPS_RESET (-1) in variant.h. } diff --git a/variants/thinknode_m6/variant.h b/variants/thinknode_m6/variant.h index 70fd65062..1688d94e1 100644 --- a/variants/thinknode_m6/variant.h +++ b/variants/thinknode_m6/variant.h @@ -102,7 +102,11 @@ #define PIN_GPS_RX (2) #define PIN_GPS_TX (3) #define PIN_GPS_EN (6) // EN -#define PIN_GPS_RESET (29) +#define PIN_GPS_RESET (29) // REINIT - must FLOAT; driving it (esp. HIGH) silences the L76K +// The M6's L76K streams NMEA on its own and must not have its REINIT pin driven. +// Tell the location provider there is no reset pin so it never touches pin 29 +// (driving it HIGH holds the module silent). +#define GPS_RESET (-1) #define PIN_GPS_STANDBY (30) // STANDBY #define PIN_GPS_PPS (31) #define GPS_BAUD_RATE 9600 From 4008b68f756ed904d8fefa73de88d88cf5b2da33 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Fri, 31 Jul 2026 20:59:17 +0700 Subject: [PATCH 11/21] Fixed GPS for M3 and disabled log --- variants/thinknode_m3/platformio.ini | 2 +- variants/thinknode_m3/variant.cpp | 5 ++++- variants/thinknode_m3/variant.h | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/variants/thinknode_m3/platformio.ini b/variants/thinknode_m3/platformio.ini index 0a3d4eda9..f23ac87d6 100644 --- a/variants/thinknode_m3/platformio.ini +++ b/variants/thinknode_m3/platformio.ini @@ -27,7 +27,7 @@ build_flags = ${nrf52_base.build_flags} -D P_LORA_TX_LED_ON=LOW -D LR11X0_DIO_AS_RF_SWITCH=true -D LR11X0_DIO3_TCXO_VOLTAGE=3.3 - -D MESH_DEBUG=1 +; -D MESH_DEBUG=1 -D ENV_INCLUDE_GPS=1 build_src_filter = ${nrf52_base.build_src_filter} + diff --git a/variants/thinknode_m3/variant.cpp b/variants/thinknode_m3/variant.cpp index dad0f3f55..efcdadf52 100644 --- a/variants/thinknode_m3/variant.cpp +++ b/variants/thinknode_m3/variant.cpp @@ -87,7 +87,10 @@ void initVariant() pinMode(PIN_GPS_POWER, OUTPUT); pinMode(PIN_GPS_EN, OUTPUT); - pinMode(PIN_GPS_RESET, OUTPUT); + // PIN_GPS_RESET (pin 25 / REINIT) is intentionally left floating (input). + // Driving it HIGH holds the L76K silent, so it never streams NMEA and the + // firmware reports "no GPS". Letting it float lets the module run. + // See GPS_RESET (-1) in variant.h. // Power on gps but in standby digitalWrite(PIN_GPS_EN, LOW); diff --git a/variants/thinknode_m3/variant.h b/variants/thinknode_m3/variant.h index 02ed78a84..f4619ba5d 100644 --- a/variants/thinknode_m3/variant.h +++ b/variants/thinknode_m3/variant.h @@ -97,7 +97,11 @@ #define PIN_GPS_POWER (14) #define PIN_GPS_EN (21) // STANDBY -#define PIN_GPS_RESET (25) // REINIT +#define PIN_GPS_RESET (25) // REINIT - must FLOAT; driving it (esp. HIGH) silences the L76K +// The M6's L76K streams NMEA on its own and must not have its REINIT pin driven. +// Tell the location provider there is no reset pin so it never touches pin 25 +// (driving it HIGH holds the module silent). +#define GPS_RESET (-1) #define GPS_RESET_ACTIVE LOW #define GPS_EN_ACTIVE HIGH #define GPS_BAUDRATE 9600 From 6160509efcc0a3ce57fa32f4d36325c1b98b012e Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Wed, 5 Aug 2026 22:06:23 +0700 Subject: [PATCH 12/21] PowerSaving17: Cleanup for RX PowerSaving --- build-iotthinks.sh | 199 ++++++++-------------- examples/companion_radio/MyMesh.cpp | 50 ++---- examples/simple_repeater/MyMesh.cpp | 5 +- platformio.ini | 8 - src/helpers/CommonCLI.cpp | 101 ++--------- src/helpers/CommonCLI.h | 13 +- src/helpers/radiolib/RXPowerSaving.h | 103 +++++++++++ src/helpers/radiolib/RadioLibWrappers.cpp | 1 + variants/heltec_t096/platformio.ini | 2 - variants/heltec_t114/platformio.ini | 4 - variants/heltec_tracker_v2/platformio.ini | 3 - variants/heltec_v4/platformio.ini | 3 - variants/rak4631/platformio.ini | 2 - variants/t1000-e/platformio.ini | 2 - variants/thinknode_m3/platformio.ini | 2 - variants/xiao_nrf52/platformio.ini | 2 - variants/xiao_s3/platformio.ini | 2 - variants/xiao_s3_wio/platformio.ini | 4 - 18 files changed, 208 insertions(+), 298 deletions(-) create mode 100644 src/helpers/radiolib/RXPowerSaving.h diff --git a/build-iotthinks.sh b/build-iotthinks.sh index 535c202a2..f80a55be3 100644 --- a/build-iotthinks.sh +++ b/build-iotthinks.sh @@ -1,48 +1,51 @@ # sh ./build-repeaters-iotthinks.sh -export FIRMWARE_VERSION="PowerSaving16" +export FIRMWARE_VERSION="PowerSaving17" ############# Repeaters ############# # Commonly-used boards ## ESP32 - 17 boards sh build.sh build-firmware \ +Heltec_ct62_repeater \ +Heltec_E290_repeater \ Heltec_v3_repeater \ -Heltec_WSL3_repeater \ heltec_v4_repeater \ +heltec_tracker_v2_repeater \ +Heltec_Wireless_Paper_repeater \ +Heltec_Wireless_Tracker_repeater \ +Heltec_WSL3_repeater \ +LilyGo_T3S3_sx1262_repeater \ +LilyGo_TBeam_1W_repeater \ Station_G2_repeater \ T_Beam_S3_Supreme_SX1262_repeater \ Tbeam_SX1262_repeater \ -LilyGo_T3S3_sx1262_repeater \ -Xiao_S3_WIO_repeater \ Xiao_C3_repeater \ Xiao_C6_repeater_ \ -Heltec_E290_repeater \ -Heltec_Wireless_Tracker_repeater \ -LilyGo_TBeam_1W_repeater \ Xiao_S3_repeater \ -heltec_tracker_v2_repeater \ -Heltec_Wireless_Paper_repeater \ -Heltec_ct62_repeater +Xiao_S3_WIO_repeater -## NRF52 - 17 boards +## NRF52 - 21 boards sh build.sh build-firmware \ -RAK_4631_repeater \ -Heltec_t114_repeater \ -Xiao_nrf52_repeater \ -Heltec_mesh_solar_repeater \ -ProMicro_repeater \ -SenseCap_Solar_repeater \ -t1000e_repeater \ -LilyGo_T-Echo_repeater \ -WioTrackerL1_repeater \ -RAK_3401_repeater \ -RAK_WisMesh_Tag_repeater \ GAT562_30S_Mesh_Kit_repeater \ GAT562_Mesh_Tracker_Pro_repeater \ +Heltec_mesh_solar_repeater \ +Heltec_t096_repeater \ +Heltec_t1_repeater \ +Heltec_t114_repeater \ ikoka_nano_nrf_22dbm_repeater \ ikoka_nano_nrf_30dbm_repeater \ ikoka_nano_nrf_33dbm_repeater \ +LilyGo_T-Echo_repeater \ +ProMicro_repeater \ +RAK_3401_repeater \ +RAK_4631_repeater \ +RAK_WisMesh_Tag_repeater \ +SenseCap_Solar_repeater \ +t1000e_repeater \ ThinkNode_M1_repeater \ -Heltec_t096_repeater +ThinkNode_M3_repeater \ +ThinkNode_M6_repeater \ +WioTrackerL1_repeater \ +Xiao_nrf52_repeater ## ESP32, SX1276 - 3 boards sh build.sh build-firmware \ @@ -55,62 +58,63 @@ Tbeam_SX1276_repeater sh build.sh build-firmware \ Heltec_v3_room_server \ heltec_v4_room_server \ -LilyGo_TBeam_1W_room_server \ -Heltec_WSL3_room_server \ -Xiao_S3_room_server \ heltec_tracker_v2_room_server \ -Heltec_Wireless_Paper_room_server +Heltec_Wireless_Paper_room_server \ +Heltec_WSL3_room_server \ +LilyGo_TBeam_1W_room_server \ +Xiao_S3_room_server -# NRF52 - 6 boards +# NRF52 - 7 boards sh build.sh build-firmware \ -RAK_4631_room_server \ +Heltec_t096_room_server \ Heltec_t114_room_server \ -Xiao_nrf52_room_server \ +RAK_3401_room_server \ +RAK_4631_room_server \ t1000e_room_server \ WioTrackerL1_room_server \ -RAK_3401_room_server \ -Heltec_t096_room_server +Xiao_nrf52_room_server ############# Companions BLE ############# -# NRF52 - 12 boards +# NRF52 - 15 boards sh build.sh build-firmware \ -RAK_4631_companion_radio_ble \ +Heltec_t096_companion_radio_ble \ +Heltec_t096_companion_radio_ble_femoff \ +Heltec_t1_companion_radio_ble \ Heltec_t114_companion_radio_ble \ -Xiao_nrf52_companion_radio_ble \ -t1000e_companion_radio_ble \ LilyGo_T-Echo_companion_radio_ble \ -WioTrackerL1_companion_radio_ble \ RAK_3401_companion_radio_ble \ +RAK_4631_companion_radio_ble \ RAK_WisMesh_Tag_companion_radio_ble \ SenseCap_Solar_companion_radio_ble \ +t1000e_companion_radio_ble \ ThinkNode_M1_companion_radio_ble \ -Heltec_t096_companion_radio_ble \ -Heltec_t096_companion_radio_ble_femoff +ThinkNode_M3_companion_radio_ble \ +ThinkNode_M6_companion_radio_ble \ +WioTrackerL1_companion_radio_ble \ +Xiao_nrf52_companion_radio_ble ############# Companions BLE PS ############# -# ESP32 - 18 boards +# ESP32 - 19 boards sh build.sh build-firmware \ -Heltec_v3_companion_radio_ble_ps \ -heltec_v4_companion_radio_ble_ps \ -heltec_v4_3_companion_radio_ble_ps_femoff \ -Xiao_C3_companion_radio_ble_ps \ -Xiao_S3_companion_radio_ble_ps \ -Xiao_S3_WIO_companion_radio_ble_ps \ -Heltec_v2_companion_radio_ble_ps \ -LilyGo_TBeam_1W_companion_radio_ble_ps \ -Heltec_WSL3_companion_radio_ble_ps \ -Heltec_Wireless_Tracker_companion_radio_ble_ps \ -heltec_tracker_v2_companion_radio_ble_ps \ -Heltec_Wireless_Paper_companion_radio_ble_ps \ -LilyGo_TLora_V2_1_1_6_companion_radio_ble_ps \ Heltec_ct62_companion_radio_ble_ps \ +heltec_tracker_v2_companion_radio_ble_ps \ +Heltec_v2_companion_radio_ble_ps \ +Heltec_v3_companion_radio_ble_ps \ +heltec_v4_3_companion_radio_ble_ps_femoff \ +heltec_v4_companion_radio_ble_ps \ +heltec_v4_expansionkit_tft_companion_radio_ble_ps \ +Heltec_Wireless_Paper_companion_radio_ble_ps \ +Heltec_Wireless_Tracker_companion_radio_ble_ps \ +Heltec_WSL3_companion_radio_ble_ps \ +LilyGo_T3S3_sx1262_companion_radio_ble_ps \ +LilyGo_TBeam_1W_companion_radio_ble_ps \ +LilyGo_TLora_V2_1_1_6_companion_radio_ble_ps \ T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps \ Tbeam_SX1262_companion_radio_ble_ps \ -heltec_v4_expansionkit_tft_companion_radio_ble_ps \ -LilyGo_T3S3_sx1262_companion_radio_ble_ps - -# Not working Tbeam_SX1276_companion_radio_ble_ps \ +Xiao_C3_companion_radio_ble_ps \ +Xiao_S3_companion_radio_ble_ps \ +Xiao_S3_WIO_companion_radio_ble_ps ############# Companions USB ############# sh build.sh build-firmware \ @@ -119,78 +123,17 @@ Heltec_t096_companion_radio_usb ############# Sample builds ############# # 14 boards sh build.sh build-firmware \ -Heltec_v3_repeater \ -heltec_v4_repeater \ -Xiao_C3_repeater \ -Xiao_C6_repeater_ \ -RAK_4631_repeater \ -Heltec_t096_repeater \ -Heltec_v3_companion_radio_ble_ps \ -heltec_v4_companion_radio_ble_ps \ -heltec_v4_3_companion_radio_ble_ps_femoff \ -Xiao_C3_companion_radio_ble_ps \ -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_t096_repeater \ +Heltec_v3_companion_radio_ble_ps \ +Heltec_v3_repeater \ 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 \ +heltec_v4_companion_radio_ble_ps \ +heltec_v4_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 \ - +RAK_4631_repeater \ +Xiao_C3_companion_radio_ble_ps \ +Xiao_C3_repeater \ +Xiao_C6_companion_radio_ble_ \ +Xiao_C6_repeater_ \ No newline at end of file diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 972755bc6..9ee67445e 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2,6 +2,7 @@ #include // needed for PlatformIO #include +#include "helpers/radiolib/RXPowerSaving.h" #define CMD_APP_START 1 #define CMD_SEND_TXT_MSG 2 @@ -279,47 +280,19 @@ bool MyMesh::getCADEnabled() const { #endif #endif +// RX PowerSaving #ifdef RXPS_FIXED_ENABLED -static uint32_t ceilPositiveFloat(float value) { - uint32_t rounded = (uint32_t)value; - return value > (float)rounded ? rounded + 1 : rounded; -} - -static bool calcFixedRxPowerSaving(uint8_t sf, float bw, uint32_t* rx_us, uint32_t* sleep_us) { - if (RXPS_FIXED_LEVEL < 1 || RXPS_FIXED_LEVEL > 10 || sf < 5 || sf > 12 || - bw <= 0.0f || (RXPS_FIXED_PREAMBLE != 16 && RXPS_FIXED_PREAMBLE != 32)) { - return false; - } - - const float symbol_us = (1000.0f * (float)(1UL << sf)) / bw; - const float amount = (float)(RXPS_FIXED_LEVEL - 1) / 9.0f; - const float rx_start_symbols = RXPS_FIXED_PREAMBLE == 16 ? 12.0f : 16.0f; - const float sleep_start_symbols = RXPS_FIXED_PREAMBLE == 16 ? 2.0f : 15.0f; - const float rx_edge_symbols = 8.0f; - const float sleep_edge_symbols = (float)RXPS_FIXED_PREAMBLE + 4.25f - 8.0f; - - const float rx_symbols = rx_start_symbols + amount * (rx_edge_symbols - rx_start_symbols); - const float sleep_symbols = sleep_start_symbols + amount * (sleep_edge_symbols - sleep_start_symbols); - - *rx_us = ceilPositiveFloat(rx_symbols * symbol_us); - *sleep_us = (uint32_t)(sleep_symbols * symbol_us); - return true; -} - static void applyFixedRxPowerSaving(uint8_t sf, float bw) { uint32_t rx_us, sleep_us; - if (!calcFixedRxPowerSaving(sf, bw, &rx_us, &sleep_us)) { - MESH_DEBUG_PRINTLN("RX Power Saving fixed profile invalid"); + if (!calcRxPowerSavingLevel(RXPS_FIXED_LEVEL, sf, bw, RXPS_FIXED_PREAMBLE, &rx_us, &sleep_us)) { + POWERSAVING_DEBUG_PRINTLN("RX Power Saving fixed profile invalid"); return; } bool ok = radio_driver.setRxPowerSaving(true, rx_us, sleep_us); - MESH_DEBUG_PRINTLN("RX Power Saving fixed level %d p%d: %s (%lu/%lu us)", - RXPS_FIXED_LEVEL, - RXPS_FIXED_PREAMBLE, - ok ? "Enabled" : "Unsupported", - (unsigned long)rx_us, - (unsigned long)sleep_us); + POWERSAVING_DEBUG_PRINTLN("RX Power Saving fixed level %d p%d: %s (%lu/%lu us)", RXPS_FIXED_LEVEL, + RXPS_FIXED_PREAMBLE, ok ? "Enabled" : "Unsupported", (unsigned long)rx_us, + (unsigned long)sleep_us); } #endif @@ -1028,11 +1001,12 @@ void MyMesh::begin(bool has_display) { radio_driver.setTxPower(_prefs.tx_power_dbm); radio_driver.setRxBoostedGainMode(_prefs.rx_boosted_gain); board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain); -#ifdef RXPS_FIXED_ENABLED - applyFixedRxPowerSaving(_prefs.sf, _prefs.bw); -#endif MESH_DEBUG_PRINTLN("RX Boosted Gain Mode: %s", radio_driver.getRxBoostedGainMode() ? "Enabled" : "Disabled"); + +#ifdef RXPS_FIXED_ENABLED + applyFixedRxPowerSaving(_prefs.sf, _prefs.bw); // RX PowerSaving +#endif } const char *MyMesh::getNodeName() { @@ -1457,7 +1431,7 @@ void MyMesh::handleCmdFrame(size_t len) { radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr); #ifdef RXPS_FIXED_ENABLED - applyFixedRxPowerSaving(_prefs.sf, _prefs.bw); + applyFixedRxPowerSaving(_prefs.sf, _prefs.bw); // RX PowerSaving #endif MESH_DEBUG_PRINTLN("OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr); diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 8502834c7..7f950493e 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1,5 +1,6 @@ #include "MyMesh.h" #include +#include "helpers/radiolib/RXPowerSaving.h" /* ------------------------------ Config -------------------------------- */ @@ -896,8 +897,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc _prefs.flood_max_advert = 8; _prefs.interference_threshold = 0; // disabled _prefs.cad_enabled = 0; // hardware CAD before TX (off by default; 'set cad on') - _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; - _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; + _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; // RX PowerSaving + _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; // RX PowerSaving // bridge defaults _prefs.bridge_enabled = 1; // enabled diff --git a/platformio.ini b/platformio.ini index 734d80591..e16f7b830 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,14 +13,6 @@ extra_configs = variants/*/platformio.ini platformio.local.ini -[companion_rxps] -custom_rxps_level = 5 -custom_rxps_preamble = 16 -build_flags = - -D RXPS_FIXED_ENABLED=1 - -D RXPS_FIXED_LEVEL=${companion_rxps.custom_rxps_level} - -D RXPS_FIXED_PREAMBLE=${companion_rxps.custom_rxps_preamble} - [arduino_base] framework = arduino monitor_speed = 115200 diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 0c9fb0e27..2b209a78f 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -11,6 +11,8 @@ #define BRIDGE_MAX_BAUD 115200 #endif +#include + // Believe it or not, this std C function is busted on some platforms! static uint32_t _atoi(const char* sp) { uint32_t n = 0; @@ -29,80 +31,6 @@ static bool isValidName(const char *n) { return true; } -static bool isValidRxPowerSavingPeriod(uint32_t us) { - return us >= RX_POWERSAVING_MIN_PERIOD_US && us <= RX_POWERSAVING_MAX_PERIOD_US; -} - -// MeshCore preamble convention used for the RX powersaving timing calculation. -// Must stay in sync with RadioLibWrapper::preambleLengthForSF() (the value the -// radio actually transmits); kept local here because CommonCLI is radio-agnostic. -static uint16_t rxPowerSavingPreambleForSF(uint8_t sf) { - return sf <= 8 ? 32 : 16; -} - -static bool isNumeric(const char* sp) { - if (!sp || !*sp) return false; - while (*sp) { - if (*sp < '0' || *sp > '9') return false; - sp++; - } - return true; -} - -static uint32_t ceilPositiveFloat(float value) { - uint32_t rounded = (uint32_t)value; - return value > (float)rounded ? rounded + 1 : rounded; -} - -static bool calcRxPowerSavingLevel(uint32_t level, uint8_t sf, float bw, uint32_t preamble, - uint32_t* rx_us, uint32_t* sleep_us) { - if (level < 1 || level > 10 || sf < 5 || sf > 12 || bw <= 0.0f || (preamble != 16 && preamble != 32)) { - return false; - } - - const float symbol_us = (1000.0f * (float)(1UL << sf)) / bw; - const float amount = (float)(level - 1) / 9.0f; - const float rx_start_symbols = preamble == 16 ? 12.0f : 16.0f; - const float sleep_start_symbols = preamble == 16 ? 2.0f : 15.0f; - const float rx_edge_symbols = 8.0f; - const float sleep_edge_symbols = (float)preamble + 4.25f - 8.0f; - - const float rx_symbols = rx_start_symbols + amount * (rx_edge_symbols - rx_start_symbols); - const float sleep_symbols = sleep_start_symbols + amount * (sleep_edge_symbols - sleep_start_symbols); - - *rx_us = ceilPositiveFloat(rx_symbols * symbol_us); - *sleep_us = (uint32_t)(sleep_symbols * symbol_us); - return true; -} - -static void ensureRxPowerSavingDefaults(NodePrefs* prefs) { - if (!isValidRxPowerSavingPeriod(prefs->rx_ps_rx_us)) { - prefs->rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; - } - if (!isValidRxPowerSavingPeriod(prefs->rx_ps_sleep_us)) { - prefs->rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; - } -} - -// Recomputes rx_ps_rx_us/rx_ps_sleep_us from the stored level and the current -// radio SF/BW. No-op (returns false) for manual timings (rx_ps_level == 0). -// Lets level-based RX powersaving auto-retune when SF/BW change. -static bool recalcRxPowerSavingFromLevel(NodePrefs* prefs) { - if (prefs->rx_ps_level < 1 || prefs->rx_ps_level > 10) return false; // manual: nothing to recompute - uint32_t preamble = prefs->rx_ps_preamble ? prefs->rx_ps_preamble - : rxPowerSavingPreambleForSF(prefs->sf); - uint32_t rx_us, sleep_us; - if (!calcRxPowerSavingLevel(prefs->rx_ps_level, prefs->sf, prefs->bw, preamble, &rx_us, &sleep_us)) { - return false; - } - if (!isValidRxPowerSavingPeriod(rx_us) || !isValidRxPowerSavingPeriod(sleep_us)) { - return false; - } - prefs->rx_ps_rx_us = rx_us; - prefs->rx_ps_sleep_us = sleep_us; - return true; -} - void CommonCLI::loadPrefs(FILESYSTEM* fs) { if (fs->exists("/com_prefs")) { loadPrefsInt(fs, "/com_prefs"); // new filename @@ -208,13 +136,16 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) { _prefs->rx_boosted_gain = constrain(_prefs->rx_boosted_gain, 0, 1); // boolean _prefs->radio_fem_rxgain = constrain(_prefs->radio_fem_rxgain, 0, 1); // boolean _prefs->cad_enabled = constrain(_prefs->cad_enabled, 0, 1); // boolean + _prefs->rx_powersaving_enabled = constrain(_prefs->rx_powersaving_enabled, 0, 1); _prefs->rx_ps_level = constrain(_prefs->rx_ps_level, 0, 10); if (_prefs->rx_ps_preamble != 16 && _prefs->rx_ps_preamble != 32) { _prefs->rx_ps_preamble = 0; // 0 = auto (derive from SF) } - ensureRxPowerSavingDefaults(_prefs); - recalcRxPowerSavingFromLevel(_prefs); // retune level-based timings to the loaded SF/BW + ensureRxPowerSavingDefaults(&_prefs->rx_ps_rx_us, &_prefs->rx_ps_sleep_us); + recalcRxPowerSavingFromLevel(_prefs->rx_ps_level, _prefs->sf, _prefs->bw, _prefs->rx_ps_preamble, + &_prefs->rx_ps_rx_us, + &_prefs->rx_ps_sleep_us); // retune level-based timings to the loaded SF/BW file.close(); } @@ -761,17 +692,17 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep } else { strcpy(reply, "Error: state must be on or off"); } - } else if (memcmp(config, "radio.rxps ", 11) == 0) { + } else if (memcmp(config, "radio.rxps ", 11) == 0) { // RX PowerSaving const char* value = &config[11]; uint8_t enable = _prefs->rx_powersaving_enabled; uint32_t rx_us = _prefs->rx_ps_rx_us; uint32_t sleep_us = _prefs->rx_ps_sleep_us; - uint32_t level = 0; - uint32_t preamble = rxPowerSavingPreambleForSF(_prefs->sf); + uint8_t level = 0; + uint8_t preamble = rxPowerSavingPreambleForSF(_prefs->sf); bool level_requested = false; bool preamble_overridden = false; - ensureRxPowerSavingDefaults(_prefs); + ensureRxPowerSavingDefaults(&_prefs->rx_ps_rx_us, &_prefs->rx_ps_sleep_us); rx_us = _prefs->rx_ps_rx_us; sleep_us = _prefs->rx_ps_sleep_us; @@ -875,7 +806,9 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep _prefs->bw = bw; // Retune level-based RX powersaving to the new SF/BW. Persist only; the // radio itself is "reboot to apply", and begin() re-arms the timings then. - bool rxps_retuned = recalcRxPowerSavingFromLevel(_prefs); + bool rxps_retuned = recalcRxPowerSavingFromLevel( + _prefs->rx_ps_level, _prefs->sf, _prefs->bw, _prefs->rx_ps_preamble, &_prefs->rx_ps_rx_us, + &_prefs->rx_ps_sleep_us); // retune level-based timings to the loaded SF/BW _callbacks->savePrefs(); strcpy(reply, rxps_retuned ? "OK - reboot to apply (rxps retuned)" : "OK - reboot to apply"); } else { @@ -915,7 +848,7 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep strcpy(reply, "OK"); } else { strcpy(reply, "Error, max 64"); - } + } } else if (memcmp(config, "flood.max.advert ", 17) == 0) { uint8_t m = atoi(&config[17]); if (m <= 64) { @@ -1121,8 +1054,8 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep } else { sprintf(reply, "> %s", _board->isLoRaFemLnaEnabled() ? "on" : "off"); } - } else if (memcmp(config, "radio.rxps", 10) == 0) { - ensureRxPowerSavingDefaults(_prefs); + } else if (memcmp(config, "radio.rxps", 10) == 0) { // RX PowerSaving + ensureRxPowerSavingDefaults(&_prefs->rx_ps_rx_us, &_prefs->rx_ps_sleep_us); sprintf(reply, "> %s,%lu,%lu", _prefs->rx_powersaving_enabled ? "on" : "off", (unsigned long)_prefs->rx_ps_rx_us, (unsigned long)_prefs->rx_ps_sleep_us); } else if (memcmp(config, "rxps.wd", 7) == 0) { diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 6ec5aa013..a46402425 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -19,18 +19,6 @@ #define LOOP_DETECT_MODERATE 2 #define LOOP_DETECT_STRICT 3 -#define RX_POWERSAVING_DEFAULT_RX_US 65625UL -#define RX_POWERSAVING_DEFAULT_SLEEP_US 60000UL -#define RX_POWERSAVING_MIN_PERIOD_US 1000UL -#define RX_POWERSAVING_MAX_PERIOD_US 30000000UL - -// The named profiles are level presets pinned to a 16-symbol preamble: most -// deployed senders still transmit 16-symbol preambles regardless of the newer -// SF-based rule (32 for SF <= 8). Revisit once the field has largely migrated. -#define RX_POWERSAVING_CONSERVATIVE_LEVEL 1UL -#define RX_POWERSAVING_BALANCED_LEVEL 5UL -#define RX_POWERSAVING_PROFILE_PREAMBLE 16UL - struct NodePrefs { // persisted to file float airtime_factor; char node_name[32]; @@ -133,6 +121,7 @@ public: // no op by default }; + // RX PowerSaving virtual bool setRxPowerSaving(bool enable, uint32_t rx_us, uint32_t sleep_us) { return !enable; }; diff --git a/src/helpers/radiolib/RXPowerSaving.h b/src/helpers/radiolib/RXPowerSaving.h new file mode 100644 index 000000000..8cfa6bcf5 --- /dev/null +++ b/src/helpers/radiolib/RXPowerSaving.h @@ -0,0 +1,103 @@ +#pragma once +#include + +#define RX_POWERSAVING_DEFAULT_RX_US 65625UL +#define RX_POWERSAVING_DEFAULT_SLEEP_US 60000UL +#define RX_POWERSAVING_MIN_PERIOD_US 1000UL +#define RX_POWERSAVING_MAX_PERIOD_US 30000000UL + +// The named profiles are level presets pinned to a 16-symbol preamble: most +// deployed senders still transmit 16-symbol preambles regardless of the newer +// SF-based rule (32 for SF <= 8). Revisit once the field has largely migrated. +#define RX_POWERSAVING_CONSERVATIVE_LEVEL 1 +#define RX_POWERSAVING_BALANCED_LEVEL 5 +#define RX_POWERSAVING_PROFILE_PREAMBLE 16 + +// Fixed settings for companions +#define RXPS_FIXED_ENABLED 1 +#define RXPS_FIXED_LEVEL RX_POWERSAVING_BALANCED_LEVEL +#define RXPS_FIXED_PREAMBLE RX_POWERSAVING_PROFILE_PREAMBLE + +inline bool isValidRxPowerSavingPeriod(uint32_t us) { + return us >= RX_POWERSAVING_MIN_PERIOD_US && us <= RX_POWERSAVING_MAX_PERIOD_US; +} + +// MeshCore preamble convention used for the RX powersaving timing calculation. +// Must stay in sync with RadioLibWrapper::preambleLengthForSF() (the value the +// radio actually transmits); kept local here because CommonCLI is radio-agnostic. +inline uint8_t rxPowerSavingPreambleForSF(uint8_t sf) { + return sf <= 8 ? 32 : 16; +} + +inline bool isNumeric(const char *sp) { + if (!sp || !*sp) return false; + while (*sp) { + if (*sp < '0' || *sp > '9') return false; + sp++; + } + return true; +} + +inline uint32_t ceilPositiveFloat(float value) { + uint32_t rounded = (uint32_t)value; + return value > (float)rounded ? rounded + 1 : rounded; +} + +inline bool calcRxPowerSavingLevel(uint8_t level, uint8_t sf, float bw, uint8_t preamble, uint32_t *rx_us, + uint32_t *sleep_us) { + if (level < 1 || level > 10 || sf < 5 || sf > 12 || bw <= 0.0f || (preamble != 16 && preamble != 32)) { + return false; + } + + const float symbol_us = (1000.0f * (float)(1UL << sf)) / bw; + const float amount = (float)(level - 1) / 9.0f; + const float rx_start_symbols = preamble == 16 ? 12.0f : 16.0f; + const float sleep_start_symbols = preamble == 16 ? 2.0f : 15.0f; + const float rx_edge_symbols = 8.0f; + const float sleep_edge_symbols = (float)preamble + 4.25f - 8.0f; + + const float rx_symbols = rx_start_symbols + amount * (rx_edge_symbols - rx_start_symbols); + const float sleep_symbols = sleep_start_symbols + amount * (sleep_edge_symbols - sleep_start_symbols); + + *rx_us = ceilPositiveFloat(rx_symbols * symbol_us); + *sleep_us = (uint32_t)(sleep_symbols * symbol_us); + return true; +} + +inline void ensureRxPowerSavingDefaults(uint32_t *rx_ps_rx_us, uint32_t *rx_ps_sleep_us) { + if (!isValidRxPowerSavingPeriod(*rx_ps_rx_us)) { + *rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; + } + + if (!isValidRxPowerSavingPeriod(*rx_ps_sleep_us)) { + *rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; + } +} + +// Recomputes rx_ps_rx_us/rx_ps_sleep_us from the stored level and the current +// radio SF/BW. No-op (returns false) for manual timings (rx_ps_level == 0). +// Lets level-based RX powersaving auto-retune when SF/BW change. +inline bool recalcRxPowerSavingFromLevel(uint8_t level, uint8_t sf, float bw, uint8_t preamble, + uint32_t *rx_ps_rx_us, uint32_t *rx_ps_sleep_us) { + if (level < 1 || level > 10) { + return false; // manual: nothing to recompute + } + + if (preamble == 0) { + preamble = rxPowerSavingPreambleForSF(sf); + } + + uint32_t rx_us, sleep_us; + if (!calcRxPowerSavingLevel(level, sf, bw, preamble, &rx_us, &sleep_us)) { + return false; + } + + if (!isValidRxPowerSavingPeriod(rx_us) || !isValidRxPowerSavingPeriod(sleep_us)) { + return false; + } + + *rx_ps_rx_us = rx_us; + *rx_ps_sleep_us = sleep_us; + + return true; +} \ No newline at end of file diff --git a/src/helpers/radiolib/RadioLibWrappers.cpp b/src/helpers/radiolib/RadioLibWrappers.cpp index b44b428e7..4f32176e5 100644 --- a/src/helpers/radiolib/RadioLibWrappers.cpp +++ b/src/helpers/radiolib/RadioLibWrappers.cpp @@ -292,6 +292,7 @@ bool RadioLibWrapper::isInRecvMode() const { return (state & ~STATE_INT_READY) == STATE_RX; } +// RX PowerSaving bool RadioLibWrapper::setRxPowerSaving(bool enabled, uint32_t rx_us, uint32_t sleep_us) { if (enabled && !supportsRxPowerSaving()) { return false; diff --git a/variants/heltec_t096/platformio.ini b/variants/heltec_t096/platformio.ini index 1324ad82e..1961b3747 100644 --- a/variants/heltec_t096/platformio.ini +++ b/variants/heltec_t096/platformio.ini @@ -127,7 +127,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${Heltec_t096.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -158,7 +157,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${Heltec_t096.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/heltec_t114/platformio.ini b/variants/heltec_t114/platformio.ini index 643bc5d12..9817bc72c 100644 --- a/variants/heltec_t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -99,7 +99,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${Heltec_t114.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D DISPLAY_CLASS=NullDisplayDriver -D MAX_CONTACTS=350 @@ -123,7 +122,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${Heltec_t114.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D DISPLAY_CLASS=NullDisplayDriver -D MAX_CONTACTS=350 @@ -213,7 +211,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${Heltec_t114_with_display.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -238,7 +235,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${Heltec_t114_with_display.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/heltec_tracker_v2/platformio.ini b/variants/heltec_tracker_v2/platformio.ini index ff5c02c26..d914ce6a1 100644 --- a/variants/heltec_tracker_v2/platformio.ini +++ b/variants/heltec_tracker_v2/platformio.ini @@ -136,7 +136,6 @@ lib_deps = extends = Heltec_tracker_v2 build_flags = ${Heltec_tracker_v2.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -156,7 +155,6 @@ lib_deps = extends = Heltec_tracker_v2 build_flags = ${Heltec_tracker_v2.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -186,7 +184,6 @@ platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 extends = Heltec_tracker_v2 build_flags = ${Heltec_tracker_v2.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/heltec_v4/platformio.ini b/variants/heltec_v4/platformio.ini index ec90e7238..113ba24a0 100644 --- a/variants/heltec_v4/platformio.ini +++ b/variants/heltec_v4/platformio.ini @@ -184,7 +184,6 @@ lib_deps = extends = heltec_v4_oled build_flags = ${heltec_v4_oled.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -204,7 +203,6 @@ lib_deps = extends = heltec_v4_oled build_flags = ${heltec_v4_oled.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -239,7 +237,6 @@ build_flags = extends = heltec_v4_oled build_flags = ${heltec_v4_oled.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 80ab08a02..bcaacc47e 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -123,7 +123,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${rak4631.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D PIN_USER_BTN=9 -D PIN_USER_BTN_ANA=31 @@ -145,7 +144,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 712704 build_flags = ${rak4631.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D PIN_USER_BTN=9 -D PIN_USER_BTN_ANA=31 diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index 7e662fbc0..43a3d93f6 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -73,7 +73,6 @@ extends = t1000-e board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = ${t1000-e.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-orig -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -97,7 +96,6 @@ extends = t1000-e board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = ${t1000-e.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-orig -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/thinknode_m3/platformio.ini b/variants/thinknode_m3/platformio.ini index 9571182d8..f23ac87d6 100644 --- a/variants/thinknode_m3/platformio.ini +++ b/variants/thinknode_m3/platformio.ini @@ -75,7 +75,6 @@ extends = ThinkNode_M3 board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 708608 build_flags = ${ThinkNode_M3.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-orig -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -99,7 +98,6 @@ extends = ThinkNode_M3 board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld board_upload.maximum_size = 708608 build_flags = ${ThinkNode_M3.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-orig -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/xiao_nrf52/platformio.ini b/variants/xiao_nrf52/platformio.ini index 44fcc56f3..f4d1b93e6 100644 --- a/variants/xiao_nrf52/platformio.ini +++ b/variants/xiao_nrf52/platformio.ini @@ -46,7 +46,6 @@ board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = ${Xiao_nrf52.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-orig -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -70,7 +69,6 @@ board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld board_upload.maximum_size = 708608 build_flags = ${Xiao_nrf52.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-orig -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/xiao_s3/platformio.ini b/variants/xiao_s3/platformio.ini index 47315b5ff..b59e69ae4 100644 --- a/variants/xiao_s3/platformio.ini +++ b/variants/xiao_s3/platformio.ini @@ -94,7 +94,6 @@ lib_deps = extends = Xiao_S3 build_flags = ${Xiao_S3.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -123,7 +122,6 @@ platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 extends = Xiao_S3 build_flags = ${Xiao_S3.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 diff --git a/variants/xiao_s3_wio/platformio.ini b/variants/xiao_s3_wio/platformio.ini index ca28a2859..6686de55d 100644 --- a/variants/xiao_s3_wio/platformio.ini +++ b/variants/xiao_s3_wio/platformio.ini @@ -132,7 +132,6 @@ lib_deps = extends = Xiao_S3_WIO build_flags = ${Xiao_S3_WIO.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -155,7 +154,6 @@ lib_deps = extends = Xiao_S3_WIO build_flags = ${Xiao_S3_WIO.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -184,7 +182,6 @@ platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 extends = Xiao_S3_WIO build_flags = ${Xiao_S3_WIO.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -213,7 +210,6 @@ build_src_filter = ${Xiao_S3_WIO.build_src_filter} +<../examples/companion_radio/*.cpp> build_flags = ${Xiao_S3_WIO.build_flags} - ${companion_rxps.build_flags} -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 From d3539e88105b99a6544bf77428eee4726b3fb2de Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Wed, 5 Aug 2026 23:32:09 +0700 Subject: [PATCH 13/21] Fixed name for Heltec_t096_companion_radio_ble_femon --- build-iotthinks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-iotthinks.sh b/build-iotthinks.sh index f80a55be3..85d681bda 100644 --- a/build-iotthinks.sh +++ b/build-iotthinks.sh @@ -77,7 +77,7 @@ Xiao_nrf52_room_server ############# Companions BLE ############# # NRF52 - 15 boards sh build.sh build-firmware \ -Heltec_t096_companion_radio_ble \ +Heltec_t096_companion_radio_ble_femon \ Heltec_t096_companion_radio_ble_femoff \ Heltec_t1_companion_radio_ble \ Heltec_t114_companion_radio_ble \ @@ -123,7 +123,7 @@ Heltec_t096_companion_radio_usb ############# Sample builds ############# # 14 boards sh build.sh build-firmware \ -Heltec_t096_companion_radio_ble \ +Heltec_t096_companion_radio_ble_femon \ Heltec_t096_companion_radio_ble_femoff \ Heltec_t096_repeater \ Heltec_v3_companion_radio_ble_ps \ From 1bf80992b9c42a27cf0b3d71282a00a68ff77a60 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sat, 8 Aug 2026 11:28:28 +0700 Subject: [PATCH 14/21] For RAK only, fixed reset pin and honour FORCE_GPS_ALIVE --- .../sensors/EnvironmentSensorManager.cpp | 24 +++++++------------ variants/rak3401/platformio.ini | 4 ++++ variants/rak3401/variant.h | 4 ++-- variants/rak4631/platformio.ini | 2 -- variants/rak4631/variant.h | 3 +++ 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 0156a03a8..e67a392e8 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -169,7 +169,9 @@ static RAK12035_SoilMoisture RAK12035; #endif #ifdef RAK_WISBLOCK_GPS -static uint32_t gpsResetPin = 0; +// -1 = no enable pin; out-of-range values are no-ops in pinMode/digitalWrite, +// while 0 would be a real GPIO (P0.00 = LFXO crystal on nRF52) +static uint32_t gpsResetPin = -1; static bool i2cGPSFlag = false; static bool serialGPSFlag = false; #ifndef TELEM_RAK12500_ADDRESS @@ -812,11 +814,7 @@ void EnvironmentSensorManager::rakGPSInit() { // search for the correct IO standby pin depending on socket used if (gpsIsAwake(WB_IO2)) { - _location->setPinEn(WB_IO2); - } else if (gpsIsAwake(WB_IO4)) { - _location->setPinEn(WB_IO4); - } else if (gpsIsAwake(WB_IO5)) { - _location->setPinEn(WB_IO5); + _location->setPinEn(WB_IO2); // WB_IO2 is the power switch for all sensor and IO slots } else { MESH_DEBUG_PRINTLN("No GPS found"); gps_active = false; @@ -861,11 +859,7 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin) { return true; } else if (Serial1.available()) { // RAK12501 (L76K) on UART MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on"); -#ifdef PIN_GPS_EN - if (PIN_GPS_EN) { - gpsResetPin = PIN_GPS_EN; - } -#endif + gpsResetPin = ioPin; serialGPSFlag = true; gps_active = true; gps_detected = true; @@ -889,8 +883,7 @@ void EnvironmentSensorManager::start_gps() { #ifdef RAK_WISBLOCK_GPS pinMode(gpsResetPin, OUTPUT); - digitalWrite(gpsResetPin, HIGH); - gpsIsAwake(_location->getPinEn()); // Turn on UART L76K for RAK12500 or I2C for RAK12501 + digitalWrite(gpsResetPin, HIGH); // WB_IO2 return; #endif @@ -913,9 +906,10 @@ void EnvironmentSensorManager::stop_gps() { } #ifdef RAK_WISBLOCK_GPS + #ifndef FORCE_GPS_ALIVE pinMode(gpsResetPin, OUTPUT); - digitalWrite(gpsResetPin, LOW); - digitalWrite(_location->getPinEn(), LOW); // Cut off power + digitalWrite(gpsResetPin, LOW); // WB_IO2 + #endif return; #endif diff --git a/variants/rak3401/platformio.ini b/variants/rak3401/platformio.ini index 5eeb6a9d6..c79e24c12 100644 --- a/variants/rak3401/platformio.ini +++ b/variants/rak3401/platformio.ini @@ -7,6 +7,7 @@ build_flags = ${nrf52_base.build_flags} ${sensor_base.build_flags} -I variants/rak3401 -D RAK_3401 + -D RAK_BOARD ; -D NRF52_POWER_MANAGEMENT -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper @@ -14,6 +15,9 @@ build_flags = ${nrf52_base.build_flags} -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 -D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX with SKY66122 FEM + -D FORCE_GPS_ALIVE ; on RAK3401, gpsResetPin ends up = WB_IO2 (kills 3V3_S rail) or + ; pin 4 (= SX126X_RESET, holds radio in reset). stop_gps() must not run. + -D PIN_GPS_EN=-1 ; -1 = no dedicated GPS enable pin (power is the shared 3V3_S rail), same as rak4631 build_src_filter = ${nrf52_base.build_src_filter} +<../variants/rak3401> + diff --git a/variants/rak3401/variant.h b/variants/rak3401/variant.h index 988278860..a2e32ae29 100644 --- a/variants/rak3401/variant.h +++ b/variants/rak3401/variant.h @@ -188,8 +188,8 @@ static const uint8_t AREF = PIN_AREF; // Power is on the controllable 3V3_S rail #define PIN_GPS_PPS (17) // Pulse per second input from the GPS -#define PIN_GPS_RX PIN_SERIAL1_RX -#define PIN_GPS_TX PIN_SERIAL1_TX +#define PIN_GPS_RX PIN_SERIAL1_TX +#define PIN_GPS_TX PIN_SERIAL1_RX #define PIN_GPS_1PPS PIN_GPS_PPS #define GPS_BAUD_RATE 9600 diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index bcaacc47e..662a9a6ae 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -13,8 +13,6 @@ build_flags = ${nrf52_base.build_flags} ; -D NRF52_POWER_MANAGEMENT -D PIN_BOARD_SCL=14 -D PIN_BOARD_SDA=13 - -D PIN_GPS_TX=PIN_SERIAL1_RX - -D PIN_GPS_RX=PIN_SERIAL1_TX -D PIN_GPS_EN=-1 -D PIN_OLED_RESET=-1 -D USE_SX1262 diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 38cc88685..42ca3b0c5 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -182,6 +182,9 @@ extern "C" #define EXTERNAL_FLASH_DEVICES IS25LP080D #define EXTERNAL_FLASH_USE_QSPI +#define PIN_GPS_RX PIN_SERIAL1_TX +#define PIN_GPS_TX PIN_SERIAL1_RX + #define PIN_GPS_1PPS 17 //GPS PPS pin #define GPS_BAUD_RATE 9600 #define GPS_ADDRESS 0x42 //i2c address for GPS From 20410896608f1666d66f23c8a40790f69cdf06c8 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sat, 8 Aug 2026 16:05:56 +0700 Subject: [PATCH 15/21] Added heltec_v4_companion_radio_usb_ps_femon and heltec_v4_companion_radio_usb_ps_femoff --- variants/heltec_v4/platformio.ini | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/variants/heltec_v4/platformio.ini b/variants/heltec_v4/platformio.ini index 113ba24a0..12d772f20 100644 --- a/variants/heltec_v4/platformio.ini +++ b/variants/heltec_v4/platformio.ini @@ -199,6 +199,16 @@ lib_deps = ${heltec_v4_oled.lib_deps} densaugeo/base64 @ ~1.4.0 +[env:heltec_v4_companion_radio_usb_ps_femon] +extends = env:heltec_v4_companion_radio_usb +platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 + +[env:heltec_v4_companion_radio_usb_ps_femoff] +extends = env:heltec_v4_companion_radio_usb_ps_femon +build_flags = + ${env:heltec_v4_companion_radio_usb_ps_femon.build_flags} + -D RADIO_FEM_RXGAIN=0 ; undefined (default on), 1=on, 0=off + [env:heltec_v4_companion_radio_ble] extends = heltec_v4_oled build_flags = From e13fb6a42607df75042bd8e901fc4904cd2c3fe5 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 12:38:31 +0700 Subject: [PATCH 16/21] Added ; -D FORCE_GPS_ALIVE --- variants/rak4631/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 662a9a6ae..7279a6c51 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -13,6 +13,7 @@ build_flags = ${nrf52_base.build_flags} ; -D NRF52_POWER_MANAGEMENT -D PIN_BOARD_SCL=14 -D PIN_BOARD_SDA=13 +; -D FORCE_GPS_ALIVE // Do not off WB_IO2 if we want to keep other sensor / IO slots on -D PIN_GPS_EN=-1 -D PIN_OLED_RESET=-1 -D USE_SX1262 From 6334f602f1ab9df82e7e7fb3e3ffb74cc0576ea3 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 12:41:29 +0700 Subject: [PATCH 17/21] Added polling period and powersave of I2C GPS for RAK12500 --- .../sensors/EnvironmentSensorManager.cpp | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index e67a392e8..ffda2414e 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -200,16 +200,21 @@ public: void begin() override { } void stop() override { } void loop() override { - if (ublox_GNSS.getGnssFixOk(8)) { - _fix = true; - _lat = ublox_GNSS.getLatitude(2) / 10; - _lng = ublox_GNSS.getLongitude(2) / 10; - _alt = ublox_GNSS.getAltitude(2); - _sats = ublox_GNSS.getSIV(2); - } else { - _fix = false; + static long next_gps_update = 0; + if ((int32_t)(millis() - next_gps_update) >= 0) { + if (ublox_GNSS.getGnssFixOk(8)) { + _fix = true; + _lat = ublox_GNSS.getLatitude(2) / 10; + _lng = ublox_GNSS.getLongitude(2) / 10; + _alt = ublox_GNSS.getAltitude(2); + _sats = ublox_GNSS.getSIV(2); + } else { + _fix = false; + } + _epoch = ublox_GNSS.getUnixEpoch(2); + + next_gps_update = millis() + 1000; } - _epoch = ublox_GNSS.getUnixEpoch(2); } bool isEnabled() override { return true; } void setPinEn(int pin_en) override { _pin_en = pin_en; } @@ -882,9 +887,14 @@ void EnvironmentSensorManager::start_gps() { } #ifdef RAK_WISBLOCK_GPS - pinMode(gpsResetPin, OUTPUT); - digitalWrite(gpsResetPin, HIGH); // WB_IO2 - return; +#ifdef FORCE_GPS_ALIVE + // There is no UART command to enter power save for L76K + if (i2cGPSFlag) ublox_GNSS.powerSaveMode(false); +#else + pinMode(gpsResetPin, OUTPUT); + digitalWrite(gpsResetPin, HIGH); // WB_IO2 +#endif + return; #endif _location->begin(); @@ -906,7 +916,10 @@ void EnvironmentSensorManager::stop_gps() { } #ifdef RAK_WISBLOCK_GPS - #ifndef FORCE_GPS_ALIVE + #ifdef FORCE_GPS_ALIVE + // There is no UART command to enter power save for L76K + if(i2cGPSFlag) ublox_GNSS.powerSaveMode(false); + #else pinMode(gpsResetPin, OUTPUT); digitalWrite(gpsResetPin, LOW); // WB_IO2 #endif From 5859319cbf4b1db5a484689f37bc13f7d7f74743 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 23:30:56 +0700 Subject: [PATCH 18/21] Added Heltec V4 R8 --- boards/heltec_v4_r8.json | 43 +++ variants/heltec_v4_r8/HeltecV4R8Board.cpp | 86 ++++++ variants/heltec_v4_r8/HeltecV4R8Board.h | 39 +++ variants/heltec_v4_r8/LoRaFEMControl.cpp | 52 ++++ variants/heltec_v4_r8/LoRaFEMControl.h | 24 ++ variants/heltec_v4_r8/pins_arduino.h | 56 ++++ variants/heltec_v4_r8/platformio.ini | 348 ++++++++++++++++++++++ variants/heltec_v4_r8/target.cpp | 45 +++ variants/heltec_v4_r8/target.h | 31 ++ 9 files changed, 724 insertions(+) create mode 100644 boards/heltec_v4_r8.json create mode 100644 variants/heltec_v4_r8/HeltecV4R8Board.cpp create mode 100644 variants/heltec_v4_r8/HeltecV4R8Board.h create mode 100644 variants/heltec_v4_r8/LoRaFEMControl.cpp create mode 100644 variants/heltec_v4_r8/LoRaFEMControl.h create mode 100644 variants/heltec_v4_r8/pins_arduino.h create mode 100644 variants/heltec_v4_r8/platformio.ini create mode 100644 variants/heltec_v4_r8/target.cpp create mode 100644 variants/heltec_v4_r8/target.h diff --git a/boards/heltec_v4_r8.json b/boards/heltec_v4_r8.json new file mode 100644 index 000000000..6dd97c84b --- /dev/null +++ b/boards/heltec_v4_r8.json @@ -0,0 +1,43 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "opi", + "hwids": [["0x303A", "0x1001"]], + "mcu": "esp32s3", + "variant": "heltec_v4_r8" + }, + "connectivity": ["wifi", "bluetooth", "lora"], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": ["esp-builtin"], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": ["arduino", "espidf"], + "name": "heltec_wifi_lora_32 v4 r8 (16 MB FLASH, 8 MB PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://heltec.org/", + "vendor": "heltec" +} diff --git a/variants/heltec_v4_r8/HeltecV4R8Board.cpp b/variants/heltec_v4_r8/HeltecV4R8Board.cpp new file mode 100644 index 000000000..1fb123b2f --- /dev/null +++ b/variants/heltec_v4_r8/HeltecV4R8Board.cpp @@ -0,0 +1,86 @@ +#include "HeltecV4R8Board.h" + +void HeltecV4R8Board::begin() { + ESP32Board::begin(); + + periph_power.begin(); + periph_power.claim(); // R8 VEXT also feeds the LoRa antenna boost rail. + + loRaFEMControl.init(); + +#ifdef PIN_TOUCH_RST + pinMode(PIN_TOUCH_RST, OUTPUT); + digitalWrite(PIN_TOUCH_RST, HIGH); + delay(10); + digitalWrite(PIN_TOUCH_RST, LOW); + delay(100); + digitalWrite(PIN_TOUCH_RST, HIGH); +#endif + + esp_reset_reason_t reason = esp_reset_reason(); + if (reason == ESP_RST_DEEPSLEEP) { + long wakeup_source = esp_sleep_get_ext1_wakeup_status(); + if (wakeup_source & (1 << P_LORA_DIO_1)) { + startup_reason = BD_STARTUP_RX_PACKET; + } + + rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS); + rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1); + } +} + +void HeltecV4R8Board::onBeforeTransmit(void) { + digitalWrite(P_LORA_TX_LED, HIGH); + loRaFEMControl.setTxModeEnable(); +} + +void HeltecV4R8Board::onAfterTransmit(void) { + digitalWrite(P_LORA_TX_LED, LOW); + loRaFEMControl.setRxModeEnable(); +} + +void HeltecV4R8Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { + esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); + + rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); + rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); + + rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS); + loRaFEMControl.setRxModeEnableWhenMCUSleep(); + + if (pin_wake_btn < 0) { + esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); + } else { + esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); + } + + if (secs > 0) { + esp_sleep_enable_timer_wakeup(secs * 1000000); + } + + esp_deep_sleep_start(); +} + +void HeltecV4R8Board::powerOff() { + enterDeepSleep(0); +} + +uint16_t HeltecV4R8Board::getBattMilliVolts() { + analogReadResolution(12); + + uint32_t raw = 0; + for (int i = 0; i < 8; i++) { + raw += analogReadMilliVolts(PIN_VBAT_READ); + } + raw = raw / 8; + + return (adc_mult * raw); +} + +const char* HeltecV4R8Board::getManufacturerName() const { +#ifdef HELTEC_V4_R8_TFT + return "Heltec V4 R8 TFT"; +#else + return "Heltec V4 R8 OLED"; +#endif +} diff --git a/variants/heltec_v4_r8/HeltecV4R8Board.h b/variants/heltec_v4_r8/HeltecV4R8Board.h new file mode 100644 index 000000000..20811abb1 --- /dev/null +++ b/variants/heltec_v4_r8/HeltecV4R8Board.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include +#include "LoRaFEMControl.h" + +#ifndef ADC_MULTIPLIER + #define ADC_MULTIPLIER (4.9f * 1.035f) +#endif + +class HeltecV4R8Board : public ESP32Board { +protected: + float adc_mult = ADC_MULTIPLIER; + +public: + RefCountedDigitalPin periph_power; + LoRaFEMControl loRaFEMControl; + + HeltecV4R8Board() : periph_power(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE) { } + + void begin(); + void onBeforeTransmit(void) override; + void onAfterTransmit(void) override; + void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1); + void powerOff() override; + uint16_t getBattMilliVolts() override; + bool setAdcMultiplier(float multiplier) override { + if (multiplier == 0.0f) { + adc_mult = ADC_MULTIPLIER; + } else { + adc_mult = multiplier; + } + return true; + } + float getAdcMultiplier() const override { return adc_mult; } + const char* getManufacturerName() const override; +}; diff --git a/variants/heltec_v4_r8/LoRaFEMControl.cpp b/variants/heltec_v4_r8/LoRaFEMControl.cpp new file mode 100644 index 000000000..bb530de3c --- /dev/null +++ b/variants/heltec_v4_r8/LoRaFEMControl.cpp @@ -0,0 +1,52 @@ +#include "LoRaFEMControl.h" + +#include +#include +#include + +void LoRaFEMControl::init(void) { + pinMode(P_LORA_PA_POWER, OUTPUT); + digitalWrite(P_LORA_PA_POWER, HIGH); + rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_POWER); + + esp_reset_reason_t reason = esp_reset_reason(); + if (reason != ESP_RST_DEEPSLEEP) { + delay(1); + } + + rtc_gpio_hold_dis((gpio_num_t)P_LORA_KCT8103L_PA_CSD); + rtc_gpio_hold_dis((gpio_num_t)P_LORA_KCT8103L_PA_CTX); + + pinMode(P_LORA_KCT8103L_PA_CSD, OUTPUT); + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + pinMode(P_LORA_KCT8103L_PA_CTX, OUTPUT); + digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH); +} + +void LoRaFEMControl::setSleepModeEnable(void) { + digitalWrite(P_LORA_KCT8103L_PA_CSD, LOW); +} + +void LoRaFEMControl::setTxModeEnable(void) { + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + digitalWrite(P_LORA_KCT8103L_PA_CTX, HIGH); +} + +void LoRaFEMControl::setRxModeEnable(void) { + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH); +} + +void LoRaFEMControl::setRxModeEnableWhenMCUSleep(void) { + digitalWrite(P_LORA_PA_POWER, HIGH); + rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_POWER); + + digitalWrite(P_LORA_KCT8103L_PA_CSD, HIGH); + rtc_gpio_hold_en((gpio_num_t)P_LORA_KCT8103L_PA_CSD); + digitalWrite(P_LORA_KCT8103L_PA_CTX, lna_enabled ? LOW : HIGH); + rtc_gpio_hold_en((gpio_num_t)P_LORA_KCT8103L_PA_CTX); +} + +void LoRaFEMControl::setLNAEnable(bool enabled) { + lna_enabled = enabled; +} diff --git a/variants/heltec_v4_r8/LoRaFEMControl.h b/variants/heltec_v4_r8/LoRaFEMControl.h new file mode 100644 index 000000000..961cfd070 --- /dev/null +++ b/variants/heltec_v4_r8/LoRaFEMControl.h @@ -0,0 +1,24 @@ +#pragma once + +typedef enum { + KCT8103L_PA, + OTHER_FEM_TYPES +} LoRaFEMType; + +class LoRaFEMControl { +public: + LoRaFEMControl() { } + virtual ~LoRaFEMControl() { } + void init(void); + void setSleepModeEnable(void); + void setTxModeEnable(void); + void setRxModeEnable(void); + void setRxModeEnableWhenMCUSleep(void); + void setLNAEnable(bool enabled); + bool isLnaCanControl(void) { return true; } + void setLnaCanControl(bool can_control) { } + LoRaFEMType getFEMType(void) const { return KCT8103L_PA; } + +private: + bool lna_enabled = false; +}; diff --git a/variants/heltec_v4_r8/pins_arduino.h b/variants/heltec_v4_r8/pins_arduino.h new file mode 100644 index 000000000..9e412aac5 --- /dev/null +++ b/variants/heltec_v4_r8/pins_arduino.h @@ -0,0 +1,56 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 17; +static const uint8_t SCL = 18; + +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +#endif diff --git a/variants/heltec_v4_r8/platformio.ini b/variants/heltec_v4_r8/platformio.ini new file mode 100644 index 000000000..70634f3d0 --- /dev/null +++ b/variants/heltec_v4_r8/platformio.ini @@ -0,0 +1,348 @@ +[Heltec_v4_r8] +extends = esp32_base +board = heltec_v4_r8 +build_flags = + ${esp32_base.build_flags} + ${sensor_base.build_flags} + -I variants/heltec_v4_r8 + -D HELTEC_V4_R8 + -D USE_SX1262 + -D ESP32_CPU_FREQ=80 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D P_LORA_DIO_1=14 + -D P_LORA_NSS=8 + -D P_LORA_RESET=12 + -D P_LORA_BUSY=13 + -D P_LORA_SCLK=9 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 + -D P_LORA_PA_POWER=7 + -D P_LORA_KCT8103L_PA_CSD=2 + -D P_LORA_KCT8103L_PA_CTX=5 + -D P_LORA_TX_LED=46 + -D PIN_USER_BTN=0 + -D PIN_VEXT_EN=40 + -D PIN_VEXT_EN_ACTIVE=LOW + -D ADC_MULTIPLIER=5.0715f + -D PIN_VBAT_READ=1 + -D LORA_TX_POWER=10 + -D MAX_LORA_TX_POWER=22 + -D SX126X_REGISTER_PATCH=1 + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 + -D SX126X_CURRENT_LIMIT=140 + -D SX126X_RX_BOOSTED_GAIN=1 + -D PIN_GPS_RX=38 + -D PIN_GPS_TX=39 + -D PIN_GPS_EN=42 + -D PIN_GPS_EN_ACTIVE=LOW + -D ENV_INCLUDE_GPS=1 +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/heltec_v4_r8> + + +lib_deps = + ${esp32_base.lib_deps} + ${sensor_base.lib_deps} + +[heltec_v4_r8_oled] +extends = Heltec_v4_r8 +build_flags = + ${Heltec_v4_r8.build_flags} + -D HELTEC_V4_R8_OLED + -D PIN_BOARD_SDA=17 + -D PIN_BOARD_SCL=18 + -D PIN_OLED_RESET=21 +build_src_filter = ${Heltec_v4_r8.build_src_filter} +lib_deps = ${Heltec_v4_r8.lib_deps} + +[heltec_v4_r8_tft] +extends = Heltec_v4_r8 +build_flags = + ${Heltec_v4_r8.build_flags} + -D HELTEC_V4_R8_TFT + -D PIN_BOARD_SDA=17 + -D PIN_BOARD_SCL=18 + -D DISPLAY_SCALE_X=2.5 + -D DISPLAY_SCALE_Y=3.75 + -D PIN_TFT_RST=-1 + -D PIN_TFT_VDD_CTL=-1 + -D PIN_TFT_LEDA_CTL=44 + -D PIN_TFT_LEDA_CTL_ACTIVE=HIGH + -D PIN_TFT_CS=47 + -D PIN_TFT_DC=48 + -D PIN_TFT_SCL=16 + -D PIN_TFT_SDA=15 + -D PIN_TFT_MISO=45 + -D PIN_BUZZER=4 + -D PIN_TOUCH_RST=21 +build_src_filter = ${Heltec_v4_r8.build_src_filter} + + +lib_deps = + ${Heltec_v4_r8.lib_deps} + adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0 + end2endzone/NonBlockingRTTTL@^1.3.0 + +[env:heltec_v4_r8_repeater] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"Heltec R8 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + ${esp32_ota.lib_deps} + bakercp/CRC32 @ ^2.0.0 + +[env:heltec_v4_r8_room_server] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D ADVERT_NAME='"Heltec R8 Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + +<../examples/simple_room_server> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_terminal_chat] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=1 +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_companion_radio_usb] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D DISPLAY_CLASS=SSD1306Display + -D ENABLE_USB_INTERFACE +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_companion_radio_ble] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D DISPLAY_CLASS=SSD1306Display + -D BLE_PIN_CODE=123456 + -D AUTO_SHUTDOWN_MILLIVOLTS=3400 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_companion_radio_ble_ps] +extends = env:heltec_v4_r8_companion_radio_ble +platform_packages = framework-arduinoespressif32 @ symlink://D:/esp32-2.0.17 + +[env:heltec_v4_r8_companion_radio_wifi] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D OFFLINE_QUEUE_SIZE=256 + -D DISPLAY_CLASS=SSD1306Display + -D WIFI_DEBUG_LOGGING=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"mypwd"' +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_sensor] +extends = heltec_v4_r8_oled +build_flags = + ${heltec_v4_r8_oled.build_flags} + -D ADVERT_NAME='"Heltec R8 Sensor"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D DISPLAY_CLASS=SSD1306Display +build_src_filter = ${heltec_v4_r8_oled.build_src_filter} + + + +<../examples/simple_sensor> +lib_deps = + ${heltec_v4_r8_oled.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_tft_repeater] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D DISPLAY_CLASS=ST7789LCDDisplay + -D ADVERT_NAME='"Heltec R8 Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + ${esp32_ota.lib_deps} + bakercp/CRC32 @ ^2.0.0 + +[env:heltec_v4_r8_tft_room_server] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D DISPLAY_CLASS=ST7789LCDDisplay + -D ADVERT_NAME='"Heltec R8 Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + +<../examples/simple_room_server> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_tft_terminal_chat] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=1 +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + +<../examples/simple_secure_chat/main.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_companion_radio_usb] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D DISPLAY_CLASS=ST7789LCDDisplay + -D ENABLE_USB_INTERFACE +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_companion_radio_ble] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -I examples/companion_radio/ui-new + -D DISPLAY_CLASS=ST7789LCDDisplay + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D BLE_PIN_CODE=123456 + -D AUTO_SHUTDOWN_MILLIVOLTS=3400 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_companion_radio_wifi] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D OFFLINE_QUEUE_SIZE=256 + -D DISPLAY_CLASS=ST7789LCDDisplay + -D WIFI_DEBUG_LOGGING=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"mypwd"' +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + + + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:heltec_v4_r8_tft_sensor] +extends = heltec_v4_r8_tft +build_flags = + ${heltec_v4_r8_tft.build_flags} + -D ADVERT_NAME='"Heltec R8 Sensor"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D DISPLAY_CLASS=ST7789LCDDisplay +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + + + +<../examples/simple_sensor> +lib_deps = + ${heltec_v4_r8_tft.lib_deps} + ${esp32_ota.lib_deps} + +[env:heltec_v4_r8_kiss_modem] +extends = Heltec_v4_r8 +build_src_filter = ${Heltec_v4_r8.build_src_filter} + +<../examples/kiss_modem/> + +[env:heltec_v4_r8_tft_kiss_modem] +extends = heltec_v4_r8_tft +build_src_filter = ${heltec_v4_r8_tft.build_src_filter} + +<../examples/kiss_modem/> diff --git a/variants/heltec_v4_r8/target.cpp b/variants/heltec_v4_r8/target.cpp new file mode 100644 index 000000000..0b38531e3 --- /dev/null +++ b/variants/heltec_v4_r8/target.cpp @@ -0,0 +1,45 @@ +#include +#include "target.h" + +HeltecV4R8Board board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +WRAPPER_CLASS radio_driver(radio, board); + +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#if ENV_INCLUDE_GPS + #include + MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock, GPS_RESET, GPS_EN, &board.periph_power); + EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); +#else + EnvironmentSensorManager sensors; +#endif + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display(&board.periph_power); + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); +#endif + +bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + +#if defined(P_LORA_SCLK) + return radio.std_init(&spi); +#else + return radio.std_init(); +#endif +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); +} diff --git a/variants/heltec_v4_r8/target.h b/variants/heltec_v4_r8/target.h new file mode 100644 index 000000000..2d1d7a5bb --- /dev/null +++ b/variants/heltec_v4_r8/target.h @@ -0,0 +1,31 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include +#include +#ifdef DISPLAY_CLASS + #ifdef HELTEC_V4_R8_OLED + #include + #elif defined(HELTEC_V4_R8_TFT) + #include + #endif + #include +#endif + +extern HeltecV4R8Board board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern EnvironmentSensorManager sensors; + +#ifdef DISPLAY_CLASS + extern DISPLAY_CLASS display; + extern MomentaryButton user_btn; +#endif + +bool radio_init(); +mesh::LocalIdentity radio_new_identity(); From 5a92e91498f21274cbffabc20355a8416e5909f4 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 23:31:30 +0700 Subject: [PATCH 19/21] Added ST7789LCD for Heltec v4 r8 --- src/helpers/ui/ST7789LCDDisplay.cpp | 8 ++++++-- src/helpers/ui/ST7789LCDDisplay.h | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/helpers/ui/ST7789LCDDisplay.cpp b/src/helpers/ui/ST7789LCDDisplay.cpp index dc75e9631..7a02668bc 100644 --- a/src/helpers/ui/ST7789LCDDisplay.cpp +++ b/src/helpers/ui/ST7789LCDDisplay.cpp @@ -1,5 +1,9 @@ #include "ST7789LCDDisplay.h" +#ifndef PIN_TFT_MISO + #define PIN_TFT_MISO -1 +#endif + #ifndef DISPLAY_ROTATION #define DISPLAY_ROTATION 3 #endif @@ -29,8 +33,8 @@ bool ST7789LCDDisplay::begin() { } // Im not sure if this is just a t-deck problem or not, if your display is slow try this. - #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) - displaySPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS); + #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) + displaySPI.begin(PIN_TFT_SCL, PIN_TFT_MISO, PIN_TFT_SDA, PIN_TFT_CS); #endif display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT); diff --git a/src/helpers/ui/ST7789LCDDisplay.h b/src/helpers/ui/ST7789LCDDisplay.h index 5b960ca19..03a6d3f12 100644 --- a/src/helpers/ui/ST7789LCDDisplay.h +++ b/src/helpers/ui/ST7789LCDDisplay.h @@ -8,7 +8,7 @@ #include class ST7789LCDDisplay : public DisplayDriver { - #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) + #if defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) SPIClass displaySPI; #endif Adafruit_ST7789 display; @@ -25,7 +25,7 @@ public: { _isOn = false; } -#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) +#elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) ST7789LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64), displaySPI(HSPI), display(&displaySPI, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST), From 28331c110c24e2d012fb8efec58db8d707bb1a91 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Sun, 9 Aug 2026 23:32:19 +0700 Subject: [PATCH 20/21] Added missing RXPowerSaving.h --- examples/simple_room_server/MyMesh.cpp | 5 +++-- examples/simple_sensor/SensorMesh.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 779628636..3f73c6a4b 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -1,4 +1,5 @@ #include "MyMesh.h" +#include "helpers/radiolib/RXPowerSaving.h" #define REPLY_DELAY_MILLIS 1500 #define PUSH_NOTIFY_DELAY_MILLIS 2000 @@ -651,8 +652,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc _prefs.flood_max_advert = 8; _prefs.interference_threshold = 0; // disabled _prefs.cad_enabled = 0; // hardware CAD before TX (off by default; 'set cad on') - _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; - _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; + _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; // RX PowerSaving + _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; // RX PowerSaving #ifdef ROOM_PASSWORD StrHelper::strncpy(_prefs.guest_password, ROOM_PASSWORD, sizeof(_prefs.guest_password)); #endif diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 2cb120d09..e446fd3df 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -1,4 +1,5 @@ #include "SensorMesh.h" +#include "helpers/radiolib/RXPowerSaving.h" /* ------------------------------ Config -------------------------------- */ @@ -730,8 +731,8 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise _prefs.flood_max = 64; _prefs.interference_threshold = 0; // disabled _prefs.cad_enabled = 0; // hardware CAD before TX (off by default; 'set cad on') - _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; - _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; + _prefs.rx_ps_rx_us = RX_POWERSAVING_DEFAULT_RX_US; // RX PowerSaving + _prefs.rx_ps_sleep_us = RX_POWERSAVING_DEFAULT_SLEEP_US; // RX PowerSaving // GPS defaults _prefs.gps_enabled = 0; From 14a7f5233febbc620450e8a97f74a82f6183f6cd Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Mon, 10 Aug 2026 19:32:08 +0700 Subject: [PATCH 21/21] Final PS 17 on PS16 branch --- build-iotthinks.sh | 50 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/build-iotthinks.sh b/build-iotthinks.sh index 85d681bda..61bd96b22 100644 --- a/build-iotthinks.sh +++ b/build-iotthinks.sh @@ -3,12 +3,13 @@ export FIRMWARE_VERSION="PowerSaving17" ############# Repeaters ############# # Commonly-used boards -## ESP32 - 17 boards +## ESP32 - 18 boards sh build.sh build-firmware \ Heltec_ct62_repeater \ Heltec_E290_repeater \ Heltec_v3_repeater \ heltec_v4_repeater \ +heltec_v4_r8_repeater \ heltec_tracker_v2_repeater \ Heltec_Wireless_Paper_repeater \ Heltec_Wireless_Tracker_repeater \ @@ -18,22 +19,24 @@ LilyGo_TBeam_1W_repeater \ Station_G2_repeater \ T_Beam_S3_Supreme_SX1262_repeater \ Tbeam_SX1262_repeater \ +ThinkNode_M5_Repeater \ Xiao_C3_repeater \ Xiao_C6_repeater_ \ Xiao_S3_repeater \ Xiao_S3_WIO_repeater -## NRF52 - 21 boards +## NRF52 - 22 boards sh build.sh build-firmware \ GAT562_30S_Mesh_Kit_repeater \ GAT562_Mesh_Tracker_Pro_repeater \ Heltec_mesh_solar_repeater \ Heltec_t096_repeater \ -Heltec_t1_repeater \ Heltec_t114_repeater \ +Heltec_t1_repeater \ ikoka_nano_nrf_22dbm_repeater \ ikoka_nano_nrf_30dbm_repeater \ ikoka_nano_nrf_33dbm_repeater \ +LilyGo_T-Echo_Card_repeater \ LilyGo_T-Echo_repeater \ ProMicro_repeater \ RAK_3401_repeater \ @@ -54,10 +57,11 @@ LilyGo_TLora_V2_1_1_6_repeater \ Tbeam_SX1276_repeater ############# Room Server ############# -# ESP32 - 7 boards +# ESP32 - 8 boards sh build.sh build-firmware \ Heltec_v3_room_server \ heltec_v4_room_server \ +heltec_v4_r8_room_server \ heltec_tracker_v2_room_server \ Heltec_Wireless_Paper_room_server \ Heltec_WSL3_room_server \ @@ -75,13 +79,15 @@ WioTrackerL1_room_server \ Xiao_nrf52_room_server ############# Companions BLE ############# -# NRF52 - 15 boards +# NRF52 - 17 boards sh build.sh build-firmware \ Heltec_t096_companion_radio_ble_femon \ Heltec_t096_companion_radio_ble_femoff \ Heltec_t1_companion_radio_ble \ Heltec_t114_companion_radio_ble \ +LilyGo_T-Echo_Card_companion_radio_ble \ LilyGo_T-Echo_companion_radio_ble \ +ProMicro_companion_radio_ble \ RAK_3401_companion_radio_ble \ RAK_4631_companion_radio_ble \ RAK_WisMesh_Tag_companion_radio_ble \ @@ -94,15 +100,16 @@ WioTrackerL1_companion_radio_ble \ Xiao_nrf52_companion_radio_ble ############# Companions BLE PS ############# -# ESP32 - 19 boards +# ESP32 - 21 boards sh build.sh build-firmware \ Heltec_ct62_companion_radio_ble_ps \ heltec_tracker_v2_companion_radio_ble_ps \ Heltec_v2_companion_radio_ble_ps \ Heltec_v3_companion_radio_ble_ps \ heltec_v4_3_companion_radio_ble_ps_femoff \ -heltec_v4_companion_radio_ble_ps \ +heltec_v4_companion_radio_ble_ps_femon \ heltec_v4_expansionkit_tft_companion_radio_ble_ps \ +heltec_v4_r8_companion_radio_ble_ps \ Heltec_Wireless_Paper_companion_radio_ble_ps \ Heltec_Wireless_Tracker_companion_radio_ble_ps \ Heltec_WSL3_companion_radio_ble_ps \ @@ -112,28 +119,49 @@ LilyGo_TLora_V2_1_1_6_companion_radio_ble_ps \ T_Beam_S3_Supreme_SX1262_companion_radio_ble_ps \ Tbeam_SX1262_companion_radio_ble_ps \ Tbeam_SX1276_companion_radio_ble_ps \ +ThinkNode_M5_companion_radio_ble_ps \ Xiao_C3_companion_radio_ble_ps \ Xiao_S3_companion_radio_ble_ps \ Xiao_S3_WIO_companion_radio_ble_ps ############# Companions USB ############# sh build.sh build-firmware \ -Heltec_t096_companion_radio_usb +Heltec_t096_companion_radio_usb \ +heltec_v4_companion_radio_usb \ +heltec_v4_companion_radio_usb_ps_femoff \ +heltec_v4_companion_radio_usb_ps_femon ############# Sample builds ############# -# 14 boards +# 24 boards sh build.sh build-firmware \ Heltec_t096_companion_radio_ble_femon \ Heltec_t096_companion_radio_ble_femoff \ +Heltec_t096_companion_radio_usb \ Heltec_t096_repeater \ +Heltec_t114_companion_radio_ble \ +Heltec_t114_repeater \ Heltec_v3_companion_radio_ble_ps \ Heltec_v3_repeater \ heltec_v4_3_companion_radio_ble_ps_femoff \ -heltec_v4_companion_radio_ble_ps \ heltec_v4_repeater \ +RAK_3401_companion_radio_ble \ +RAK_3401_repeater \ RAK_4631_companion_radio_ble \ RAK_4631_repeater \ +SenseCap_Solar_companion_radio_ble \ +SenseCap_Solar_repeater \ +WioTrackerL1_companion_radio_ble \ +WioTrackerL1_repeater \ Xiao_C3_companion_radio_ble_ps \ Xiao_C3_repeater \ Xiao_C6_companion_radio_ble_ \ -Xiao_C6_repeater_ \ No newline at end of file +Xiao_C6_repeater_ \ +Xiao_nrf52_companion_radio_ble \ +Xiao_nrf52_repeater + +# 4 boards +sh build.sh build-firmware \ +heltec_v4_companion_radio_ble_ps_femon \ +heltec_v4_companion_radio_usb \ +heltec_v4_companion_radio_usb_ps_femoff \ +heltec_v4_companion_radio_usb_ps_femon \ No newline at end of file