Add human-readable UTC time alongside epoch in web UI and CSV

This commit is contained in:
2026-02-16 08:57:16 +01:00
parent 0a2e4e5a68
commit 4de1dda82b
2 changed files with 58 additions and 21 deletions

View File

@@ -39,6 +39,21 @@ static String format_date_utc(uint32_t ts_utc) {
return String(buf);
}
static String format_hms_utc(uint32_t ts_utc) {
if (ts_utc == 0) {
return "";
}
time_t t = static_cast<time_t>(ts_utc);
struct tm tm_utc;
gmtime_r(&t, &tm_utc);
char buf[16];
snprintf(buf, sizeof(buf), "%02d:%02d:%02d",
tm_utc.tm_hour,
tm_utc.tm_min,
tm_utc.tm_sec);
return String(buf);
}
void sd_logger_init() {
if (!ENABLE_SD_LOGGING) {
g_sd_ready = false;
@@ -87,11 +102,14 @@ void sd_logger_log_sample(const MeterData &data, bool include_error_text) {
}
if (new_file) {
f.println("ts_utc,p_w,p1_w,p2_w,p3_w,e_kwh,bat_v,bat_pct,rssi,snr,err_m,err_d,err_tx,err_last");
f.println("ts_utc,ts_hms_utc,p_w,p1_w,p2_w,p3_w,e_kwh,bat_v,bat_pct,rssi,snr,err_m,err_d,err_tx,err_last");
}
String ts_hms_utc = format_hms_utc(data.ts_utc);
f.print(data.ts_utc);
f.print(',');
f.print(ts_hms_utc);
f.print(',');
f.print(data.total_power_w, 1);
f.print(',');
f.print(data.phase_power_w[0], 1);