Merge branch 'main' into configuration_nvs_storage
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,3 +3,6 @@
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
.vscode/extensions.json
|
||||
.vscode/settings.json
|
||||
data
|
||||
|
@@ -52,6 +52,7 @@ build_flags =
|
||||
-mtext-section-literals
|
||||
-DVERSION=\"${common.version}\"
|
||||
-DTOOLDVERSION=\"${common.to_old_version}\"
|
||||
#-DENABLE_HEAP_DEBUGGING
|
||||
-DASYNCWEBSERVER_REGEX
|
||||
#-DCORE_DEBUG_LEVEL=3
|
||||
-DCONFIG_ARDUHAL_LOG_COLORS=1
|
||||
|
24
src/api.cpp
24
src/api.cpp
@@ -3,6 +3,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include "commonFS.h"
|
||||
#include <Preferences.h>
|
||||
#include "debug.h"
|
||||
|
||||
volatile spoolmanApiStateType spoolmanApiState = API_INIT;
|
||||
//bool spoolman_connected = false;
|
||||
@@ -88,6 +89,8 @@ JsonDocument fetchSingleSpoolInfo(int spoolId) {
|
||||
}
|
||||
|
||||
void sendToApi(void *parameter) {
|
||||
HEAP_DEBUG_MESSAGE("sendToApi begin");
|
||||
|
||||
spoolmanApiState = API_TRANSMITTING;
|
||||
SendToApiParams* params = (SendToApiParams*)parameter;
|
||||
|
||||
@@ -132,8 +135,8 @@ void sendToApi(void *parameter) {
|
||||
}
|
||||
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
doc.clear();
|
||||
}
|
||||
doc.clear();
|
||||
|
||||
} else {
|
||||
Serial.println("Fehler beim Senden an Spoolman! HTTP Code: " + String(httpCode));
|
||||
@@ -146,8 +149,9 @@ void sendToApi(void *parameter) {
|
||||
|
||||
// Speicher freigeben
|
||||
delete params;
|
||||
vTaskDelete(NULL);
|
||||
HEAP_DEBUG_MESSAGE("sendToApi end");
|
||||
spoolmanApiState = API_IDLE;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
bool updateSpoolTagId(String uidString, const char* payload) {
|
||||
@@ -170,6 +174,8 @@ bool updateSpoolTagId(String uidString, const char* payload) {
|
||||
Serial.print("Update Spule mit URL: ");
|
||||
Serial.println(spoolsUrl);
|
||||
|
||||
doc.clear();
|
||||
|
||||
// Update Payload erstellen
|
||||
JsonDocument updateDoc;
|
||||
updateDoc["extra"]["nfc_id"] = "\""+uidString+"\"";
|
||||
@@ -208,6 +214,7 @@ bool updateSpoolTagId(String uidString, const char* payload) {
|
||||
}
|
||||
|
||||
uint8_t updateSpoolWeight(String spoolId, uint16_t weight) {
|
||||
HEAP_DEBUG_MESSAGE("updateSpoolWeight begin");
|
||||
String spoolsUrl = spoolmanUrl + apiUrl + "/spool/" + spoolId + "/measure";
|
||||
Serial.print("Update Spule mit URL: ");
|
||||
Serial.println(spoolsUrl);
|
||||
@@ -242,11 +249,14 @@ uint8_t updateSpoolWeight(String spoolId, uint16_t weight) {
|
||||
);
|
||||
|
||||
updateDoc.clear();
|
||||
HEAP_DEBUG_MESSAGE("updateSpoolWeight end");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t updateSpoolLocation(String spoolId, String location){
|
||||
HEAP_DEBUG_MESSAGE("updateSpoolLocation begin");
|
||||
|
||||
String spoolsUrl = spoolmanUrl + apiUrl + "/spool/" + spoolId;
|
||||
Serial.print("Update Spule mit URL: ");
|
||||
Serial.println(spoolsUrl);
|
||||
@@ -282,6 +292,7 @@ uint8_t updateSpoolLocation(String spoolId, String location){
|
||||
|
||||
updateDoc.clear();
|
||||
|
||||
HEAP_DEBUG_MESSAGE("updateSpoolLocation end");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -346,6 +357,10 @@ bool updateSpoolBambuData(String payload) {
|
||||
|
||||
String updatePayload;
|
||||
serializeJson(updateDoc, updatePayload);
|
||||
|
||||
doc.clear();
|
||||
updateDoc.clear();
|
||||
|
||||
Serial.print("Update Payload: ");
|
||||
Serial.println(updatePayload);
|
||||
|
||||
@@ -512,6 +527,7 @@ bool checkSpoolmanExtraFields() {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
doc.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,6 +574,8 @@ bool checkSpoolmanInstance(const String& url) {
|
||||
oledShowTopRow();
|
||||
return strcmp(status, "healthy") == 0;
|
||||
}
|
||||
|
||||
doc.clear();
|
||||
}
|
||||
} else {
|
||||
Serial.println("Error contacting spoolman instance! HTTP Code: " + String(httpCode));
|
||||
@@ -581,6 +599,8 @@ bool saveSpoolmanUrl(const String& url, bool octoOn, const String& octo_url, con
|
||||
octoUrl = octo_url;
|
||||
octoToken = octoTk;
|
||||
|
||||
doc.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
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);
|
||||
}
|
@@ -212,14 +212,14 @@ void loop() {
|
||||
lastWeight = weight;
|
||||
|
||||
// Wenn ein Tag mit SM id erkannte wurde und der Waage Counter anspricht an SM Senden
|
||||
if (spoolId != "" && weigthCouterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS) {
|
||||
if (activeSpoolId != "" && weigthCouterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS) {
|
||||
oledShowIcon("loading");
|
||||
if (updateSpoolWeight(spoolId, weight))
|
||||
if (updateSpoolWeight(activeSpoolId, weight))
|
||||
{
|
||||
oledShowIcon("success");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
weightSend = 1;
|
||||
autoSetToBambuSpoolId = spoolId.toInt();
|
||||
autoSetToBambuSpoolId = activeSpoolId.toInt();
|
||||
|
||||
if (octoEnabled)
|
||||
{
|
||||
|
21
src/nfc.cpp
21
src/nfc.cpp
@@ -15,7 +15,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;
|
||||
|
||||
@@ -65,6 +66,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\"}");
|
||||
@@ -219,17 +222,18 @@ bool decodeNdefAndReturnJson(const byte* encodedMessage) {
|
||||
// Sende die aktualisierten AMS-Daten an alle WebSocket-Clients
|
||||
Serial.println("JSON-Dokument erfolgreich verarbeitet");
|
||||
Serial.println(doc.as<String>());
|
||||
if (doc.containsKey("sm_id") && doc["sm_id"] != "")
|
||||
if (doc["sm_id"].is<String>() && 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"] != "")
|
||||
else if(doc["location"].is<String>() && doc["location"] != "")
|
||||
{
|
||||
Serial.println("Location Tag found!");
|
||||
String location = doc["location"].as<String>();
|
||||
if(spoolId != ""){
|
||||
updateSpoolLocation(spoolId, location);
|
||||
if(lastSpoolId != ""){
|
||||
updateSpoolLocation(lastSpoolId, location);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -241,12 +245,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;
|
||||
}
|
||||
|
||||
@@ -447,6 +453,7 @@ void scanRfidTask(void * parameter) {
|
||||
nfcReaderState = NFC_IDLE;
|
||||
//uidString = "";
|
||||
nfcJsonData = "";
|
||||
activeSpoolId = "";
|
||||
Serial.println("Tag entfernt");
|
||||
if (!bambuCredentials.autosend_enable) oledShowWeight(weight);
|
||||
}
|
||||
|
@@ -19,7 +19,8 @@ void startWriteJsonToTag(const char* payload);
|
||||
|
||||
extern TaskHandle_t RfidReaderTask;
|
||||
extern String nfcJsonData;
|
||||
extern String spoolId;
|
||||
extern String activeSpoolId;
|
||||
extern String lastSpoolId;
|
||||
extern volatile nfcReaderStateType nfcReaderState;
|
||||
extern volatile bool pauseBambuMqttTask;
|
||||
|
||||
|
@@ -11,6 +11,8 @@
|
||||
#include "display.h"
|
||||
#include "ota.h"
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION "1.1.0"
|
||||
@@ -27,6 +29,7 @@ nfcReaderStateType lastnfcReaderState = NFC_IDLE;
|
||||
|
||||
|
||||
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) {
|
||||
Serial.println("Neuer Client verbunden!");
|
||||
// Sende die AMS-Daten an den neuen Client
|
||||
@@ -34,6 +37,10 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
sendNfcData(client);
|
||||
foundNfcTag(client, 0);
|
||||
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) {
|
||||
Serial.println("Client getrennt.");
|
||||
} else if (type == WS_EVT_ERROR) {
|
||||
@@ -114,7 +121,9 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
else {
|
||||
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
|
||||
@@ -264,6 +273,8 @@ void setupWebserver(AsyncWebServer &server) {
|
||||
html.replace("{{autoSendToBambu}}", bambuCredentials.autosend_enable ? "checked" : "");
|
||||
html.replace("{{autoSendTime}}", (bambuCredentials.autosend_time != 0) ? String(bambuCredentials.autosend_time) : String(BAMBU_DEFAULT_AUTOSEND_TIME));
|
||||
|
||||
doc.clear();
|
||||
|
||||
request->send(200, "text/html", html);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user