receiver: store CSVs by local date and keep UTC history fallback

This commit is contained in:
2026-02-18 01:34:47 +01:00
parent 6f359b11d3
commit 92ac7e8810
2 changed files with 27 additions and 9 deletions

View File

@@ -27,15 +27,15 @@ static bool ensure_dir(const String &path) {
return SD.mkdir(path);
}
static String format_date_utc(uint32_t ts_utc) {
static String format_date_local(uint32_t ts_utc) {
time_t t = static_cast<time_t>(ts_utc);
struct tm tm_utc;
gmtime_r(&t, &tm_utc);
struct tm tm_local;
localtime_r(&t, &tm_local);
char buf[16];
snprintf(buf, sizeof(buf), "%04d-%02d-%02d",
tm_utc.tm_year + 1900,
tm_utc.tm_mon + 1,
tm_utc.tm_mday);
tm_local.tm_year + 1900,
tm_local.tm_mon + 1,
tm_local.tm_mday);
return String(buf);
}
@@ -94,7 +94,7 @@ void sd_logger_log_sample(const MeterData &data, bool include_error_text) {
return;
}
String filename = sender_dir + "/" + format_date_utc(data.ts_utc) + ".csv";
String filename = sender_dir + "/" + format_date_local(data.ts_utc) + ".csv";
bool new_file = !SD.exists(filename);
File f = SD.open(filename, FILE_APPEND);
if (!f) {