|
@@ -115,6 +115,15 @@ static void print_bat(void) {
|
115
|
115
|
debug.printf("Vbat: %.2fV (%d%%)\n", vbat, heltec_battery_percent(vbat));
|
116
|
116
|
}
|
117
|
117
|
|
|
118
|
+double lora_get_mangled_bat(void) {
|
|
119
|
+ uint8_t data[sizeof(double)];
|
|
120
|
+ float vbat = heltec_vbat();
|
|
121
|
+ int percent = heltec_battery_percent(vbat);
|
|
122
|
+ memcpy(data, &vbat, sizeof(float));
|
|
123
|
+ memcpy(data + sizeof(float), &percent, sizeof(int));
|
|
124
|
+ return *((double *)data);
|
|
125
|
+}
|
|
126
|
+
|
118
|
127
|
static void lora_rx(void) {
|
119
|
128
|
rx_flag = true;
|
120
|
129
|
}
|
|
@@ -305,10 +314,6 @@ void lora_run(void) {
|
305
|
314
|
debug.printf(" RSSI: %.2f dBm\n", radio.getRSSI());
|
306
|
315
|
debug.printf(" SNR: %.2f dB\n", radio.getSNR());
|
307
|
316
|
|
308
|
|
- double val = NAN;
|
309
|
|
- memcpy(&val, data + 1, sizeof(double));
|
310
|
|
- debug.printf(" Value: %.2f\n", val);
|
311
|
|
-
|
312
|
317
|
#ifdef DEBUG_LORA_RX_HEXDUMP
|
313
|
318
|
for (int i = 0; i < sizeof(data); i++) {
|
314
|
319
|
debug.printf("%02X", data[i]);
|
|
@@ -320,7 +325,21 @@ void lora_run(void) {
|
320
|
325
|
}
|
321
|
326
|
#endif
|
322
|
327
|
|
323
|
|
- // TODO payload to influxdb
|
|
328
|
+ if (data[0] == LORA_SML_BAT_V) {
|
|
329
|
+ float vbat = NAN;
|
|
330
|
+ int percent = -1;
|
|
331
|
+ memcpy(&vbat, data + 1, sizeof(float));
|
|
332
|
+ memcpy(&percent, data + 1 + sizeof(float), sizeof(int));
|
|
333
|
+ debug.printf(" Vbat: %.2f (%d%%)\n", vbat, percent);
|
|
334
|
+
|
|
335
|
+ // TODO payload to influxdb
|
|
336
|
+ } else {
|
|
337
|
+ double val = NAN;
|
|
338
|
+ memcpy(&val, data + 1, sizeof(double));
|
|
339
|
+ debug.printf(" Value: %.2f\n", val);
|
|
340
|
+
|
|
341
|
+ // TODO payload to influxdb
|
|
342
|
+ }
|
324
|
343
|
}
|
325
|
344
|
|
326
|
345
|
success = true;
|
|
@@ -350,7 +369,6 @@ void lora_run(void) {
|
350
|
369
|
lora_tx(s.c_str(), s.length());
|
351
|
370
|
}
|
352
|
371
|
#else // LORA_TEST_TX
|
353
|
|
-#ifdef FEATURE_SML
|
354
|
372
|
if (button.isSingleClick()) {
|
355
|
373
|
// In case of button click, tell user to wait
|
356
|
374
|
if (!tx_legal) {
|
|
@@ -358,9 +376,16 @@ void lora_run(void) {
|
358
|
376
|
return;
|
359
|
377
|
}
|
360
|
378
|
|
361
|
|
- lora_sml_send(LORA_SML_HELLO, -23.42, 0);
|
362
|
|
- }
|
|
379
|
+#ifdef FEATURE_SML
|
|
380
|
+ lora_sml_send(LORA_SML_BAT_V, lora_get_mangled_bat(), 0);
|
|
381
|
+#else // FEATURE_SML
|
|
382
|
+ uint8_t data[sizeof(double) + 1];
|
|
383
|
+ data[0] = LORA_SML_HELLO;
|
|
384
|
+ double tmp = -23.42;
|
|
385
|
+ memcpy(data + 1, &tmp, sizeof(double));
|
|
386
|
+ lora_tx(data, sizeof(data));
|
363
|
387
|
#endif // FEATURE_SML
|
|
388
|
+ }
|
364
|
389
|
#endif // LORA_TEST_TX
|
365
|
390
|
}
|
366
|
391
|
|