Compare commits
4 commits
0a7e56f726
...
f6b9325baf
Author | SHA1 | Date | |
---|---|---|---|
f6b9325baf | |||
b81b7c34ac | |||
2e10d99bbc | |||
c9181afe87 |
4 changed files with 89 additions and 1 deletions
|
@ -517,6 +517,37 @@ String Str_Epoch2Date(unsigned long epochTime) {
|
|||
return dateStr;
|
||||
}
|
||||
|
||||
char* Char_Timestamp_yyyymmdd(const unsigned long timestamp) {
|
||||
/* char length should be 9 at the end */
|
||||
|
||||
char tmp_month[3];
|
||||
char tmp_day[3];
|
||||
char tmp_minute[3];
|
||||
static char tmp_timestamp[12];
|
||||
|
||||
if(month(timestamp) < 10) {
|
||||
snprintf(tmp_month, sizeof(tmp_month), "0%d", month(timestamp));
|
||||
} else {
|
||||
snprintf(tmp_month, sizeof(tmp_month), "%d", month(timestamp));
|
||||
}
|
||||
|
||||
if(day(timestamp) < 10) {
|
||||
snprintf(tmp_day, sizeof(tmp_day), "0%d", day(timestamp));
|
||||
} else {
|
||||
snprintf(tmp_day, sizeof(tmp_day), "%d", day(timestamp));
|
||||
}
|
||||
|
||||
if(minute(timestamp) < 10) {
|
||||
snprintf(tmp_minute, sizeof(tmp_minute), "0%d", minute(timestamp));
|
||||
} else {
|
||||
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);
|
||||
|
||||
return tmp_timestamp;
|
||||
}
|
||||
|
||||
|
||||
/* Those two functions should be in LittleFS file, but because dependency and lazyness */
|
||||
void Time2FS_Save() {
|
||||
|
|
|
@ -723,6 +723,60 @@ bool SaveConfig(bool writeToSerial = false) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/***************
|
||||
* Dashboard Chart LittleFS functions
|
||||
* Stuff for writing, rotating, deleting files
|
||||
*/
|
||||
|
||||
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[24]; //18
|
||||
char tmp_message[32];
|
||||
char tmp_floatChar[16]; // = "12.34";
|
||||
float tmp_float = Sensor_getCalibratedValue(config.grow.dashboard.chartSensor[chartId], config.grow.dashboard.chartRead[chartId]);
|
||||
unsigned long timeNow = now();
|
||||
|
||||
/* build full path - looks like /d/0_1/20250420 */
|
||||
snprintf(fullpath, sizeof(fullpath), "/chart/%d/%s", chartId, Char_Timestamp_yyyymmdd(timeNow));
|
||||
/* 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);
|
||||
|
||||
|
||||
|
||||
Log.notice(F("%s fullpath: %s, message: %s" CR), LogLoc, fullpath, tmp_message);
|
||||
|
||||
#ifdef ESP8266
|
||||
File file = LittleFS.open(fullpath, "a");
|
||||
#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();
|
||||
}
|
||||
|
||||
void LFS_Chart_Dirlist_Data() {
|
||||
const static char LogLoc[] PROGMEM = "[LittleFS:Chart_Dirlist_Data]";
|
||||
|
||||
}
|
||||
|
||||
///*
|
||||
//* ESP8266 functions
|
||||
//*/
|
||||
|
|
|
@ -43,7 +43,8 @@ void Timer_3s() {
|
|||
#ifdef DEBUG2
|
||||
Log.verbose(F("%s" CR), LogLoc);
|
||||
#endif
|
||||
|
||||
if(config.grow.dashboard.chartConfigured[0] == true)
|
||||
LFS_Chart_Log_Data(0);
|
||||
}
|
||||
|
||||
void Timer_5s() {
|
||||
|
@ -57,5 +58,6 @@ void TimeR_Init() {
|
|||
timer.setInterval(1000, Timer_Output);
|
||||
timer.setInterval(1000, Timer_Sensor);
|
||||
timer.setInterval(100, Timer_Control);
|
||||
timer.setInterval(30000, Timer_3s);
|
||||
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue