fix(FileManager,Logging): day-rotated SD logs + boot reset-reason reporting
SD logging was a silent no-op on fresh cards: appendLine() opened /logs/vesper.log in FILE_APPEND without ever creating the /logs directory first. FileManager now exposes appendLogLine(), which creates the directory, rotates to YYYY-MM-DD.log files, and prunes oldest files once a 512KB total budget is exceeded. LoggingHandler gains logs.list / logs.download commands (chunked, paginated) so SD logs can be pulled off a device remotely for offline-device troubleshooting. Telemetry now captures esp_reset_reason() at boot and classifies it as a fault (panic/watchdog/brownout) or an expected reset (power-on/software/deep sleep). CommunicationRouter reports it once MQTT connects: faults go to status/alerts, expected resets go to status/info (type: boot_reason). MQTTDriver gained a setOnConnectCallback hook to support this. F-045, F-046, F-048 in the feature catalog.
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void Telemetry::begin() {
|
||||
resetReason = esp_reset_reason();
|
||||
LOG_INFO(TAG, "Reset reason: %s%s", getResetReasonString().c_str(), isFaultReset() ? " (FAULT)" : "");
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
strikeCounters[i] = 0;
|
||||
bellLoad[i] = 0;
|
||||
@@ -21,6 +24,36 @@ void Telemetry::begin() {
|
||||
LOG_INFO(TAG, "Telemetry initialized");
|
||||
}
|
||||
|
||||
bool Telemetry::isFaultReset() const {
|
||||
switch (resetReason) {
|
||||
case ESP_RST_PANIC:
|
||||
case ESP_RST_INT_WDT:
|
||||
case ESP_RST_TASK_WDT:
|
||||
case ESP_RST_WDT:
|
||||
case ESP_RST_BROWNOUT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
String Telemetry::getResetReasonString() const {
|
||||
switch (resetReason) {
|
||||
case ESP_RST_UNKNOWN: return "UNKNOWN";
|
||||
case ESP_RST_POWERON: return "POWERON";
|
||||
case ESP_RST_EXT: return "EXTERNAL_PIN";
|
||||
case ESP_RST_SW: return "SOFTWARE";
|
||||
case ESP_RST_PANIC: return "PANIC";
|
||||
case ESP_RST_INT_WDT: return "INTERRUPT_WATCHDOG";
|
||||
case ESP_RST_TASK_WDT: return "TASK_WATCHDOG";
|
||||
case ESP_RST_WDT: return "OTHER_WATCHDOG";
|
||||
case ESP_RST_DEEPSLEEP: return "DEEPSLEEP_WAKE";
|
||||
case ESP_RST_BROWNOUT: return "BROWNOUT";
|
||||
case ESP_RST_SDIO: return "SDIO";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void Telemetry::setPlayerReference(bool* isPlayingPtr) {
|
||||
playerIsPlayingPtr = isPlayingPtr;
|
||||
LOG_DEBUG(TAG, "Player reference set");
|
||||
@@ -270,8 +303,9 @@ void Telemetry::logBootEvent(uint32_t bootTimestamp) {
|
||||
|
||||
uint32_t bootNum = (uint32_t)(doc["total_boots"] | 0) + 1;
|
||||
JsonObject entry = entries.add<JsonObject>();
|
||||
entry["ts"] = bootTimestamp;
|
||||
entry["boot"] = bootNum;
|
||||
entry["ts"] = bootTimestamp;
|
||||
entry["boot"] = bootNum;
|
||||
entry["reason"] = getResetReasonString();
|
||||
doc["total_boots"] = bootNum;
|
||||
|
||||
if (!fileManager->writeJsonFile("/telemetry_boot_log.json", doc)) {
|
||||
|
||||
Reference in New Issue
Block a user