Browse Source

lora tx goes to deep sleep

Thomas Buck 4 months ago
parent
commit
9e7fd20188
4 changed files with 25 additions and 3 deletions
  1. 1
    1
      compile_commands.json
  2. 2
    0
      include/smart_meter.h
  3. 18
    2
      src/lora.cpp
  4. 4
    0
      src/smart_meter.cpp

+ 1
- 1
compile_commands.json View File

@@ -1 +1 @@
1
-.pio/build/lorarx/compile_commands.json
1
+.pio/build/loratx/compile_commands.json

+ 2
- 0
include/smart_meter.h View File

@@ -19,6 +19,8 @@
19 19
 void sml_init(void);
20 20
 void sml_run(void);
21 21
 
22
+bool sml_data_received(void);
23
+
22 24
 #endif // FEATURE_SML
23 25
 
24 26
 #endif // __ESP_ENV_SMART_METER__

+ 18
- 2
src/lora.cpp View File

@@ -16,13 +16,17 @@
16 16
 #include <Arduino.h>
17 17
 
18 18
 // Turns the 'PRG' button into the power button, long press is off
19
+// this also increases deep sleep power usage!
20
+#ifndef FEATURE_SML
19 21
 #define HELTEC_POWER_BUTTON
22
+#endif // ! FEATURE_SML
20 23
 
21 24
 #include <heltec_unofficial.h>
22 25
 
23 26
 #include "config.h"
24 27
 #include "DebugLog.h"
25 28
 #include "influx.h"
29
+#include "smart_meter.h"
26 30
 #include "lora.h"
27 31
 
28 32
 //#define DEBUG_LORA_RX_HEXDUMP
@@ -31,6 +35,9 @@
31 35
 #define LORA_LED_BRIGHTNESS 0 // in percent, 50% brightness is plenty for this LED
32 36
 #define OLED_BAT_INTERVAL (2UL * 60UL * 1000UL) // in ms
33 37
 #define FORCE_BAT_SEND_AT_OLED_INTERVAL
38
+#define DEEP_SLEEP_TIMEOUT_MS (1UL * 60UL * 1000UL) // gather data for 1min
39
+#define DEEP_SLEEP_ABORT_NO_DATA_MS (20UL * 1000UL) // if no data appears, abort after 20s
40
+#define DEEP_SLEEP_DURATION_S (5UL * 60UL) // then sleep for 5min
34 41
 #else // FEATURE_SML
35 42
 #define LORA_LED_BRIGHTNESS 25 // in percent, 50% brightness is plenty for this LED
36 43
 #endif // FEATURE_SML
@@ -306,8 +313,9 @@ void lora_init(void) {
306 313
 void lora_run(void) {
307 314
     heltec_loop();
308 315
 
309
-#ifdef OLED_BAT_INTERVAL
310 316
     unsigned long time = millis();
317
+
318
+#ifdef OLED_BAT_INTERVAL
311 319
     if (((time - last_bat_time) >= OLED_BAT_INTERVAL) || (last_bat_time == 0)) {
312 320
         last_bat_time = time;
313 321
         print_bat();
@@ -316,7 +324,15 @@ void lora_run(void) {
316 324
         lora_sml_send(LORA_SML_BAT_V, lora_get_mangled_bat(), 0);
317 325
 #endif // FORCE_BAT_SEND_AT_OLED_INTERVAL
318 326
     }
319
-#endif
327
+#endif // OLED_BAT_INTERVAL
328
+
329
+#if defined(DEEP_SLEEP_TIMEOUT_MS) && defined(DEEP_SLEEP_DURATION_S)
330
+    bool got_sml = sml_data_received();
331
+    if ((got_sml && (time >= DEEP_SLEEP_TIMEOUT_MS))
332
+            || ((!got_sml) && (time >= DEEP_SLEEP_ABORT_NO_DATA_MS))) {
333
+        heltec_deep_sleep(DEEP_SLEEP_DURATION_S);
334
+    }
335
+#endif // DEEP_SLEEP_TIMEOUT_MS && DEEP_SLEEP_DURATION_S
320 336
 
321 337
     if (!use_lora) {
322 338
         return;

+ 4
- 0
src/smart_meter.cpp View File

@@ -33,6 +33,10 @@ static unsigned long counter = 0;
33 33
 static double SumWh = NAN, T1Wh = NAN, T2Wh = NAN;
34 34
 static double SumW = NAN, L1W = NAN, L2W = NAN, L3W = NAN;
35 35
 
36
+bool sml_data_received(void) {
37
+    return counter > 0;
38
+}
39
+
36 40
 static void EnergySum(void) {
37 41
     smlOBISWh(SumWh);
38 42
 }

Loading…
Cancel
Save