feat(MQTTDriver,SystemHandler): free_heap on heartbeat + ping RTT timestamp echo
Requested by the console-side agent building a device Health tab (RSSI, ping latency, free heap, restart timeline graphs). Both changes are additive and backward-compatible. publishHeartbeat() now includes free_heap (ESP.getFreeHeap()) on the existing 30s heartbeat, alongside rssi — previously free heap was only visible once per boot via boot_report, a single point rather than a trend. handlePing() previously built a JsonDocument and never used it — ping was a pure ack. It now echoes back an optional caller-supplied "ts" (epoch-millis) unchanged, plus device_uptime_ms, so the caller can compute round-trip latency as (time of receipt) - ts without needing synchronized clocks. ts is optional on both request and response, so existing callers doing a plain liveness check are unaffected. Left the existing #if HAS_RTC scoping on SystemHandler.cpp untouched, per the request — ping remains RTC-variant-only. Verified: pio run on vesper-std-v1 and agnus-v1 (confirms the HAS_RTC scoping around SystemHandler.cpp wasn't disturbed). Documented in feature-catalog.md F-054, MQTTDriver/README.md, and Communication/Handlers/README.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -416,6 +416,10 @@ void MQTTDriver::publishHeartbeat() {
|
||||
// WiFi signal strength
|
||||
payload["rssi"] = WiFi.RSSI();
|
||||
|
||||
// Free heap (bytes) — lets the console chart heap trend over time instead of
|
||||
// only seeing one sample per boot (via boot_report)
|
||||
payload["free_heap"] = ESP.getFreeHeap();
|
||||
|
||||
// Serialize to string
|
||||
String heartbeatMessage;
|
||||
serializeJson(doc, heartbeatMessage);
|
||||
|
||||
@@ -62,7 +62,7 @@ Reconnect attempts are reset to 0 on a successful connection or a new `onNetwork
|
||||
|
||||
## Heartbeat
|
||||
|
||||
Once connected, a heartbeat is published immediately and then every 30 seconds to `vesper/{uid}/status/heartbeat` with `retain = true`. Heartbeat payload includes `device_id`, `firmware_version`, `ip_address`, `gateway`, `uptime_ms`, `rssi`, and an uptime string. The heartbeat timer is stopped on disconnect and restarted on reconnect.
|
||||
Once connected, a heartbeat is published immediately and then every 30 seconds to `vesper/{uid}/status/heartbeat` with `retain = true`. Heartbeat payload includes `device_id`, `firmware_version`, `ip_address`, `gateway`, `uptime_ms`, `rssi`, `free_heap` (bytes, via `ESP.getFreeHeap()` — added so a console can chart heap trend over time from the same 30s cadence as RSSI, rather than only seeing one heap sample per boot via `boot_report`), and an uptime string. The heartbeat timer is stopped on disconnect and restarted on reconnect.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -81,13 +81,13 @@ Full control over the Timekeeper clock subsystem and its persisted configuration
|
||||
|
||||
## SystemHandler
|
||||
|
||||
General device management. `identify` is WebSocket-only. `system.restart` defers the actual reboot to a FreeRTOS task so the reply reaches the client first.
|
||||
General device management. `identify` is WebSocket-only. `system.restart` defers the actual reboot to a FreeRTOS task so the reply reaches the client first. `ping`/`identify`/all `system.*` commands here are wrapped in `#if HAS_RTC` — this handler does not exist on non-RTC variants (e.g. `agnus_mini`).
|
||||
|
||||
**Commands:**
|
||||
|
||||
| Command | Key contents | Description |
|
||||
|---------|-------------|-------------|
|
||||
| `ping` | — | Returns `{ "status": "SUCCESS", "type": "pong" }`. |
|
||||
| `ping` | `{ "ts": 1752600000123 }` (optional) | Echoes `ts` back unchanged plus `device_uptime_ms` (`millis()`), so the caller can compute round-trip time as `(time of response receipt) − ts` without needing synchronized clocks. Returns `{ "status": "SUCCESS", "type": "pong", "data": { "ts": 1752600000123, "device_uptime_ms": 184213 } }`. `ts` is omitted from the response if the caller didn't send one — fully backward compatible with callers that just want a liveness ack. |
|
||||
| `identify` | `{ "device_type": "master"\|"secondary" }` | WebSocket only. Classifies the calling client in `ClientManager`. |
|
||||
| `system.status` | — | Player status, time elapsed, projected run time, 16 strike counters. |
|
||||
| `system.get_time` | — | Local and UTC timestamps, broken-down time fields, `rtc_available`. |
|
||||
|
||||
@@ -54,7 +54,14 @@ CommandResult SystemHandler::execute(const CommandEnvelope& envelope) {
|
||||
CommandResult SystemHandler::handlePing(const CommandEnvelope& e) {
|
||||
JsonDocument doc;
|
||||
doc["type"] = "pong";
|
||||
return CommandResult::ok("pong");
|
||||
// Echo caller's timestamp back unchanged so the caller can compute RTT
|
||||
// as (time_received - contents.ts) without needing symmetric clocks.
|
||||
// uint64_t: epoch-millis (e.g. 1752600000123) overflows uint32_t.
|
||||
if (e.contents["ts"].is<uint64_t>()) {
|
||||
doc["ts"] = e.contents["ts"];
|
||||
}
|
||||
doc["device_uptime_ms"] = millis();
|
||||
return CommandResult::ok("pong", doc);
|
||||
}
|
||||
|
||||
CommandResult SystemHandler::handleIdentify(const CommandEnvelope& e) {
|
||||
|
||||
Reference in New Issue
Block a user