feat(Telemetry,CommunicationRouter): lifetime boot counter + coredump crash detail over MQTT
Investigating the F-051 TelemetryTask crash surfaced two gaps: the console only ever saw a coarse "Device reset due to fault: PANIC" alert, none of the serial monitor's task-name/register detail; and there was no automatic per-boot report a console could use to count reboots without polling. Adds Telemetry::getLifetimeBootCount() — a new NVS-backed counter (namespace "vesper_boot") that increments once per boot, works on every board variant (SD or not), and is reliable regardless of NTP sync status. Deliberately kept separate from FirmwareValidator's existing NVS boot_count (scoped to boots-since-this-OTA-slot-was- flashed, feeds rollback-safety retry logic — left untouched) and Telemetry's existing SD-based total_boots (repositioned as history- only; unreliable as a counter since it's SD/NTP-dependent). Adds Telemetry::captureCrashReport(), which reads the ESP-IDF coredump summary (esp_core_dump_get_summary) once at begin(). The coredump partition and CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH were already present/enabled in this project's stock min_spiffs.csv and precompiled Arduino-ESP32 core — no partition table or SDK config change needed. This is the official "user mode" retrieval API, safe to call from ordinary application code after boot; no custom panic hook, nothing runs inside the panic handler itself. Extracts the faulting task name, PC, and exception cause/vaddr, then erases the dump so it's reported exactly once. CommunicationRouter::reportBootReasonOnce() (renamed reportBootOnce()) now always publishes a consolidated "boot_report" event to status/info on first MQTT connect — boot count, reset reason, free heap, and crash detail when available — alongside the existing fault-triggered status/alerts WARNING (unchanged). lifetime_boot_count also added to telemetry.get_metrics, system.get_telemetry, and system.get_all for on-demand polling. Verified: pio run on both vesper-std-v1 and agnus-v1 (no-SD variant). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -130,7 +130,7 @@ void CommunicationRouter::begin() {
|
||||
Logging::setSubsystemMqttLevel("OTAManager", Logging::INFO); // update events important
|
||||
|
||||
_mqttClient.setOnConnectCallback([this](bool /*sessionPresent*/) {
|
||||
reportBootReasonOnce();
|
||||
reportBootOnce();
|
||||
});
|
||||
|
||||
LOG_INFO(TAG, "MQTT transport initialised");
|
||||
@@ -500,21 +500,43 @@ void CommunicationRouter::publishAlert(const String& subsystem, const String& ne
|
||||
LOG_DEBUG(TAG, "Alert published: %s → %s", subsystem.c_str(), newState.c_str());
|
||||
}
|
||||
|
||||
void CommunicationRouter::reportBootReasonOnce() {
|
||||
void CommunicationRouter::reportBootOnce() {
|
||||
if (_bootReasonReported || !_telemetry) return;
|
||||
_bootReasonReported = true;
|
||||
|
||||
String reason = _telemetry->getResetReasonString();
|
||||
bool isFault = _telemetry->isFaultReset();
|
||||
|
||||
if (_telemetry->isFaultReset()) {
|
||||
// Existing fault alert — unchanged trigger condition and topic, so consoles
|
||||
// already handling this WARNING keep working as-is.
|
||||
if (isFault) {
|
||||
publishAlert("System", "WARNING", "Device reset due to fault: " + reason);
|
||||
LOG_WARNING(TAG, "Fault reset reported: %s", reason.c_str());
|
||||
} else {
|
||||
JsonDocument payload;
|
||||
payload["reason"] = reason;
|
||||
publishInfo("boot_reason", payload);
|
||||
LOG_INFO(TAG, "Boot reason reported: %s", reason.c_str());
|
||||
}
|
||||
|
||||
// Consolidated boot report — always published, fault or not. Single place
|
||||
// a console needs to watch for "device rebooted" plus everything useful
|
||||
// about why: lifetime boot count, reset reason, and (if the last reset was
|
||||
// a crash with a coredump available) the faulting task/PC/exception detail.
|
||||
JsonDocument payload;
|
||||
payload["boot_count"] = _telemetry->getLifetimeBootCount();
|
||||
payload["reset_reason"] = reason;
|
||||
payload["is_fault"] = isFault;
|
||||
payload["free_heap"] = (uint32_t)ESP.getFreeHeap();
|
||||
|
||||
const CrashReport& crash = _telemetry->getCrashReport();
|
||||
if (crash.available) {
|
||||
JsonObject crashObj = payload["crash"].to<JsonObject>();
|
||||
crashObj["task"] = crash.taskName;
|
||||
crashObj["pc"] = crash.pc;
|
||||
crashObj["exc_cause"] = crash.excCause;
|
||||
crashObj["exc_vaddr"] = crash.excVaddr;
|
||||
}
|
||||
|
||||
publishInfo("boot_report", payload);
|
||||
LOG_INFO(TAG, "Boot report published: count=%lu reason=%s%s",
|
||||
_telemetry->getLifetimeBootCount(), reason.c_str(),
|
||||
crash.available ? " (crash detail included)" : "");
|
||||
}
|
||||
|
||||
void CommunicationRouter::publishInfo(const String& type, const JsonDocument& payload) {
|
||||
|
||||
Reference in New Issue
Block a user