feat(Telemetry): expose SD boot history via telemetry.get_boot_history, fix counter drift
The SD-based boot history (logBootEvent() -> /telemetry_boot_log.json)
was write-only: nothing in the firmware ever read it back, and its
"boot" field was a locally-tallied counter (only advanced on the
NTP-gated write path) that could silently drift from the new
lifetime_boot_count added in the previous commit.
- logBootEvent() now stamps each entry with getLifetimeBootCount()
directly instead of its own total_boots tally, so the SD history's
"boot" numbers always agree with what MQTT boot_report and
telemetry.get_metrics/system.get_telemetry report. The old
total_boots JSON key is no longer written (old files may still have
it; current firmware ignores it).
- Each entry now also carries crash detail (task/pc/exc_cause/
exc_vaddr) when a coredump was captured for that boot, same shape
as the MQTT boot_report's crash object.
- New Telemetry::getBootHistory() + telemetry.get_boot_history command
actually exposes the file: optional {"limit": N} (clamped 1-200),
returns {"count", "boots": [...]}. Returns an error response (not a
crash or empty success) when there's no SD/FileManager or the file
doesn't exist yet — expected on agnus (no-SD) variants or before a
device's first NTP sync.
Full request/response contract documented in Telemetry's README and
feature-catalog.md F-053, written for direct consumption by whoever
builds the console-side retrieval UI.
Verified: pio run on vesper-std-v1 and agnus-v1 (no-SD variant).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,8 @@ std::vector<String> TelemetryHandler::commands() const {
|
||||
return {
|
||||
"telemetry.get_strikes", "telemetry.reset_strikes", "telemetry.get_loads",
|
||||
"telemetry.set_max_loads", "telemetry.set_guard_enabled",
|
||||
"telemetry.get_metrics", "telemetry.reset_metrics"
|
||||
"telemetry.get_metrics", "telemetry.reset_metrics",
|
||||
"telemetry.get_boot_history"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,6 +23,7 @@ CommandResult TelemetryHandler::execute(const CommandEnvelope& envelope) {
|
||||
if (envelope.command == "telemetry.set_guard_enabled") return handleSetGuardEnabled(envelope);
|
||||
if (envelope.command == "telemetry.get_metrics") return handleGetMetrics(envelope);
|
||||
if (envelope.command == "telemetry.reset_metrics") return handleResetMetrics(envelope);
|
||||
if (envelope.command == "telemetry.get_boot_history") return handleGetBootHistory(envelope);
|
||||
return CommandResult::err(envelope.command, "Unknown telemetry command");
|
||||
}
|
||||
|
||||
@@ -108,3 +110,21 @@ CommandResult TelemetryHandler::handleResetMetrics(const CommandEnvelope& e) {
|
||||
LOG_WARNING(TAG, "Telemetry metrics reset by command");
|
||||
return CommandResult::ok("telemetry.reset_metrics", "Lifetime runtime and playback count reset to zero");
|
||||
}
|
||||
|
||||
CommandResult TelemetryHandler::handleGetBootHistory(const CommandEnvelope& e) {
|
||||
// Optional "limit" — defaults to the full 200-entry cap. Clamped to
|
||||
// [1, BOOT_LOG_MAX_ENTRIES] so a bad value can't return zero entries
|
||||
// or force reading past what's actually stored.
|
||||
uint16_t limit = BOOT_LOG_MAX_ENTRIES;
|
||||
if (e.contents["limit"].is<uint16_t>()) {
|
||||
uint16_t requested = e.contents["limit"].as<uint16_t>();
|
||||
limit = (requested == 0) ? 1 : (requested > BOOT_LOG_MAX_ENTRIES ? BOOT_LOG_MAX_ENTRIES : requested);
|
||||
}
|
||||
|
||||
JsonDocument doc;
|
||||
if (!_telemetry.getBootHistory(doc, limit)) {
|
||||
return CommandResult::err("telemetry.get_boot_history",
|
||||
"No boot history available (no SD card, or no boot has completed NTP sync yet)");
|
||||
}
|
||||
return CommandResult::ok("telemetry.get_boot_history", doc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user