File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -194,6 +194,7 @@ void setup() {
194194 );
195195
196196#ifdef WIFI_SSID
197+ board.setInhibitSleep (true ); // prevent sleep when WiFi is active
197198 WiFi.begin (WIFI_SSID , WIFI_PWD );
198199 serial_interface.begin (TCP_PORT );
199200#elif defined(BLE_PIN_CODE)
Original file line number Diff line number Diff line change @@ -134,14 +134,17 @@ void loop() {
134134#endif
135135 rtc_clock.tick ();
136136
137- if (the_mesh.getNodePrefs ()->powersaving_enabled && // To check if power saving is enabled
138- the_mesh.millisHasNowPassed (lastActive + nextSleepinSecs * 1000 )) { // To check if it is time to sleep
139- if (!the_mesh.hasPendingWork ()) { // No pending work. Safe to sleep
137+ if (the_mesh.getNodePrefs ()->powersaving_enabled && !the_mesh.hasPendingWork ()) {
138+ #if defined(NRF52_PLATFORM)
139+ board.sleep (1800 ); // nrf ignores seconds param, sleeps whenever possible
140+ #else
141+ if (the_mesh.millisHasNowPassed (lastActive + nextSleepinSecs * 1000 )) { // To check if it is time to sleep
140142 board.sleep (1800 ); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
141143 lastActive = millis ();
142144 nextSleepinSecs = 5 ; // Default: To work for 5s and sleep again
143145 } else {
144146 nextSleepinSecs += 5 ; // When there is pending work, to work another 5s
145147 }
148+ #endif
146149 }
147150}
Original file line number Diff line number Diff line change 1111#include < SPIFFS.h>
1212
1313bool ESP32Board::startOTAUpdate (const char * id, char reply[]) {
14+ inhibit_sleep = true ; // prevent sleep during OTA
1415 WiFi.softAP (" MeshCore-OTA" , NULL );
1516
1617 sprintf (reply, " Started: http://%s/update" , WiFi.softAPIP ().toString ().c_str ());
Original file line number Diff line number Diff line change 88#include < rom/rtc.h>
99#include < sys/time.h>
1010#include < Wire.h>
11- #include " esp_wifi.h"
1211#include " driver/rtc_io.h"
1312
1413class ESP32Board : public mesh ::MainBoard {
1514protected:
1615 uint8_t startup_reason;
16+ bool inhibit_sleep = false ;
1717
1818public:
1919 void begin () {
@@ -72,11 +72,7 @@ class ESP32Board : public mesh::MainBoard {
7272 }
7373
7474 void sleep (uint32_t secs) override {
75- // To check for WiFi status to see if there is active OTA
76- wifi_mode_t mode;
77- esp_err_t err = esp_wifi_get_mode (&mode);
78-
79- if (err != ESP_OK ) { // WiFi is off ~ No active OTA, safe to go to sleep
75+ if (!inhibit_sleep) {
8076 enterLightSleep (secs); // To wake up after "secs" seconds or when receiving a LoRa packet
8177 }
8278 }
@@ -126,6 +122,10 @@ class ESP32Board : public mesh::MainBoard {
126122 }
127123
128124 bool startOTAUpdate (const char * id, char reply[]) override ;
125+
126+ void setInhibitSleep (bool inhibit) {
127+ inhibit_sleep = inhibit;
128+ }
129129};
130130
131131class ESP32RTCClock : public mesh ::RTCClock {
Original file line number Diff line number Diff line change @@ -251,6 +251,32 @@ void NRF52BoardDCDC::begin() {
251251 }
252252}
253253
254+ void NRF52Board::sleep (uint32_t secs) {
255+ // Clear FPU interrupt flags to avoid insomnia
256+ // see errata 87 for details https://docs.nordicsemi.com/bundle/errata_nRF52840_Rev3/page/ERR/nRF52840/Rev3/latest/anomaly_840_87.html
257+ #if (__FPU_USED == 1)
258+ __set_FPSCR (__get_FPSCR () & ~(0x0000009F ));
259+ (void ) __get_FPSCR ();
260+ NVIC_ClearPendingIRQ (FPU_IRQn);
261+ #endif
262+
263+ // On nRF52, we use event-driven sleep instead of timed sleep
264+ // The 'secs' parameter is ignored - we wake on any interrupt
265+ uint8_t sd_enabled = 0 ;
266+ sd_softdevice_is_enabled (&sd_enabled);
267+
268+ if (sd_enabled) {
269+ // first call processes pending softdevice events, second call sleeps.
270+ sd_app_evt_wait ();
271+ sd_app_evt_wait ();
272+ } else {
273+ // softdevice is disabled, use raw WFE
274+ __SEV ();
275+ __WFE ();
276+ __WFE ();
277+ }
278+ }
279+
254280// Temperature from NRF52 MCU
255281float NRF52Board::getMCUTemperature () {
256282 NRF_TEMP ->TASKS_START = 1 ; // Start temperature measurement
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ class NRF52Board : public mesh::MainBoard {
5151 virtual float getMCUTemperature () override ;
5252 virtual void reboot () override { NVIC_SystemReset (); }
5353 virtual bool startOTAUpdate (const char *id, char reply[]) override ;
54+ virtual void sleep (uint32_t secs) override ;
5455
5556#ifdef NRF52_POWER_MANAGEMENT
5657 bool isExternalPowered () override ;
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ class CustomSX1262 : public SX1262 {
7676 setRfSwitchPins (SX126X_RXEN , SX126X_TXEN );
7777 #endif
7878
79+ // for improved RX with Heltec v4
80+ #ifdef SX126X_REGISTER_PATCH
81+ uint8_t r_data = 0 ;
82+ readRegister (0x8B5 , &r_data, 1 );
83+ r_data |= 0x01 ;
84+ writeRegister (0x8B5 , &r_data, 1 );
85+ #endif
86+
7987 return true ; // success
8088 }
8189
Original file line number Diff line number Diff line change @@ -17,18 +17,19 @@ build_flags =
1717 -D P_LORA_SCLK =9
1818 -D P_LORA_MISO =11
1919 -D P_LORA_MOSI =10
20- -D P_LORA_PA_POWER =7 ; power en
21- -D P_LORA_PA_EN =2
22- -D P_LORA_PA_TX_EN =46 ; enable tx
20+ -D P_LORA_PA_POWER =7 ; VFEM_Ctrl - Power on GC1109
21+ -D P_LORA_PA_EN =2 ; PA CSD - Enable GC1109
22+ -D P_LORA_PA_TX_EN =46 ; PA CPS - GC1109 TX PA full(High) / bypass(Low)
2323 -D PIN_USER_BTN =0
2424 -D PIN_VEXT_EN =36
2525 -D PIN_VEXT_EN_ACTIVE =LOW
2626 -D LORA_TX_POWER =10 ; If it is configured as 10 here, the final output will be 22 dbm.
2727 -D MAX_LORA_TX_POWER =22 ; Max SX1262 output
28- -D SX126X_DIO2_AS_RF_SWITCH =true
28+ -D SX126X_REGISTER_PATCH =1 ; Patch register 0x8B5 for improved RX
29+ -D SX126X_DIO2_AS_RF_SWITCH =true ; GC1109 CTX is controlled by SX1262 DIO2
2930 -D SX126X_DIO3_TCXO_VOLTAGE =1.8
3031 -D SX126X_CURRENT_LIMIT =140
31- -D SX126X_RX_BOOSTED_GAIN =1
32+ -D SX126X_RX_BOOSTED_GAIN =1 ; In some cases, commenting this out will improve RX
3233 -D PIN_GPS_RX =38
3334 -D PIN_GPS_TX =39
3435 -D PIN_GPS_RESET =42
You can’t perform that action at this time.
0 commit comments