wip first steps for chart data logging

This commit is contained in:
DeltaLima 2025-04-08 05:38:02 +02:00
parent 2e10d99bbc
commit b81b7c34ac
3 changed files with 30 additions and 28 deletions

View file

@ -729,17 +729,17 @@ bool SaveConfig(bool writeToSerial = false) {
* Stuff for writing, rotating, deleting files
*/
void Chart_Write_Data(const byte sensorId, const byte readId) {
const static char LogLoc[] PROGMEM = "[LittleFS:Chart_Write_Data]";
void LFS_Chart_Log_Data(const byte chartId) {
const static char LogLoc[] PROGMEM = "[LittleFS:Chart_Log_Data]";
/* sensor data is in directory /d/ */
char fullpath[18]; //18
char timestamp[6];
char fullpath[19]; //18
//char timestamp[6];
char tmp_month[3];
char tmp_day[3];
char tmp_minute[3];
char tmp_message[32];
char tmp_floatChar[16]; // = "12.34";
float tmp_float = Sensor_getCalibratedValue(sensorId, readId);
float tmp_float = Sensor_getCalibratedValue(config.grow.dashboard.chartSensor[chartId], config.grow.dashboard.chartRead[chartId]);
unsigned long timeNow = now();
if(month() < 10) {
@ -761,37 +761,37 @@ void Chart_Write_Data(const byte sensorId, const byte readId) {
}
/* build full path - looks like /d/0_1/20250420 */
snprintf(fullpath, sizeof(fullpath), "/d/%d_%d/%d%s%s_%s", sensorId, readId, year(), tmp_month, tmp_day, tmp_minute);
snprintf(fullpath, sizeof(fullpath), "/chart/%d/%d%s%s_%s", chartId, year(), tmp_month, tmp_day, tmp_minute);
/* build message
* https://forum.arduino.cc/t/sprintf-a-float-number/1013193/5 */
dtostrf(tmp_float, 2, 2, tmp_floatChar);
snprintf(tmp_message, sizeof(tmp_message), "%lu;%s", timeNow, tmp_floatChar);
snprintf(tmp_message, sizeof(tmp_message), "%lu;%s\n", timeNow, tmp_floatChar);
Log.notice(F("%s fullpath: %s, message: %s" CR), LogLoc, fullpath, tmp_message);
//#ifdef ESP8266
//File file = LittleFS.open(fullpath, "a");
//#endif
#ifdef ESP8266
File file = LittleFS.open(fullpath, "a");
#endif
//#ifdef ESP32
//fs::FS &fs = LittleFS;
//File file = fs.open(fullpath, FILE_APPEND);
//#endif
#ifdef ESP32
fs::FS &fs = LittleFS;
File file = fs.open(fullpath, FILE_APPEND);
#endif
//if (!file) {
//Log.error(F("%s Failed to open file for appending %s" CR), LogLoc, fullpath);
//return;
//}
//if (file.print(tmp_message)) {
//#ifdef DEBUG
//Log.notice(F("%s File appended %s" CR), LogLoc, fullpath);
//#endif
//} else {
//Log.error(F("%s Failed to append file %s" CR), LogLoc, fullpath);
//}
//file.close();
if (!file) {
Log.error(F("%s Failed to open file for appending %s" CR), LogLoc, fullpath);
return;
}
if (file.print(tmp_message)) {
#ifdef DEBUG
Log.notice(F("%s File appended %s" CR), LogLoc, fullpath);
#endif
} else {
Log.error(F("%s Failed to append file %s" CR), LogLoc, fullpath);
}
file.close();
}
///*

View file

@ -43,7 +43,8 @@ void Timer_3s() {
#ifdef DEBUG2
Log.verbose(F("%s" CR), LogLoc);
#endif
Chart_Write_Data(config.grow.dashboard.chartSensor[0], config.grow.dashboard.chartRead[0]);
if(config.grow.dashboard.chartConfigured[0] == true)
LFS_Chart_Log_Data(0);
}
void Timer_5s() {
@ -57,6 +58,6 @@ void TimeR_Init() {
timer.setInterval(1000, Timer_Output);
timer.setInterval(1000, Timer_Sensor);
timer.setInterval(100, Timer_Control);
timer.setInterval(3000, Timer_3s);
timer.setInterval(30000, Timer_3s);
}

View file

@ -107,6 +107,7 @@ void Webserver_Init() {
/* DEBUG only - offer config for direct download */
#ifdef DEBUG
webserver.serveStatic(CANGROW_CFG, LittleFS, CANGROW_CFG);
webserver.serveStatic("/d/1_1/20250408_1", LittleFS, "/d/1_1/20250408_1");
#endif
/* 404 Error page */