Memory leak fixes in api and nfc, location tag fix

Fixes multiple potential memory leaks in API and NFC. Also fixes an issue in the new locaiton tag feature that could lead to multiple parallel API requests. This could cause memory leak issues but also result in wrong weights being registered for a spool.
This commit is contained in:
Jan Philipp Ecker committed 2025-07-26 22:36:04 +02:00
1 parent d536181a73
commit faaffee391
4 files changed
+41 -11

No files matched your search

+12 -5
View File
@@ -14,7 +14,8 @@ Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
TaskHandle_t RfidReaderTask;
JsonDocument rfidData;
String spoolId = "";
String activeSpoolId = "";
String lastSpoolId = "";
String nfcJsonData = "";
volatile bool pauseBambuMqttTask = false;
@@ -64,6 +65,8 @@ void payloadToJson(uint8_t *data) {
Serial.print("deserializeJson() failed: ");
Serial.println(error.f_str());
}
doc.clear();
} else {
Serial.println("Kein gültiger JSON-Inhalt gefunden oder fehlerhafte Formatierung.");
//writeJsonToTag("{\"version\":\"1.0\",\"protocol\":\"NFC\",\"color_hex\":\"#FFFFFF\",\"type\":\"Example\",\"min_temp\":10,\"max_temp\":30,\"brand\":\"BrandName\"}");
@@ -221,14 +224,15 @@ bool decodeNdefAndReturnJson(const byte* encodedMessage) {
if (doc.containsKey("sm_id") && doc["sm_id"] != "")
{
Serial.println("SPOOL-ID gefunden: " + doc["sm_id"].as<String>());
spoolId = doc["sm_id"].as<String>();
activeSpoolId = doc["sm_id"].as<String>();
lastSpoolId = activeSpoolId;
}
else if(doc.containsKey("location") && doc["location"] != "")
{
Serial.println("Location Tag found!");
String location = doc["location"].as<String>();
if(spoolId != ""){
updateSpoolLocation(spoolId, location);
if(lastSpoolId != ""){
updateSpoolLocation(lastSpoolId, location);
}
else
{
@@ -240,12 +244,14 @@ bool decodeNdefAndReturnJson(const byte* encodedMessage) {
else
{
Serial.println("Keine SPOOL-ID gefunden.");
spoolId = "";
activeSpoolId = "";
oledShowMessage("Unknown Spool");
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
doc.clear();
return true;
}
@@ -446,6 +452,7 @@ void scanRfidTask(void * parameter) {
nfcReaderState = NFC_IDLE;
//uidString = "";
nfcJsonData = "";
activeSpoolId = "";
Serial.println("Tag entfernt");
if (!autoSendToBambu) oledShowWeight(weight);
}