-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.cpp
45 lines (41 loc) · 1.28 KB
/
node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "node.h"
#include "definitions.h"
#include "influx.h"
Point node("node");
void setNodeTags() {
node.clearTags();
node.addTag(F("MAC"), WiFi.macAddress());
node.addTag(F("name"), config.getString("name"));
node.addTag(F("location"), config.getString("location"));
node.addTag(F("firmware"), FIRMWARE_VERSION);
}
void captureNodeFields() {
node.clearFields();
node.addField(F("rssi"), WiFi.RSSI());
node.addField(F("uptime"), millis() - setupMillis);
node.addField(F("freeHeap"), ESP.getFreeHeap());
node.addField(F("heapFragmentation"),
100 - ESP.getMaxAllocHeap() * 100.0 / ESP.getFreeHeap());
}
/**
* Task: Wait the appropriate period, and log the `node` fields.
*
* If logging fails, it will wait progressively smaller portions of time.
*/
void nodeLoggerTask(void *parameters) {
uint64_t delayTime = NODE_LOG_PERIOD;
for (;;) {
Serial.println(F("[ NODE ] Logger task"));
captureNodeFields();
bool logOk = logPoint(node);
if (!logOk) {
// On failure, Decrease delay by 25%, 1 sec minimum
delayTime = min(delayTime * 0.75, 1000.0);
} else {
// On success, reset delay to normal
delayTime = NODE_LOG_PERIOD;
}
Serial.println(F("[ NODE ] Waiting..."));
vTaskDelay(delayTime / portTICK_PERIOD_MS);
}
}