|
@@ -22,6 +22,7 @@
|
22
|
22
|
|
23
|
23
|
#include "config.h"
|
24
|
24
|
#include "DebugLog.h"
|
|
25
|
+#include "influx.h"
|
25
|
26
|
#include "lora.h"
|
26
|
27
|
|
27
|
28
|
// define LORA_TEST_TX to periodically transmit a test message
|
|
@@ -31,7 +32,8 @@
|
31
|
32
|
|
32
|
33
|
#ifdef FEATURE_SML
|
33
|
34
|
#define LORA_LED_BRIGHTNESS 1 // in percent, 50% brightness is plenty for this LED
|
34
|
|
-#define OLED_BAT_INTERVAL (10UL * 1000UL) // in ms
|
|
35
|
+#define OLED_BAT_INTERVAL (2UL * 60UL * 1000UL) // in ms
|
|
36
|
+#define FORCE_BAT_SEND_AT_OLED_INTERVAL
|
35
|
37
|
#else // FEATURE_SML
|
36
|
38
|
#define LORA_LED_BRIGHTNESS 25 // in percent, 50% brightness is plenty for this LED
|
37
|
39
|
#endif // FEATURE_SML
|
|
@@ -135,7 +137,7 @@ static bool lora_tx(uint8_t *data, size_t len) {
|
135
|
137
|
return false;
|
136
|
138
|
}
|
137
|
139
|
|
138
|
|
- debug.printf("TX [%lu] ", len);
|
|
140
|
+ debug.printf("TX [%d] (%lu) ", data[0], len);
|
139
|
141
|
radio.clearDio1Action();
|
140
|
142
|
|
141
|
143
|
heltec_led(LORA_LED_BRIGHTNESS);
|
|
@@ -292,9 +294,13 @@ void lora_run(void) {
|
292
|
294
|
|
293
|
295
|
#ifdef OLED_BAT_INTERVAL
|
294
|
296
|
unsigned long time = millis();
|
295
|
|
- if ((time - last_bat_time) >= OLED_BAT_INTERVAL) {
|
|
297
|
+ if (((time - last_bat_time) >= OLED_BAT_INTERVAL) || (last_bat_time == 0)) {
|
296
|
298
|
last_bat_time = time;
|
297
|
299
|
print_bat();
|
|
300
|
+
|
|
301
|
+#ifdef FORCE_BAT_SEND_AT_OLED_INTERVAL
|
|
302
|
+ lora_sml_send(LORA_SML_BAT_V, lora_get_mangled_bat(), 0);
|
|
303
|
+#endif // FORCE_BAT_SEND_AT_OLED_INTERVAL
|
298
|
304
|
}
|
299
|
305
|
#endif
|
300
|
306
|
|
|
@@ -314,7 +320,7 @@ void lora_run(void) {
|
314
|
320
|
debug.printf(" RSSI: %.2f dBm\n", radio.getRSSI());
|
315
|
321
|
debug.printf(" SNR: %.2f dB\n", radio.getSNR());
|
316
|
322
|
|
317
|
|
-#ifdef DEBUG_LORA_RX_HEXDUMP
|
|
323
|
+#if defined(DEBUG_LORA_RX_HEXDUMP) || (!defined(ENABLE_INFLUXDB_LOGGING))
|
318
|
324
|
for (int i = 0; i < sizeof(data); i++) {
|
319
|
325
|
debug.printf("%02X", data[i]);
|
320
|
326
|
if (i < (sizeof(data) - 1)) {
|
|
@@ -325,6 +331,7 @@ void lora_run(void) {
|
325
|
331
|
}
|
326
|
332
|
#endif
|
327
|
333
|
|
|
334
|
+#ifdef ENABLE_INFLUXDB_LOGGING
|
328
|
335
|
if (data[0] == LORA_SML_BAT_V) {
|
329
|
336
|
float vbat = NAN;
|
330
|
337
|
int percent = -1;
|
|
@@ -332,14 +339,55 @@ void lora_run(void) {
|
332
|
339
|
memcpy(&percent, data + 1 + sizeof(float), sizeof(int));
|
333
|
340
|
debug.printf(" Vbat: %.2f (%d%%)\n", vbat, percent);
|
334
|
341
|
|
335
|
|
- // TODO payload to influxdb
|
|
342
|
+ writeSensorDatum("environment", "sml", SENSOR_LOCATION, "vbat", vbat);
|
|
343
|
+ writeSensorDatum("environment", "sml", SENSOR_LOCATION, "percent", percent);
|
336
|
344
|
} else {
|
337
|
345
|
double val = NAN;
|
338
|
346
|
memcpy(&val, data + 1, sizeof(double));
|
339
|
347
|
debug.printf(" Value: %.2f\n", val);
|
340
|
348
|
|
341
|
|
- // TODO payload to influxdb
|
|
349
|
+ String key;
|
|
350
|
+ switch (data[0]) {
|
|
351
|
+ case LORA_SML_HELLO:
|
|
352
|
+ key = "hello";
|
|
353
|
+ break;
|
|
354
|
+
|
|
355
|
+ case LORA_SML_SUM_WH:
|
|
356
|
+ key = "Sum_Wh";
|
|
357
|
+ break;
|
|
358
|
+
|
|
359
|
+ case LORA_SML_T1_WH:
|
|
360
|
+ key = "T1_Wh";
|
|
361
|
+ break;
|
|
362
|
+
|
|
363
|
+ case LORA_SML_T2_WH:
|
|
364
|
+ key = "T2_Wh";
|
|
365
|
+ break;
|
|
366
|
+
|
|
367
|
+ case LORA_SML_SUM_W:
|
|
368
|
+ key = "Sum_W";
|
|
369
|
+ break;
|
|
370
|
+
|
|
371
|
+ case LORA_SML_L1_W:
|
|
372
|
+ key = "L1_W";
|
|
373
|
+ break;
|
|
374
|
+
|
|
375
|
+ case LORA_SML_L2_W:
|
|
376
|
+ key = "L2_W";
|
|
377
|
+ break;
|
|
378
|
+
|
|
379
|
+ case LORA_SML_L3_W:
|
|
380
|
+ key = "L3_W";
|
|
381
|
+ break;
|
|
382
|
+
|
|
383
|
+ default:
|
|
384
|
+ key = "unknown";
|
|
385
|
+ break;
|
|
386
|
+ }
|
|
387
|
+
|
|
388
|
+ writeSensorDatum("environment", "sml", SENSOR_LOCATION, key, val);
|
342
|
389
|
}
|
|
390
|
+#endif // ENABLE_INFLUXDB_LOGGING
|
343
|
391
|
}
|
344
|
392
|
|
345
|
393
|
success = true;
|