chart data log function
This commit is contained in:
parent
b81b7c34ac
commit
f6b9325baf
2 changed files with 39 additions and 25 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() {
|
||||
|
|
|
@ -732,40 +732,18 @@ bool SaveConfig(bool writeToSerial = false) {
|
|||
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[19]; //18
|
||||
//char timestamp[6];
|
||||
char tmp_month[3];
|
||||
char tmp_day[3];
|
||||
char tmp_minute[3];
|
||||
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();
|
||||
|
||||
if(month() < 10) {
|
||||
snprintf(tmp_month, sizeof(tmp_month), "0%d", month());
|
||||
} else {
|
||||
snprintf(tmp_month, sizeof(tmp_month), "%d", month());
|
||||
}
|
||||
|
||||
if(day() < 10) {
|
||||
snprintf(tmp_day, sizeof(tmp_day), "0%d", day());
|
||||
} else {
|
||||
snprintf(tmp_day, sizeof(tmp_day), "%d", day());
|
||||
}
|
||||
|
||||
if(minute() < 10) {
|
||||
snprintf(tmp_minute, sizeof(tmp_minute), "0%d", minute());
|
||||
} else {
|
||||
snprintf(tmp_minute, sizeof(tmp_minute), "%d", minute());
|
||||
}
|
||||
|
||||
/* build full path - looks like /d/0_1/20250420 */
|
||||
snprintf(fullpath, sizeof(fullpath), "/chart/%d/%d%s%s_%s", chartId, year(), tmp_month, tmp_day, tmp_minute);
|
||||
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\n", timeNow, tmp_floatChar);
|
||||
snprintf(tmp_message, sizeof(tmp_message), "%lu;%s", timeNow, tmp_floatChar);
|
||||
|
||||
|
||||
|
||||
|
@ -794,6 +772,11 @@ void LFS_Chart_Log_Data(const byte chartId) {
|
|||
file.close();
|
||||
}
|
||||
|
||||
void LFS_Chart_Dirlist_Data() {
|
||||
const static char LogLoc[] PROGMEM = "[LittleFS:Chart_Dirlist_Data]";
|
||||
|
||||
}
|
||||
|
||||
///*
|
||||
//* ESP8266 functions
|
||||
//*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue