Working on getting diagnostics working

This commit is contained in:
2026-08-09 10:13:16 -06:00
parent e411c934d5
commit 7ad00e452c
4 changed files with 42 additions and 21 deletions
+3 -2
View File
@@ -14,7 +14,8 @@ board = esp32dev
framework = arduino framework = arduino
lib_deps = lib_deps =
WebSockets WebSockets
;build_type = debug
; upload via OTA ; upload via OTA
upload_protocol = espota ;upload_protocol = espota
upload_port = 192.168.4.1 ;upload_port = 192.168.4.1
+22 -14
View File
@@ -13,29 +13,37 @@ void DiagnosticsState::update()
current.cpuFrequency = current.cpuFrequency =
ESP.getCpuFreqMHz(); ESP.getCpuFreqMHz();
history[historyIndex] = current; //history[historyIndex] = current;
//
//historyIndex++;
//if(historyIndex >= DIAGNOSTIC_HISTORY_SIZE)
//{
// historyIndex = 0;
//}
Serial.print("#update: ");
Serial.println(current.freeHeap);
Serial.println("Calling current from update");
getCurrent();
historyIndex++;
if(historyIndex >= DIAGNOSTIC_HISTORY_SIZE)
{
historyIndex = 0;
}
} }
DiagnosticSample DiagnosticsState::getCurrent() DiagnosticSample DiagnosticsState::getCurrent()
{ {
Serial.print("#getCurrent: ");
Serial.println(current.freeHeap);
Serial.println(current.timestamp);
return current; return current;
} }
DiagnosticSample DiagnosticsState::getHistory(uint8_t index) //DiagnosticSample DiagnosticsState::getHistory(uint8_t index)
{ //{
if(index >= DIAGNOSTIC_HISTORY_SIZE) // if(index >= DIAGNOSTIC_HISTORY_SIZE)
{ // {
return current; // return current;
} // }
return history[index]; // return history[index];
} //}
+3 -3
View File
@@ -23,12 +23,12 @@ public:
DiagnosticSample getCurrent(); DiagnosticSample getCurrent();
DiagnosticSample getHistory(uint8_t index); //DiagnosticSample getHistory(uint8_t index);
private: private:
DiagnosticSample current; DiagnosticSample current;
DiagnosticSample history[DIAGNOSTIC_HISTORY_SIZE]; //DiagnosticSample history[DIAGNOSTIC_HISTORY_SIZE];
uint8_t historyIndex = 0; //uint8_t historyIndex = 0;
}; };
+13 -1
View File
@@ -128,6 +128,7 @@ Firmware Version: <div id="firmware_version">Loading...</div>
void WebService::broadcastState() void WebService::broadcastState()
{ {
DiagnosticSample diagnostics = diagnosticsState.getCurrent(); DiagnosticSample diagnostics = diagnosticsState.getCurrent();
Serial.println(diagnostics.freeHeap);
String json = "{"; String json = "{";
// Opening system tag: // Opening system tag:
@@ -148,6 +149,7 @@ void WebService::broadcastState()
json += "\"free_heap\":\""; json += "\"free_heap\":\"";
json += diagnostics.freeHeap; json += diagnostics.freeHeap;
//json += ESP.getFreeHeap();
json += "\","; json += "\",";
json += "\"minimum_free_heap\":\""; json += "\"minimum_free_heap\":\"";
@@ -165,7 +167,7 @@ void WebService::broadcastState()
json += "}"; json += "}";
Serial.println(json); //Serial.println(json);
webSocket.broadcastTXT(json); webSocket.broadcastTXT(json);
} }
@@ -179,6 +181,16 @@ void WebService::begin() {
); );
}); });
#ifdef DEBUGGING
// Prints out paths that are requested but not found.
server.onNotFound([this]() {
Serial.print("HTTP not found: ");
Serial.println(server.uri());
server.send(404, "text/plain", "Not found");
});
#endif
server.begin(); server.begin();
webSocket.begin(); webSocket.begin();