Browse Source

lora tx goes to deep sleep

Thomas Buck 2 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
-.pio/build/lorarx/compile_commands.json
1
+.pio/build/loratx/compile_commands.json

+ 2
- 0
include/smart_meter.h View File

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

+ 18
- 2
src/lora.cpp View File

16
 #include <Arduino.h>
16
 #include <Arduino.h>
17
 
17
 
18
 // Turns the 'PRG' button into the power button, long press is off
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
 #define HELTEC_POWER_BUTTON
21
 #define HELTEC_POWER_BUTTON
22
+#endif // ! FEATURE_SML
20
 
23
 
21
 #include <heltec_unofficial.h>
24
 #include <heltec_unofficial.h>
22
 
25
 
23
 #include "config.h"
26
 #include "config.h"
24
 #include "DebugLog.h"
27
 #include "DebugLog.h"
25
 #include "influx.h"
28
 #include "influx.h"
29
+#include "smart_meter.h"
26
 #include "lora.h"
30
 #include "lora.h"
27
 
31
 
28
 //#define DEBUG_LORA_RX_HEXDUMP
32
 //#define DEBUG_LORA_RX_HEXDUMP
31
 #define LORA_LED_BRIGHTNESS 0 // in percent, 50% brightness is plenty for this LED
35
 #define LORA_LED_BRIGHTNESS 0 // in percent, 50% brightness is plenty for this LED
32
 #define OLED_BAT_INTERVAL (2UL * 60UL * 1000UL) // in ms
36
 #define OLED_BAT_INTERVAL (2UL * 60UL * 1000UL) // in ms
33
 #define FORCE_BAT_SEND_AT_OLED_INTERVAL
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
 #else // FEATURE_SML
41
 #else // FEATURE_SML
35
 #define LORA_LED_BRIGHTNESS 25 // in percent, 50% brightness is plenty for this LED
42
 #define LORA_LED_BRIGHTNESS 25 // in percent, 50% brightness is plenty for this LED
36
 #endif // FEATURE_SML
43
 #endif // FEATURE_SML
306
 void lora_run(void) {
313
 void lora_run(void) {
307
     heltec_loop();
314
     heltec_loop();
308
 
315
 
309
-#ifdef OLED_BAT_INTERVAL
310
     unsigned long time = millis();
316
     unsigned long time = millis();
317
+
318
+#ifdef OLED_BAT_INTERVAL
311
     if (((time - last_bat_time) >= OLED_BAT_INTERVAL) || (last_bat_time == 0)) {
319
     if (((time - last_bat_time) >= OLED_BAT_INTERVAL) || (last_bat_time == 0)) {
312
         last_bat_time = time;
320
         last_bat_time = time;
313
         print_bat();
321
         print_bat();
316
         lora_sml_send(LORA_SML_BAT_V, lora_get_mangled_bat(), 0);
324
         lora_sml_send(LORA_SML_BAT_V, lora_get_mangled_bat(), 0);
317
 #endif // FORCE_BAT_SEND_AT_OLED_INTERVAL
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
     if (!use_lora) {
337
     if (!use_lora) {
322
         return;
338
         return;

+ 4
- 0
src/smart_meter.cpp View File

33
 static double SumWh = NAN, T1Wh = NAN, T2Wh = NAN;
33
 static double SumWh = NAN, T1Wh = NAN, T2Wh = NAN;
34
 static double SumW = NAN, L1W = NAN, L2W = NAN, L3W = NAN;
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
 static void EnergySum(void) {
40
 static void EnergySum(void) {
37
     smlOBISWh(SumWh);
41
     smlOBISWh(SumWh);
38
 }
42
 }

Loading…
Cancel
Save