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:
@@ -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