chart data rotate stuff wip

This commit is contained in:
DeltaLima 2025-04-08 23:34:08 +02:00
parent 094ca906dc
commit 7944fe3d46
3 changed files with 37 additions and 12 deletions

View file

@ -543,7 +543,7 @@ char* Char_Timestamp_yyyymmdd(const unsigned long timestamp) {
snprintf(tmp_minute, sizeof(tmp_minute), "%d", minute(timestamp));
}
snprintf(tmp_timestamp, sizeof(tmp_timestamp), "%d%s%s_%s", year(), tmp_month, tmp_day, tmp_minute);
snprintf(tmp_timestamp, sizeof(tmp_timestamp), "%d%s%s%s", year(), tmp_month, tmp_day, tmp_minute);
return tmp_timestamp;
}

View file

@ -754,14 +754,14 @@ void LFS_Chart_Log_Data(const byte chartId) {
#ifdef DEBUG
Log.notice(F("%s fullpath: %s, message: %s" CR), LogLoc, filePath, tmp_message);
Log.verbose(F("%s fullpath: %s, message: %s" CR), LogLoc, filePath, tmp_message);
#endif
/* https://github.com/cotestatnt/async-esp-fs-webserver/blob/master/examples/csvLogger/csvLogger.ino */
/* check if dir exists */
if (!LittleFS.exists(chartDirPath)) {
#ifdef DEBUG
Log.notice(F("%s create non-existing dir: %s" CR), LogLoc, chartDirPath);
Log.verbose(F("%s create non-existing dir: %s" CR), LogLoc, chartDirPath);
#endif
LittleFS.mkdir(chartDirPath);
}
@ -770,12 +770,12 @@ void LFS_Chart_Log_Data(const byte chartId) {
if (LittleFS.exists(filePath)) {
file = LittleFS.open(filePath, "a"); // Append to existing file
#ifdef DEBUG
Log.notice(F("%s appending filePath: %s" CR), LogLoc, filePath);
Log.verbose(F("%s appending filePath: %s" CR), LogLoc, filePath);
#endif
} else {
file = LittleFS.open(filePath, "w"); // Create a new file
#ifdef DEBUG
Log.notice(F("%s create filePath: %s" CR), LogLoc, filePath);
Log.verbose(F("%s create filePath: %s" CR), LogLoc, filePath);
#endif
}
file.println(tmp_message);
@ -786,9 +786,7 @@ void LFS_Chart_Log_Data(const byte chartId) {
/* Function to List Chart dirs, for debugging purposes mainly */
void LFS_Chart_Dirlist_Data(const byte chartId) {
const static char LogLoc[] PROGMEM = "[LittleFS:Chart_Dirlist_Data]";
//const char *basePath = "/c";
char chartDirPath[10];
//snprintf(path, sizeof(path), "/chart/%d", chartId);
snprintf(chartDirPath, sizeof(chartDirPath), "%s%d", CHART_BASE_PATH, chartId);
/* https://github.com/cotestatnt/async-esp-fs-webserver/blob/master/src/AsyncFsWebServer.cpp */
@ -796,10 +794,9 @@ void LFS_Chart_Dirlist_Data(const byte chartId) {
File file = root.openNextFile();
while (file) {
if (!file.isDirectory()) {
Serial.print(" FILE : ");
Serial.print(file.name());
Serial.print("\tSIZE: ");
Serial.println(file.size());
#ifdef DEBUG
Log.verbose(F("%s PATH: %s \tFILE: %s \tSIZE: %d" CR), LogLoc, chartDirPath, file.name(), file.size());
#endif
}
file = root.openNextFile();
}
@ -807,7 +804,34 @@ void LFS_Chart_Dirlist_Data(const byte chartId) {
/* Rotate Chart data files */
void LFS_Chart_Rotate_Data(const byte chartId) {
const static char LogLoc[] PROGMEM = "[LittleFS:Chart_Rotate_Data]";
/* get actual time as string */
//char timestampNow_char[12];
//timestampNow_char = Char_Timestamp_yyyymmdd(now());
/* convert to unsigned long */
unsigned long timestampNow = strtoul(Char_Timestamp_yyyymmdd(now()), NULL, 0);
char chartDirPath[10];
snprintf(chartDirPath, sizeof(chartDirPath), "%s%d", CHART_BASE_PATH, chartId);
/* https://github.com/cotestatnt/async-esp-fs-webserver/blob/master/src/AsyncFsWebServer.cpp */
File root = LittleFS.open(chartDirPath, "r");
File file = root.openNextFile();
while (file) {
if (!file.isDirectory()) {
/* https://cplusplus.com/reference/cstdlib/strtoul/ */
//TIMESCALE_DAY
//timestampFile = strtoul(timeStampNow_char, NULL, 0);
char timestampFile_char[12];
//timestampFile_char = file.name();
unsigned long timestampFile = strtoul(file.name(), NULL, 0);
#ifdef DEBUG
Log.verbose(F("%s timestampNow %u - timestampFile %u" CR), LogLoc, timestampNow, timestampFile);
#endif
}
file = root.openNextFile();
}
}

View file

@ -45,7 +45,8 @@ void Timer_3s() {
#endif
if(config.grow.dashboard.chartConfigured[0] == true) {
LFS_Chart_Log_Data(0);
LFS_Chart_Dirlist_Data(0);
//LFS_Chart_Dirlist_Data(0);
LFS_Chart_Rotate_Data(0);
}
}