|
@@ -33,9 +33,9 @@
|
33
|
33
|
|
34
|
34
|
#ifdef FEATURE_SML
|
35
|
35
|
#define LORA_LED_BRIGHTNESS 0 // in percent, 50% brightness is plenty for this LED
|
36
|
|
-#define DEEP_SLEEP_DURATION_S 60
|
37
|
|
-#define DEEP_SLEEP_TIMEOUT_MS (30UL * 1000UL)
|
38
|
|
-#define DEEP_SLEEP_ABORT_NO_DATA_MS DEEP_SLEEP_TIMEOUT_MS
|
|
36
|
+#define DEEP_SLEEP_DURATION_S (60 - (millis() / 1000)) // 60s cycle time
|
|
37
|
+#define DEEP_SLEEP_TIMEOUT_MS (30UL * 1000UL) // fallback sleep timeout when sml data was received
|
|
38
|
+#define DEEP_SLEEP_ABORT_NO_DATA_MS DEEP_SLEEP_TIMEOUT_MS // sleep timeout when no sml data received
|
39
|
39
|
#else // FEATURE_SML
|
40
|
40
|
#define LORA_LED_BRIGHTNESS 25 // in percent, 50% brightness is plenty for this LED
|
41
|
41
|
#endif // FEATURE_SML
|
|
@@ -59,7 +59,7 @@
|
59
|
59
|
// transmissting without an antenna can damage your hardware.
|
60
|
60
|
// 25mW = 14dBm
|
61
|
61
|
#define MAX_TX_POWER 14
|
62
|
|
-#define ANTENNA_GAIN 5
|
|
62
|
+#define ANTENNA_GAIN (5 - 3) // 3dB for the coax extensions and their SMA connectors
|
63
|
63
|
#define TRANSMIT_POWER (MAX_TX_POWER - ANTENNA_GAIN)
|
64
|
64
|
|
65
|
65
|
#define RADIOLIB_xy(action) \
|
|
@@ -85,7 +85,9 @@ static unsigned long tx_time = 0, minimum_pause = 0;
|
85
|
85
|
static volatile bool rx_flag = false;
|
86
|
86
|
|
87
|
87
|
#ifndef LORA_KEEP_SENDING_CACHE
|
|
88
|
+#define BAT_MSG_EVERY_NTH 5
|
88
|
89
|
RTC_DATA_ATTR static uint8_t last_tx_msg = LORA_SML_HELLO;
|
|
90
|
+RTC_DATA_ATTR static uint8_t bat_msg_cnt = 0;
|
89
|
91
|
#endif // ! LORA_KEEP_SENDING_CACHE
|
90
|
92
|
|
91
|
93
|
#ifdef FEATURE_SML
|
|
@@ -259,6 +261,13 @@ void lora_sml_done(void) {
|
259
|
261
|
do {
|
260
|
262
|
last_tx_msg++;
|
261
|
263
|
n++;
|
|
264
|
+ if (last_tx_msg == LORA_SML_BAT_V) {
|
|
265
|
+ bat_msg_cnt++;
|
|
266
|
+ if (bat_msg_cnt < BAT_MSG_EVERY_NTH) {
|
|
267
|
+ continue; // skip bat message this time
|
|
268
|
+ }
|
|
269
|
+ bat_msg_cnt = 0;
|
|
270
|
+ }
|
262
|
271
|
if (last_tx_msg >= LORA_SML_NUM_MESSAGES) {
|
263
|
272
|
last_tx_msg = 0;
|
264
|
273
|
}
|
|
@@ -270,6 +279,7 @@ void lora_sml_done(void) {
|
270
|
279
|
lora_tx(msg, cache[msg].value);
|
271
|
280
|
}
|
272
|
281
|
|
|
282
|
+ debug.println("sleep");
|
273
|
283
|
heltec_deep_sleep(DEEP_SLEEP_DURATION_S < (minimum_pause / 1000) ? (minimum_pause / 1000) : DEEP_SLEEP_DURATION_S);
|
274
|
284
|
#endif // ! LORA_KEEP_SENDING_CACHE
|
275
|
285
|
}
|
|
@@ -363,6 +373,7 @@ void lora_run(void) {
|
363
|
373
|
bool got_sml = sml_data_received();
|
364
|
374
|
if ((got_sml && (time >= DEEP_SLEEP_TIMEOUT_MS))
|
365
|
375
|
|| ((!got_sml) && (time >= DEEP_SLEEP_ABORT_NO_DATA_MS))) {
|
|
376
|
+ debug.printf("falllback sleep %d %lu\n", got_sml, time);
|
366
|
377
|
heltec_deep_sleep(DEEP_SLEEP_DURATION_S < (minimum_pause / 1000) ? (minimum_pause / 1000) : DEEP_SLEEP_DURATION_S);
|
367
|
378
|
}
|
368
|
379
|
#endif // DEEP_SLEEP_TIMEOUT_MS && DEEP_SLEEP_DURATION_S
|
|
@@ -371,6 +382,7 @@ void lora_run(void) {
|
371
|
382
|
if ((time >= (6UL * 60UL * 60UL * 1000UL) // running for at least 6h
|
372
|
383
|
&& ((time - last_rx) >= (30UL * 1000UL))) // and last lora rx at least 30s ago
|
373
|
384
|
|| ((time - last_rx) >= (4UL * 60UL * 1000UL))) { // or last message longer than 4min ago
|
|
385
|
+ debug.println("hang sleep");
|
374
|
386
|
heltec_deep_sleep(5); // attempt reset to avoid lorarx hanging
|
375
|
387
|
}
|
376
|
388
|
#endif // ! FEATURE_SML
|
|
@@ -503,6 +515,7 @@ void lora_run(void) {
|
503
|
515
|
return;
|
504
|
516
|
}
|
505
|
517
|
|
|
518
|
+ debug.println("click");
|
506
|
519
|
lora_tx(LORA_SML_HELLO, heltec_temperature());
|
507
|
520
|
}
|
508
|
521
|
#endif // ! FEATURE_SML
|