diff --git a/src/api.cpp b/src/api.cpp index ca24d12..38434da 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -208,6 +208,25 @@ bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, S return (httpCode == 200); } +bool sendTagData(String tagJson) { + if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false; + HTTPClient http; + http.setTimeout(10000); + http.setReuse(true); + http.begin(filamanUrl + "/api/v1/devices/tag-data"); + http.addHeader("Content-Type", "application/json"); + http.addHeader("Authorization", "Device " + filamanToken); + http.addHeader("Connection", "keep-alive"); + JsonDocument doc; + doc["tag_json"] = tagJson; + String payload; + serializeJson(doc, payload); + int httpCode = http.POST(payload); + http.end(); + Serial.printf("sendTagData: HTTP %d\n", httpCode); + return (httpCode == 200); +} + void filamanApiTask(void* pvParameters) { for (;;) { ApiRequest req; @@ -228,10 +247,11 @@ void filamanApiTask(void* pvParameters) { if (hasReq) { filamanApiState = API_TRANSMITTING; switch (req.type) { - case API_REQUEST_HEARTBEAT: sendHeartbeatWithRetry(2); break; // Mit Retry-Logik + case API_REQUEST_HEARTBEAT: sendHeartbeatWithRetry(2); break; case API_REQUEST_WEIGHT: sendWeight(req.id1, req.str1, req.val); break; case API_REQUEST_LOCATE: sendLocation(req.id1, req.str1, req.id2, req.str2); break; case API_REQUEST_RFID_RESULT: sendRfidResult(req.str1, req.id1, req.id2, req.bool1, req.str3, req.remainingWeight); break; + case API_REQUEST_TAG_DATA: sendTagData(req.str1); break; default: break; } filamanApiState = API_IDLE; @@ -323,6 +343,23 @@ void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool succe } } +void sendTagDataAsync(String tagJson) { + if (!checkFilamanRegistration()) return; + if (xSemaphoreTake(queueMutex, pdMS_TO_TICKS(50)) == pdTRUE) { + for(int i=0; i 0 ? (brand + " " + type) : type; Serial.println("Extended-data tag: protocol=" + protocolStr + " type=" + type + " brand=" + brand); activeSpoolId = ""; // Keine sm_id → Gewicht wird mit tag_uuid gesendet - oledShowProgressBar(2, 4, tr(STR_SPOOL_TAG), displayText.c_str()); - oledSetPriority(DISPLAY_PRIORITY_ACTION, 2000); + if (scanRequestActive) { + scanRequestActive = false; + sendTagDataAsync(nfcJsonData); + tagProcessed = true; + } else { + oledShowProgressBar(2, 4, tr(STR_SPOOL_TAG), displayText.c_str()); + oledSetPriority(DISPLAY_PRIORITY_ACTION, 2000); + } } else { diff --git a/src/nfc.h b/src/nfc.h index d424d40..c4b78f2 100644 --- a/src/nfc.h +++ b/src/nfc.h @@ -28,6 +28,7 @@ void scanRfidTask(void * parameter); void startWriteJsonToTag(const bool isSpoolTag, const char* payload, int spoolId = 0, int locationId = 0); bool quickSpoolIdCheck(String uidString); bool readCompleteJsonForFastPath(); // Read complete JSON data for fast-path web interface display +void setScanRequest(bool active); extern TaskHandle_t RfidReaderTask; extern String nfcJsonData; @@ -36,6 +37,7 @@ extern String activeTagUuid; extern String lastSpoolId; extern volatile nfcReaderStateType nfcReaderState; extern volatile bool nfcWriteInProgress; +extern volatile bool scanRequestActive; extern bool tagProcessed; extern bool isBambuTag; diff --git a/src/website.cpp b/src/website.cpp index 64de830..1def1ea 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -285,6 +285,11 @@ void setupWebserver(AsyncWebServer &server) { request->send(200, "application/json", "{\"success\": true}"); }); + server.on("/api/v1/rfid/scan-request", HTTP_POST, [](AsyncWebServerRequest *request){}, NULL, [](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ + setScanRequest(true); + request->send(200, "application/json", "{\"success\": true}"); + }); + server.on("/reboot", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(200, "text/plain", "Rebooting..."); delay(500);