Introduces new heap debugging feature and fixes some memory leaks in website feature
Introduces a new define HEAP_DEBUG_MESSAGE(location) that can be used to instrument the code to get heap information output on the Serial output. It can be enabled via the define ENABLE_HEAP_DEBUGGING. Also fixes some memory leaks in the website part of the project.
This commit is contained in:
12
src/debug.h
Normal file
12
src/debug.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ENABLE_HEAP_DEBUGGING
|
||||||
|
#define HEAP_DEBUG_MESSAGE(location) printHeapDebugData(location);
|
||||||
|
#else
|
||||||
|
#define HEAP_DEBUG_MESSAGE(location)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline void printHeapDebugData(String location){
|
||||||
|
Serial.println("Heap: " + String(ESP.getMinFreeHeap()/1024) + "\t" + String(ESP.getFreeHeap()/1024) + "\t" + String(ESP.getMaxAllocHeap()/1024) + "\t" + location);
|
||||||
|
}
|
@@ -10,6 +10,7 @@
|
|||||||
#include <Update.h>
|
#include <Update.h>
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
#define VERSION "1.1.0"
|
#define VERSION "1.1.0"
|
||||||
@@ -26,6 +27,7 @@ nfcReaderStateType lastnfcReaderState = NFC_IDLE;
|
|||||||
|
|
||||||
|
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
|
HEAP_DEBUG_MESSAGE("onWsEvent begin");
|
||||||
if (type == WS_EVT_CONNECT) {
|
if (type == WS_EVT_CONNECT) {
|
||||||
Serial.println("Neuer Client verbunden!");
|
Serial.println("Neuer Client verbunden!");
|
||||||
// Sende die AMS-Daten an den neuen Client
|
// Sende die AMS-Daten an den neuen Client
|
||||||
@@ -33,6 +35,10 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
|||||||
sendNfcData(client);
|
sendNfcData(client);
|
||||||
foundNfcTag(client, 0);
|
foundNfcTag(client, 0);
|
||||||
sendWriteResult(client, 3);
|
sendWriteResult(client, 3);
|
||||||
|
|
||||||
|
// Clean up dead connections
|
||||||
|
(*server).cleanupClients();
|
||||||
|
Serial.println("Currently connected number of clients: " + String((*server).getClients().size()));
|
||||||
} else if (type == WS_EVT_DISCONNECT) {
|
} else if (type == WS_EVT_DISCONNECT) {
|
||||||
Serial.println("Client getrennt.");
|
Serial.println("Client getrennt.");
|
||||||
} else if (type == WS_EVT_ERROR) {
|
} else if (type == WS_EVT_ERROR) {
|
||||||
@@ -113,7 +119,9 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
|||||||
else {
|
else {
|
||||||
Serial.println("Unbekannter WebSocket-Typ: " + doc["type"].as<String>());
|
Serial.println("Unbekannter WebSocket-Typ: " + doc["type"].as<String>());
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
}
|
}
|
||||||
|
HEAP_DEBUG_MESSAGE("onWsEvent end");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion zum Laden und Ersetzen des Headers in einer HTML-Datei
|
// Funktion zum Laden und Ersetzen des Headers in einer HTML-Datei
|
||||||
@@ -280,6 +288,8 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
html.replace("{{autoSendTime}}", String(autoSetBambuAmsCounter));
|
html.replace("{{autoSendTime}}", String(autoSetBambuAmsCounter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doc.clear();
|
||||||
|
|
||||||
request->send(200, "text/html", html);
|
request->send(200, "text/html", html);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user