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:
@@ -61,6 +61,7 @@ Every feature — user-facing or significant internal mechanism — is listed he
|
||||
| F-049 | `firmware.status` rollback safety-net diagnostics (retry/failure counts, backup partition) | v2.1.2 | Stable |
|
||||
| F-050 | SD log lines prefixed with wall-clock date/time + uptime | v2.1.2 | Stable |
|
||||
| F-051 | Fix: TelemetryTask/HealthMonitor stack overflow — stack bump + deferred MQTT/SD logging queue | v2.0.3 | Stable |
|
||||
| F-052 | Consolidated lifetime boot counter + coredump crash detail, published automatically over MQTT | v2.1.3 | Stable |
|
||||
|
||||
---
|
||||
|
||||
@@ -460,7 +461,7 @@ New commands added to `TelemetryHandler`:
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `telemetry.get_metrics` | Returns `lifetime_runtime_seconds`, `session_runtime_seconds`, `total_playbacks`, `guard_enabled` |
|
||||
| `telemetry.get_metrics` | Returns `lifetime_runtime_seconds`, `session_runtime_seconds`, `total_playbacks`, `guard_enabled`, `lifetime_boot_count` (F-052) |
|
||||
| `telemetry.reset_metrics` | Resets lifetime runtime and playback count to zero (persisted) |
|
||||
|
||||
Subsystem: `src/Communication/Handlers/TelemetryHandler/`
|
||||
@@ -717,3 +718,47 @@ Implemented in `src/Logging/Logging.hpp` / `Logging.cpp`:
|
||||
RAM impact verified negligible via `pio run` (62980 vs. 62956 bytes static RAM; the 4096B task stack is allocated at runtime only if MQTT or SD logging is actually enabled).
|
||||
|
||||
Subsystem: `src/Logging/Logging.hpp`, `src/Logging/Logging.cpp`
|
||||
|
||||
---
|
||||
|
||||
### F-052 — Consolidated lifetime boot counter + coredump crash detail, published automatically over MQTT
|
||||
|
||||
**Motivation:** Investigating the F-051 crash surfaced a gap — the console only ever saw `"Device reset due to fault: PANIC"`, a coarse `esp_reset_reason()` string, with none of the detail the serial monitor showed (faulting task name, program counter, register dump). Separately, there was no automatic per-boot report a console could use to count reboots ("did this device restart 50 times today?") without polling — the two existing boot counters (`FirmwareValidator`'s NVS `boot_count` and `Telemetry`'s SD-based `total_boots`) were both unsuited to that job for different reasons (see table below).
|
||||
|
||||
**Three boot/crash mechanisms now coexist, deliberately kept separate:**
|
||||
|
||||
| Mechanism | Storage | Scope | Survives SD failure? |
|
||||
|---|---|---|---|
|
||||
| `Telemetry::getLifetimeBootCount()` — **new, this feature** | NVS, namespace `vesper_boot` | Whole device lifetime | Yes |
|
||||
| `FirmwareValidator::getBootCount()` — pre-existing, unchanged | NVS, namespace `fw_validator` | Boots since this firmware image was flashed (rollback-safety bookkeeping) | Yes |
|
||||
| `Telemetry::logBootEvent()` → SD `/telemetry_boot_log.json` — pre-existing, unchanged | SD card, rotating array (200 entries) | Timestamped history of recent boots | No — silently empty without SD or before NTP sync |
|
||||
|
||||
`FirmwareValidator`'s counter was deliberately left untouched rather than repurposed — it's load-bearing for startup/runtime validation retry logic and scoped to "since this OTA slot was flashed," not the device's lifetime. The SD-based log is repositioned as a *history* (useful for browsing recent boots with timestamps), not a counter — its `total_boots` field was never reliable as one (no-SD `agnus` variants get nothing from it, and it's silently skipped before NTP sync).
|
||||
|
||||
**Coredump-based crash detail (`Telemetry::captureCrashReport()`):** ESP-IDF's panic handler already writes a coredump to flash on every crash — this project's stock `min_spiffs.csv` partition table already reserves a 64KB `coredump` partition, and the precompiled Arduino-ESP32 core already has `CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH` enabled. Neither needed to change. `captureCrashReport()` calls the official, documented "user mode" retrieval API (`esp_core_dump_image_check()` + `esp_core_dump_get_summary()`) once at `begin()` — no custom panic hook, nothing runs inside the panic handler itself, so there's no risk to the crash path. If a coredump is present, it extracts the faulting task name, program counter, Xtensa exception cause, and faulting virtual address into a `CrashReport` struct, then erases the coredump from flash (`esp_core_dump_image_erase()`) so it's reported exactly once, not re-sent on every subsequent boot.
|
||||
|
||||
A custom RTC-noinit-memory panic hook was considered and rejected — the coredump API already gives strictly more detail (task name + PC + backtrace vs. just a reason string) with less risk (no code runs during the crash itself), for free, since the partition and SDK support already existed.
|
||||
|
||||
**MQTT reporting (`CommunicationRouter::reportBootOnce()`, renamed from `reportBootReasonOnce()`):** fires once per boot, on first MQTT connect. Fault resets still additionally publish the existing `status/alerts` WARNING (unchanged trigger/topic). A new consolidated `boot_report` event is **always** published to `vesper/{uid}/status/info`, fault or not:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "boot_report",
|
||||
"boot_count": 47,
|
||||
"reset_reason": "PANIC",
|
||||
"is_fault": true,
|
||||
"free_heap": 187234,
|
||||
"crash": {
|
||||
"task": "TelemetryTask",
|
||||
"pc": 1074111832,
|
||||
"exc_cause": 1,
|
||||
"exc_vaddr": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `crash` object is present only when `CrashReport::available` is true (a coredump was actually found — e.g. absent on a brownout reset, which doesn't produce one).
|
||||
|
||||
**On-demand access:** `lifetime_boot_count` was also added to `telemetry.get_metrics`, `system.get_telemetry`, and `system.get_all` responses, so a console can poll the same counter without waiting for the next reboot.
|
||||
|
||||
Subsystem: `src/Telemetry/Telemetry.hpp`, `src/Telemetry/Telemetry.cpp`, `src/Communication/CommunicationRouter/CommunicationRouter.cpp`, `src/Communication/Handlers/TelemetryHandler/TelemetryHandler.cpp`, `src/Communication/Handlers/SystemHandler/SystemHandler.cpp`
|
||||
|
||||
Reference in New Issue
Block a user