|
@@ -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;
|