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:
@@ -2,11 +2,15 @@
|
||||
|
||||
#define TAG "Telemetry"
|
||||
#include <ArduinoJson.h>
|
||||
#include <cstring>
|
||||
|
||||
void Telemetry::begin() {
|
||||
resetReason = esp_reset_reason();
|
||||
LOG_INFO(TAG, "Reset reason: %s%s", getResetReasonString().c_str(), isFaultReset() ? " (FAULT)" : "");
|
||||
|
||||
initBootTracking();
|
||||
captureCrashReport();
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
strikeCounters[i] = 0;
|
||||
bellLoad[i] = 0;
|
||||
@@ -57,6 +61,58 @@ String Telemetry::getResetReasonString() const {
|
||||
}
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// BOOT TRACKING — lifetime counter + crash coredump summary
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
void Telemetry::initBootTracking() {
|
||||
// Separate NVS namespace from FirmwareValidator's "fw_validator" — this
|
||||
// counter tracks the device's whole lifetime, not boots-since-this-firmware-
|
||||
// image-was-flashed, so it must not share storage or reset semantics.
|
||||
esp_err_t err = nvs_open("vesper_boot", NVS_READWRITE, &_bootNvsHandle);
|
||||
if (err != ESP_OK) {
|
||||
LOG_ERROR(TAG, "Failed to open boot-tracking NVS namespace: %s", esp_err_to_name(err));
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t count = 0;
|
||||
nvs_get_u32(_bootNvsHandle, "lifetime_boots", &count); // defaults to 0 if key absent
|
||||
count++;
|
||||
nvs_set_u32(_bootNvsHandle, "lifetime_boots", count);
|
||||
nvs_commit(_bootNvsHandle);
|
||||
|
||||
lifetimeBootCount = count;
|
||||
LOG_INFO(TAG, "Lifetime boot count: %lu", lifetimeBootCount);
|
||||
}
|
||||
|
||||
void Telemetry::captureCrashReport() {
|
||||
if (esp_core_dump_image_check() != ESP_OK) {
|
||||
return; // no coredump present — expected on a non-crash reset
|
||||
}
|
||||
|
||||
esp_core_dump_summary_t summary;
|
||||
if (esp_core_dump_get_summary(&summary) != ESP_OK) {
|
||||
LOG_WARNING(TAG, "Coredump present but summary read failed");
|
||||
esp_core_dump_image_erase(); // don't leave a dump we can't parse sitting in flash
|
||||
return;
|
||||
}
|
||||
|
||||
crashReport.available = true;
|
||||
strncpy(crashReport.taskName, summary.exc_task, sizeof(crashReport.taskName) - 1);
|
||||
crashReport.taskName[sizeof(crashReport.taskName) - 1] = '\0';
|
||||
crashReport.pc = summary.exc_pc;
|
||||
crashReport.excCause = summary.ex_info.exc_cause;
|
||||
crashReport.excVaddr = summary.ex_info.exc_vaddr;
|
||||
|
||||
LOG_WARNING(TAG, "Crash coredump found — task '%s', PC 0x%08lX, cause %lu, vaddr 0x%08lX",
|
||||
crashReport.taskName, crashReport.pc, crashReport.excCause, crashReport.excVaddr);
|
||||
|
||||
// Erase immediately after reading — this is a one-shot report. Without this,
|
||||
// the same coredump would be re-reported on every subsequent boot until the
|
||||
// next crash overwrites it.
|
||||
esp_core_dump_image_erase();
|
||||
}
|
||||
|
||||
void Telemetry::setPlayerReference(bool* isPlayingPtr) {
|
||||
playerIsPlayingPtr = isPlayingPtr;
|
||||
LOG_DEBUG(TAG, "Player reference set");
|
||||
|
||||
Reference in New Issue
Block a user