Add web last-update timestamp and debug auto-reboot

This commit is contained in:
2026-02-13 01:51:31 +01:00
parent 3a1de36b75
commit 9d5f5ed513
2 changed files with 105 additions and 4 deletions

View File

@@ -57,6 +57,32 @@ static HistoryJob g_history = {};
static constexpr size_t SD_LIST_MAX_FILES = 200;
static constexpr size_t SD_DOWNLOAD_MAX_PATH = 160;
static String format_utc_timestamp(uint32_t ts_utc) {
if (ts_utc == 0) {
return "n/a";
}
time_t t = static_cast<time_t>(ts_utc);
struct tm tm_utc;
gmtime_r(&t, &tm_utc);
char buf[32];
snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d UTC",
tm_utc.tm_year + 1900,
tm_utc.tm_mon + 1,
tm_utc.tm_mday,
tm_utc.tm_hour,
tm_utc.tm_min,
tm_utc.tm_sec);
return String(buf);
}
static uint32_t timestamp_age_seconds(uint32_t ts_utc) {
uint32_t now_utc = time_get_utc();
if (ts_utc == 0 || now_utc < ts_utc) {
return 0;
}
return now_utc - ts_utc;
}
static int32_t round_power_w(float value) {
if (isnan(value)) {
return 0;
@@ -374,6 +400,11 @@ static String render_sender_block(const SenderStatus &status) {
if (!status.has_data) {
s += "No data";
} else {
s += "Last update: " + format_utc_timestamp(status.last_update_ts_utc);
if (time_is_synced()) {
s += " (" + String(timestamp_age_seconds(status.last_update_ts_utc)) + "s ago)";
}
s += "<br>";
s += "Energy: " + String(status.last_data.energy_total_kwh, 2) + " kWh<br>";
s += "Power: " + String(round_power_w(status.last_data.total_power_w)) + " W<br>";
s += "P1/P2/P3: " + String(round_power_w(status.last_data.phase_power_w[0])) + " / " +