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:
+19
-1
@@ -29,6 +29,8 @@ Telemetry tracks per-bell strike counts and thermal load to protect actuators fr
|
||||
| `esp_reset_reason_t getResetReason() const` | Returns the ESP32 reset reason captured once at `begin()`, via `esp_reset_reason()`. |
|
||||
| `bool isFaultReset() const` | Returns `true` if the captured reset reason indicates a fault: `ESP_RST_PANIC`, `ESP_RST_INT_WDT`, `ESP_RST_TASK_WDT`, `ESP_RST_WDT`, or `ESP_RST_BROWNOUT`. `false` for expected resets (power-on, software reset/OTA, deep sleep wake, etc). |
|
||||
| `String getResetReasonString() const` | Human-readable reset reason, e.g. `"PANIC"`, `"POWERON"`, `"TASK_WATCHDOG"`. |
|
||||
| `uint32_t getLifetimeBootCount() const` | NVS-backed count of every boot this device has ever done. The authoritative counter — see [Boot tracking](#boot-tracking) below for why this exists alongside two other, narrower counters. |
|
||||
| `const CrashReport& getCrashReport() const` | Coredump summary from the most recent crash, if one was found at `begin()`. `.available` is `false` when the last reset wasn't a crash, or no coredump was present for one that was. |
|
||||
|
||||
---
|
||||
|
||||
@@ -69,6 +71,8 @@ communication.setTelemetryReference(&telemetry);
|
||||
| `Logging` | Required | All log output |
|
||||
| FreeRTOS | Required | `xTaskCreatePinnedToCore`, `portMUX_TYPE` spinlock |
|
||||
| ArduinoJson | Required | JSON serialisation for SD persistence |
|
||||
| NVS (`nvs.h`) | Required | Lifetime boot counter (`vesper_boot` namespace) — works even without SD |
|
||||
| ESP-IDF coredump (`esp_core_dump.h`) | Required | Reads the crash coredump summary already written to the `coredump` flash partition by the panic handler. Requires `CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH` and a `coredump` partition table entry — both present by default in this project's `min_spiffs.csv` and precompiled Arduino-ESP32 core. No custom panic hook involved. |
|
||||
|
||||
---
|
||||
|
||||
@@ -86,7 +90,21 @@ communication.setTelemetryReference(&telemetry);
|
||||
|
||||
**Heat model.** The thermal model is a simple increment/decrement counter, not a physical model. One strike adds 1 unit of load; 1 unit decays per second. A bell with `maxLoad = 200` (the default) tolerates sustained rates up to ~200 strikes per second before triggering overload, which is far beyond any realistic bell schedule. The threshold is more useful as a runaway-loop guard than a true thermal limit. Adjust per-bell thresholds via `setBellMaxLoad()` if tighter protection is needed for a specific installation.
|
||||
|
||||
**Reset reason capture.** `resetReason` is read once at the very top of `begin()`, before anything else can crash again this boot. It's included in the boot log entry written by `logBootEvent()` (field `"reason"`) so it's available on SD even for offline devices. For online devices, `CommunicationRouter` reports it once, the first time MQTT connects after boot: fault reasons go to `vesper/{uid}/status/alerts` (via `publishAlert`), expected reasons go to `vesper/{uid}/status/info` (via `publishInfo`, event type `"boot_reason"`). See [CommunicationRouter](../Communication/CommunicationRouter/README.md).
|
||||
**Reset reason capture.** `resetReason` is read once at the very top of `begin()`, before anything else can crash again this boot. It's included in the boot log entry written by `logBootEvent()` (field `"reason"`) so it's available on SD even for offline devices. For online devices, `CommunicationRouter::reportBootOnce()` publishes a consolidated report the first time MQTT connects after boot — see [Boot tracking](#boot-tracking) and [CommunicationRouter](../Communication/CommunicationRouter/README.md).
|
||||
|
||||
### Boot tracking
|
||||
|
||||
There are three separate, intentionally-distinct boot/crash mechanisms in the firmware. They look similar and are easy to conflate — here's what each one is actually for:
|
||||
|
||||
| Mechanism | Storage | Scope | Survives SD failure? | Use it for |
|
||||
|---|---|---|---|---|
|
||||
| `Telemetry::getLifetimeBootCount()` | NVS, namespace `vesper_boot` | Whole device lifetime | Yes | **The authoritative answer to "how many times has this device rebooted, ever."** Used by `CommunicationRouter::reportBootOnce()` and exposed via `telemetry.get_metrics` / `system.get_telemetry` / `system.get_all`. |
|
||||
| `FirmwareValidator::getBootCount()` | NVS, namespace `fw_validator` | Boots since this firmware image was flashed (feeds rollback-safety logic) | Yes | Firmware-validation decisions only (`firmware.status`'s `boot_count`). Do not use this as a lifetime counter — it's scoped to the current OTA slot's validation window, not the device's history. |
|
||||
| `Telemetry::logBootEvent()` → `/telemetry_boot_log.json` | SD card, rotating array (last 200 entries) | Timestamped history of recent boots | **No** — silently produces no entry without an SD card or before NTP sync | Browsing recent boot history with timestamps (e.g. "show me the last 10 reboots and when"). Its own `total_boots` field is **not** a reliable counter — use `getLifetimeBootCount()` instead. |
|
||||
|
||||
**Coredump-based crash detail.** `captureCrashReport()` runs once at `begin()`, right after `initBootTracking()`. It calls `esp_core_dump_image_check()` — if the last reset left a coredump in the `coredump` flash partition (written automatically by the ESP-IDF panic handler; this is stock ESP-IDF behavior already enabled in this project, not something this firmware added), it reads the summary via `esp_core_dump_get_summary()` into `CrashReport` (faulting task name, program counter, Xtensa exception cause and faulting virtual address — the same information the serial monitor prints as a register dump at the moment of the crash, but retrievable in code after reboot). The dump is erased from flash immediately after reading (`esp_core_dump_image_erase()`) so it's reported exactly once, not re-sent on every subsequent boot.
|
||||
|
||||
This required no custom panic hook — `esp_core_dump_get_summary()` is a documented, "user mode" API safe to call from ordinary application code after boot; nothing runs inside the panic handler itself.
|
||||
|
||||
**Remote commands (via TelemetryHandler).** The following v2 commands are handled by `TelemetryHandler` and routed through `CommunicationRouter`:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user