feat: add tag data handling and scan request functionality

This commit is contained in:
Manuel Weiser committed 2026-05-28 17:04:24 +02:00
1 parent 9456e6ab91
commit 775700f90f
5 files changed
+61 -4

No files matched your search

+38 -1
View File
@@ -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<MAX_API_QUEUE; i++) if(!apiQueue[i].active) {
apiQueue[i].type = API_REQUEST_TAG_DATA;
apiQueue[i].str1 = tagJson;
apiQueue[i].id1 = 0;
apiQueue[i].id2 = 0;
apiQueue[i].str2 = "";
apiQueue[i].val = 0.0f;
apiQueue[i].active = true;
break;
}
xSemaphoreGive(queueMutex);
}
}
bool initFilaman() {
oledShowProgressBar(3, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_API_INIT));
loadFilamanConfig();
+3 -1
View File
@@ -17,7 +17,8 @@ typedef enum {
API_REQUEST_HEARTBEAT,
API_REQUEST_WEIGHT,
API_REQUEST_LOCATE,
API_REQUEST_RFID_RESULT
API_REQUEST_RFID_RESULT,
API_REQUEST_TAG_DATA
} FilamanApiRequestType;
extern volatile filamanApiStateType filamanApiState;
@@ -30,6 +31,7 @@ void sendHeartbeatAsync();
void sendWeightAsync(int spoolId, String tagUuid, float weight);
void sendLocationAsync(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid);
void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight = 0);
void sendTagDataAsync(String tagJson);
// Internal blocking functions (used by async task)
bool sendHeartbeat();
+13 -2
View File
@@ -27,6 +27,11 @@ bool isBambuTag = false;
volatile bool nfcReadingTaskSuspendRequest = false;
volatile bool nfcReadingTaskSuspendState = false;
volatile bool nfcWriteInProgress = false; // Prevent any tag operations during write
volatile bool scanRequestActive = false; // Set by website when frontend requests a tag scan
void setScanRequest(bool active) {
scanRequestActive = active;
}
volatile nfcReaderStateType nfcReaderState = NFC_IDLE;
// 0 = nicht gelesen
@@ -1362,8 +1367,14 @@ bool decodeNdefAndReturnJson(const byte* encodedMessage, String uidString) {
String displayText = brand.length() > 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
{
+2
View File
@@ -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;
+5
View File
@@ -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);