mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Logging in progress
This commit is contained in:
@@ -9,19 +9,21 @@ typedef std::vector<LoggingClass> MyLoggingVector;
|
|||||||
|
|
||||||
class LoggingClass {
|
class LoggingClass {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LoggingClass(unsigned long period, unsigned int maxPoints, String key);
|
LoggingClass(unsigned long period, unsigned int maxPoints, String key);
|
||||||
~LoggingClass();
|
~LoggingClass();
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
void writeDate();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
unsigned long currentMillis;
|
unsigned long currentMillis;
|
||||||
unsigned long prevMillis;
|
unsigned long prevMillis;
|
||||||
|
|
||||||
unsigned long _period;
|
unsigned long _period;
|
||||||
unsigned int _maxPoints;
|
unsigned int _maxPoints;
|
||||||
String _key;
|
String _key;
|
||||||
|
|
||||||
|
void addNewDelOldData(const String filename, size_t maxPoints, String payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MyLoggingVector* myLogging;
|
extern MyLoggingVector* myLogging;
|
||||||
|
|||||||
@@ -13,12 +13,33 @@ void LoggingClass::loop() {
|
|||||||
unsigned long difference = currentMillis - prevMillis;
|
unsigned long difference = currentMillis - prevMillis;
|
||||||
if (difference >= _period) {
|
if (difference >= _period) {
|
||||||
prevMillis = millis();
|
prevMillis = millis();
|
||||||
writeDate();
|
addNewDelOldData("log." + _key + ".txt", _maxPoints, jsonReadStr(configLiveJson, _key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggingClass::writeDate() {
|
|
||||||
SerialPrint("I", "Logging", _key);
|
void LoggingClass::addNewDelOldData(const String filename, size_t maxPoints, String payload) {
|
||||||
|
String logData = readFile(filename, 5120);
|
||||||
|
size_t lines_cnt = itemsCount(logData, "\r\n");
|
||||||
|
|
||||||
|
SerialPrint("I", "Logging", "http://" + WiFi.localIP().toString() + "/" + filename + " (" + String(lines_cnt, DEC) + ")");
|
||||||
|
|
||||||
|
if ((lines_cnt > maxPoints + 1) || !lines_cnt) {
|
||||||
|
removeFile(filename);
|
||||||
|
lines_cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines_cnt > maxPoints) {
|
||||||
|
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||||
|
if (timeNow->hasTimeSynced()) {
|
||||||
|
logData += timeNow->getTimeUnix() + " " + payload + "\r\n";
|
||||||
|
writeFile(filename, logData);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (timeNow->hasTimeSynced()) {
|
||||||
|
addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyLoggingVector* myLogging= nullptr;
|
MyLoggingVector* myLogging = nullptr;
|
||||||
13
src/main.cpp
13
src/main.cpp
@@ -98,10 +98,8 @@ void setup() {
|
|||||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||||
|
|
||||||
myLogging = new MyLoggingVector();
|
myLogging = new MyLoggingVector();
|
||||||
myLogging->push_back(LoggingClass(5000, 1, "5 sec"));
|
myLogging->push_back(LoggingClass(30000, 10, "analog-adc-1"));
|
||||||
myLogging->push_back(LoggingClass(10000, 1, "10 sec"));
|
//myLogging->push_back(LoggingClass(10000, 1, "10 sec"));
|
||||||
|
|
||||||
//myLogging->push_back(new LoggingClass());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -124,6 +122,9 @@ void loop() {
|
|||||||
myNotAsyncActions->loop();
|
myNotAsyncActions->loop();
|
||||||
ts.update();
|
ts.update();
|
||||||
|
|
||||||
myLogging->at(0).loop();
|
if (myLogging != nullptr) {
|
||||||
myLogging->at(1).loop();
|
for (unsigned int i = 0; i < myLogging->size(); i++) {
|
||||||
|
myLogging->at(i).loop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user