|
|
|
@@ -121,7 +121,7 @@ void sendToApi(void *parameter) {
|
|
|
|
|
|
|
|
|
|
// Wait until API is IDLE
|
|
|
|
|
while(spoolmanApiState != API_IDLE){
|
|
|
|
|
Serial.println("Waiting!");
|
|
|
|
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
|
|
|
yield();
|
|
|
|
|
}
|
|
|
|
|
spoolmanApiState = API_TRANSMITTING;
|
|
|
|
@@ -616,6 +616,7 @@ bool updateSpoolBambuData(String payload) {
|
|
|
|
|
uint16_t createVendor(String vendor) {
|
|
|
|
|
// Create new vendor in Spoolman database using task system
|
|
|
|
|
// Note: Due to async nature, the ID will be stored in createdVendorId global variable
|
|
|
|
|
// Note: This function assumes that the caller has already ensured API is IDLE
|
|
|
|
|
createdVendorId = 0; // Reset previous value
|
|
|
|
|
|
|
|
|
|
String spoolsUrl = spoolmanUrl + apiUrl + "/vendor";
|
|
|
|
@@ -645,19 +646,18 @@ uint16_t createVendor(String vendor) {
|
|
|
|
|
params->spoolsUrl = spoolsUrl;
|
|
|
|
|
params->updatePayload = vendorPayload;
|
|
|
|
|
|
|
|
|
|
// Check if API is idle before creating task
|
|
|
|
|
if(spoolmanApiState == API_IDLE){
|
|
|
|
|
// Erstelle die Task
|
|
|
|
|
BaseType_t result = xTaskCreate(
|
|
|
|
|
sendToApi, // Task-Funktion
|
|
|
|
|
"SendToApiTask", // Task-Name
|
|
|
|
|
6144, // Stackgröße in Bytes
|
|
|
|
|
(void*)params, // Parameter
|
|
|
|
|
0, // Priorität
|
|
|
|
|
NULL // Task-Handle (nicht benötigt)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
Serial.println("Not spawning new task, API still active!");
|
|
|
|
|
// Create task without additional API state check since caller ensures synchronization
|
|
|
|
|
BaseType_t result = xTaskCreate(
|
|
|
|
|
sendToApi, // Task-Funktion
|
|
|
|
|
"SendToApiTask", // Task-Name
|
|
|
|
|
6144, // Stackgröße in Bytes
|
|
|
|
|
(void*)params, // Parameter
|
|
|
|
|
0, // Priorität
|
|
|
|
|
NULL // Task-Handle (nicht benötigt)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result != pdPASS) {
|
|
|
|
|
Serial.println("Failed to create vendor task!");
|
|
|
|
|
delete params;
|
|
|
|
|
vendorDoc.clear();
|
|
|
|
|
return 0;
|
|
|
|
@@ -678,7 +678,10 @@ uint16_t checkVendor(String vendor) {
|
|
|
|
|
// Check if vendor exists using task system
|
|
|
|
|
foundVendorId = 0; // Reset previous value
|
|
|
|
|
|
|
|
|
|
String spoolsUrl = spoolmanUrl + apiUrl + "/vendor?name=" + vendor;
|
|
|
|
|
String vendorName = vendor;
|
|
|
|
|
vendorName.trim();
|
|
|
|
|
vendorName.replace(" ", "+");
|
|
|
|
|
String spoolsUrl = spoolmanUrl + apiUrl + "/vendor?name=" + vendorName;
|
|
|
|
|
Serial.print("Check vendor with URL: ");
|
|
|
|
|
Serial.println(spoolsUrl);
|
|
|
|
|
|
|
|
|
@@ -713,6 +716,9 @@ uint16_t checkVendor(String vendor) {
|
|
|
|
|
while(spoolmanApiState != API_IDLE) {
|
|
|
|
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Additional delay to ensure foundVendorId is properly set after API state becomes IDLE
|
|
|
|
|
vTaskDelay(50 / portTICK_PERIOD_MS);
|
|
|
|
|
|
|
|
|
|
// Check if vendor was found
|
|
|
|
|
if (foundVendorId == 0) {
|
|
|
|
@@ -736,6 +742,7 @@ uint16_t checkVendor(String vendor) {
|
|
|
|
|
uint16_t createFilament(uint16_t vendorId, const JsonDocument& payload) {
|
|
|
|
|
// Create new filament in Spoolman database using task system
|
|
|
|
|
// Note: Due to async nature, the ID will be stored in createdFilamentId global variable
|
|
|
|
|
// Note: This function assumes that the caller has already ensured API is IDLE
|
|
|
|
|
createdFilamentId = 0; // Reset previous value
|
|
|
|
|
|
|
|
|
|
String spoolsUrl = spoolmanUrl + apiUrl + "/filament";
|
|
|
|
@@ -744,12 +751,12 @@ uint16_t createFilament(uint16_t vendorId, const JsonDocument& payload) {
|
|
|
|
|
|
|
|
|
|
// Create JSON payload for filament creation
|
|
|
|
|
JsonDocument filamentDoc;
|
|
|
|
|
filamentDoc["name"] = payload["name"].as<String>();
|
|
|
|
|
filamentDoc["name"] = payload["color_name"].as<String>();
|
|
|
|
|
filamentDoc["vendor_id"] = String(vendorId);
|
|
|
|
|
filamentDoc["material"] = payload["type"].as<String>();
|
|
|
|
|
filamentDoc["density"] = (payload["density"].is<String>() && payload["density"].as<String>().length() > 0) ? payload["density"].as<String>() : "1.24";
|
|
|
|
|
filamentDoc["diameter"] = (payload["diameter"].is<String>() && payload["diameter"].as<String>().length() > 0) ? payload["diameter"].as<String>() : "1.75";
|
|
|
|
|
filamentDoc["weight"] = payload["weight"].as<String>();
|
|
|
|
|
filamentDoc["weight"] = String(weight);
|
|
|
|
|
filamentDoc["spool_weight"] = payload["spool_weight"].as<String>();
|
|
|
|
|
filamentDoc["article_number"] = payload["artnr"].as<String>();
|
|
|
|
|
filamentDoc["extruder_temp"] = payload["extruder_temp"].is<String>() ? payload["extruder_temp"].as<String>() : "";
|
|
|
|
@@ -771,7 +778,7 @@ uint16_t createFilament(uint16_t vendorId, const JsonDocument& payload) {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
filamentDoc["color_hex"] = (payload["color"].is<String>() && payload["color"].as<String>().length() >= 6) ? payload["color"].as<String>() : "FFFFFF";
|
|
|
|
|
filamentDoc["color_hex"] = (payload["color_hex"].is<String>() && payload["color_hex"].as<String>().length() >= 6) ? payload["color_hex"].as<String>() : "FFFFFF";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String filamentPayload;
|
|
|
|
@@ -790,19 +797,18 @@ uint16_t createFilament(uint16_t vendorId, const JsonDocument& payload) {
|
|
|
|
|
params->spoolsUrl = spoolsUrl;
|
|
|
|
|
params->updatePayload = filamentPayload;
|
|
|
|
|
|
|
|
|
|
// Check if API is idle before creating task
|
|
|
|
|
if(spoolmanApiState == API_IDLE){
|
|
|
|
|
// Erstelle die Task
|
|
|
|
|
BaseType_t result = xTaskCreate(
|
|
|
|
|
sendToApi, // Task-Funktion
|
|
|
|
|
"SendToApiTask", // Task-Name
|
|
|
|
|
6144, // Stackgröße in Bytes
|
|
|
|
|
(void*)params, // Parameter
|
|
|
|
|
0, // Priorität
|
|
|
|
|
NULL // Task-Handle (nicht benötigt)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
Serial.println("Not spawning new task, API still active!");
|
|
|
|
|
// Create task without additional API state check since caller ensures synchronization
|
|
|
|
|
BaseType_t result = xTaskCreate(
|
|
|
|
|
sendToApi, // Task-Funktion
|
|
|
|
|
"SendToApiTask", // Task-Name
|
|
|
|
|
6144, // Stackgröße in Bytes
|
|
|
|
|
(void*)params, // Parameter
|
|
|
|
|
0, // Priorität
|
|
|
|
|
NULL // Task-Handle (nicht benötigt)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result != pdPASS) {
|
|
|
|
|
Serial.println("Failed to create filament task!");
|
|
|
|
|
delete params;
|
|
|
|
|
filamentDoc.clear();
|
|
|
|
|
return 0;
|
|
|
|
@@ -858,6 +864,9 @@ uint16_t checkFilament(uint16_t vendorId, const JsonDocument& payload) {
|
|
|
|
|
while(spoolmanApiState != API_IDLE) {
|
|
|
|
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Additional delay to ensure foundFilamentId is properly set after API state becomes IDLE
|
|
|
|
|
vTaskDelay(50 / portTICK_PERIOD_MS);
|
|
|
|
|
|
|
|
|
|
// Check if filament was found
|
|
|
|
|
if (foundFilamentId == 0) {
|
|
|
|
@@ -881,6 +890,7 @@ uint16_t checkFilament(uint16_t vendorId, const JsonDocument& payload) {
|
|
|
|
|
uint16_t createSpool(uint16_t vendorId, uint16_t filamentId, JsonDocument& payload, String uidString) {
|
|
|
|
|
// Create new spool in Spoolman database using task system
|
|
|
|
|
// Note: Due to async nature, the ID will be stored in createdSpoolId global variable
|
|
|
|
|
// Note: This function assumes that the caller has already ensured API is IDLE
|
|
|
|
|
createdSpoolId = 0; // Reset previous value
|
|
|
|
|
|
|
|
|
|
String spoolsUrl = spoolmanUrl + apiUrl + "/spool";
|
|
|
|
@@ -890,8 +900,8 @@ uint16_t createSpool(uint16_t vendorId, uint16_t filamentId, JsonDocument& paylo
|
|
|
|
|
|
|
|
|
|
// Create JSON payload for spool creation
|
|
|
|
|
JsonDocument spoolDoc;
|
|
|
|
|
spoolDoc["first_used"] = String(currentDate);
|
|
|
|
|
spoolDoc["last_used"] = String(currentDate);
|
|
|
|
|
//spoolDoc["first_used"] = String(currentDate);
|
|
|
|
|
//spoolDoc["last_used"] = String(currentDate);
|
|
|
|
|
spoolDoc["filament_id"] = String(filamentId);
|
|
|
|
|
spoolDoc["initial_weight"] = weight > 10 ? String(weight) : "1000";
|
|
|
|
|
spoolDoc["spool_weight"] = (payload["spool_weight"].is<String>() && payload["spool_weight"].as<String>().length() > 0) ? payload["spool_weight"].as<String>() : "180";
|
|
|
|
@@ -918,19 +928,18 @@ uint16_t createSpool(uint16_t vendorId, uint16_t filamentId, JsonDocument& paylo
|
|
|
|
|
params->spoolsUrl = spoolsUrl;
|
|
|
|
|
params->updatePayload = spoolPayload;
|
|
|
|
|
|
|
|
|
|
// Check if API is idle before creating task
|
|
|
|
|
if(spoolmanApiState == API_IDLE){
|
|
|
|
|
// Erstelle die Task
|
|
|
|
|
BaseType_t result = xTaskCreate(
|
|
|
|
|
sendToApi, // Task-Funktion
|
|
|
|
|
"SendToApiTask", // Task-Name
|
|
|
|
|
6144, // Stackgröße in Bytes
|
|
|
|
|
(void*)params, // Parameter
|
|
|
|
|
0, // Priorität
|
|
|
|
|
NULL // Task-Handle (nicht benötigt)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
Serial.println("Not spawning new task, API still active!");
|
|
|
|
|
// Create task without additional API state check since caller ensures synchronization
|
|
|
|
|
BaseType_t result = xTaskCreate(
|
|
|
|
|
sendToApi, // Task-Funktion
|
|
|
|
|
"SendToApiTask", // Task-Name
|
|
|
|
|
6144, // Stackgröße in Bytes
|
|
|
|
|
(void*)params, // Parameter
|
|
|
|
|
0, // Priorität
|
|
|
|
|
NULL // Task-Handle (nicht benötigt)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result != pdPASS) {
|
|
|
|
|
Serial.println("Failed to create spool task!");
|
|
|
|
|
delete params;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@@ -941,7 +950,7 @@ uint16_t createSpool(uint16_t vendorId, uint16_t filamentId, JsonDocument& paylo
|
|
|
|
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// daten mit startWriteJsonToTag schreiben
|
|
|
|
|
// Write data to tag with startWriteJsonToTag
|
|
|
|
|
// void startWriteJsonToTag(const bool isSpoolTag, const char* payload);
|
|
|
|
|
payload["sm_id"].set(String(createdSpoolId));
|
|
|
|
|
|
|
|
|
|