feat(Telemetry,Networking,OTAManager,CommunicationRouter): diagnostics report — CPU temp, WiFi reconnects, OTA state, stack high-water mark
Console requested four more Health-tab metrics beyond F-054's free_heap/ping work. None needed 30s heartbeat freshness, so this adds a separate low-frequency report instead of growing the heartbeat further: published every 5 min to status/info (diagnostics_report) and queryable on-demand via a new telemetry.get_diagnostics command. Only CPU temperature needs local sampling (15s, via a min/max/avg RunningStats accumulator on Telemetry) — a thermal spike could occur and subside entirely within a 5-minute gap. The other three fields are monotonic/self-tracking (WiFi reconnect counter, FreeRTOS's own stack high-water mark, rarely-changing OTA state) so a single read at report time loses no information. Verified: pio run on all four board variants.
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
#include "TelemetryHandler.hpp"
|
||||
#include "../../../Telemetry/Telemetry.hpp"
|
||||
#include "../../../OTAManager/OTAManager.hpp"
|
||||
#include "../../../Networking/Networking.hpp"
|
||||
#include "../../../Logging/Logging.hpp"
|
||||
|
||||
#define TAG "TelemetryHandler"
|
||||
|
||||
TelemetryHandler::TelemetryHandler(Telemetry& telemetry) : _telemetry(telemetry) {}
|
||||
TelemetryHandler::TelemetryHandler(Telemetry& telemetry, OTAManager& otaManager, Networking& networking)
|
||||
: _telemetry(telemetry), _otaManager(otaManager), _networking(networking) {}
|
||||
|
||||
std::vector<String> TelemetryHandler::commands() const {
|
||||
return {
|
||||
"telemetry.get_strikes", "telemetry.reset_strikes", "telemetry.get_loads",
|
||||
"telemetry.set_max_loads", "telemetry.set_guard_enabled",
|
||||
"telemetry.get_metrics", "telemetry.reset_metrics",
|
||||
"telemetry.get_boot_history"
|
||||
"telemetry.get_boot_history", "telemetry.get_diagnostics"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -24,6 +27,7 @@ CommandResult TelemetryHandler::execute(const CommandEnvelope& envelope) {
|
||||
if (envelope.command == "telemetry.get_metrics") return handleGetMetrics(envelope);
|
||||
if (envelope.command == "telemetry.reset_metrics") return handleResetMetrics(envelope);
|
||||
if (envelope.command == "telemetry.get_boot_history") return handleGetBootHistory(envelope);
|
||||
if (envelope.command == "telemetry.get_diagnostics") return handleGetDiagnostics(envelope);
|
||||
return CommandResult::err(envelope.command, "Unknown telemetry command");
|
||||
}
|
||||
|
||||
@@ -128,3 +132,33 @@ CommandResult TelemetryHandler::handleGetBootHistory(const CommandEnvelope& e) {
|
||||
}
|
||||
return CommandResult::ok("telemetry.get_boot_history", doc);
|
||||
}
|
||||
|
||||
CommandResult TelemetryHandler::handleGetDiagnostics(const CommandEnvelope& e) {
|
||||
// On-demand mirror of CommunicationRouter::reportDiagnosticsIfDue()'s
|
||||
// periodic diagnostics_report — same fields, same shape. Deliberately
|
||||
// does NOT reset the temperature accumulator (unlike the periodic
|
||||
// report) — this is a peek, not a consuming read, so the next scheduled
|
||||
// 5-minute report still sees the full sampling window.
|
||||
JsonDocument doc;
|
||||
|
||||
_telemetry.writeTemperatureStats(doc);
|
||||
|
||||
JsonObject wifiObj = doc["wifi_reconnects"].to<JsonObject>();
|
||||
wifiObj["lifetime_count"] = _networking.getReconnectCount();
|
||||
wifiObj["last_reason"] = _networking.getLastDisconnectReason();
|
||||
wifiObj["last_at_uptime_ms"] = _networking.getLastDisconnectUptimeMs();
|
||||
|
||||
JsonObject otaObj = doc["ota"].to<JsonObject>();
|
||||
otaObj["current_version"] = _otaManager.getCurrentVersion().toString();
|
||||
otaObj["update_available"] = _otaManager.isUpdateAvailable();
|
||||
if (_otaManager.isUpdateAvailable()) {
|
||||
otaObj["available_version"] = _otaManager.getAvailableVersion().toString();
|
||||
}
|
||||
otaObj["last_check_uptime_ms"] = _otaManager.getLastCheckUptimeMs();
|
||||
otaObj["last_error"] = OTAManager::errorCodeToString(_otaManager.getLastError());
|
||||
|
||||
JsonObject stackObj = doc["stack_high_water"].to<JsonObject>();
|
||||
Telemetry::writeStackHighWaterMarks(stackObj);
|
||||
|
||||
return CommandResult::ok("telemetry.get_diagnostics", doc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user