Compare commits
6 Commits
v1.5.12-be
...
v1.5.12-be
Author | SHA1 | Date | |
---|---|---|---|
2587227e78 | |||
0f19dc4f46 | |||
721dac1ead | |||
08abd1a37f | |||
da78861613 | |||
9231a303f3 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,5 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
## [1.5.12-beta11] - 2025-08-29
|
||||
### Changed
|
||||
- update platformio.ini for beta version v1.5.12-beta11
|
||||
|
||||
### Fixed
|
||||
- update spoolman ID reset values to 65535 for better API response detection
|
||||
|
||||
|
||||
## [1.5.12-beta10] - 2025-08-29
|
||||
### Changed
|
||||
- update platformio.ini for beta version v1.5.12-beta10
|
||||
- streamline task creation in checkVendor and checkFilament functions
|
||||
|
||||
|
||||
## [1.5.12-beta9] - 2025-08-29
|
||||
### Added
|
||||
- update vendor and filament ID handling to use NULL and add delays for stability
|
||||
|
@@ -9,7 +9,7 @@
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[common]
|
||||
version = "1.5.12-beta9"
|
||||
version = "1.5.12-beta11"
|
||||
to_old_version = "1.5.0"
|
||||
|
||||
##
|
||||
|
79
src/api.cpp
79
src/api.cpp
@@ -5,6 +5,7 @@
|
||||
#include <Preferences.h>
|
||||
#include "debug.h"
|
||||
#include "scale.h"
|
||||
#include "nfc.h"
|
||||
#include <time.h>
|
||||
volatile spoolmanApiStateType spoolmanApiState = API_IDLE;
|
||||
|
||||
@@ -151,7 +152,7 @@ void sendToApi(void *parameter) {
|
||||
else httpCode = http.PUT(updatePayload);
|
||||
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
Serial.println("Spoolman erfolgreich aktualisiert");
|
||||
Serial.println("Spoolman Abfrage erfolgreich");
|
||||
|
||||
// Restgewicht der Spule auslesen
|
||||
String payload = http.getString();
|
||||
@@ -676,7 +677,7 @@ uint16_t createVendor(String vendor) {
|
||||
|
||||
uint16_t checkVendor(String vendor) {
|
||||
// Check if vendor exists using task system
|
||||
foundVendorId = NULL; // Reset previous value
|
||||
foundVendorId = 65535; // Reset to invalid value to detect when API response is received
|
||||
|
||||
String vendorName = vendor;
|
||||
vendorName.trim();
|
||||
@@ -701,30 +702,18 @@ uint16_t checkVendor(String vendor) {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
|
||||
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!");
|
||||
delete params;
|
||||
return 0;
|
||||
}
|
||||
// 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)
|
||||
);
|
||||
|
||||
// Wait for task completion
|
||||
while(spoolmanApiState != API_IDLE) {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
// Additional delay to ensure foundVendorId is properly set after API state becomes IDLE
|
||||
while (foundVendorId == NULL)
|
||||
// Wait until foundVendorId is updated by the API response (not 65535 anymore)
|
||||
while (foundVendorId == 65535)
|
||||
{
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
@@ -836,7 +825,7 @@ uint16_t createFilament(uint16_t vendorId, const JsonDocument& payload) {
|
||||
|
||||
uint16_t checkFilament(uint16_t vendorId, const JsonDocument& payload) {
|
||||
// Check if filament exists using task system
|
||||
foundFilamentId = NULL; // Reset previous value
|
||||
foundFilamentId = 65535; // Reset to invalid value to detect when API response is received
|
||||
|
||||
String spoolsUrl = spoolmanUrl + apiUrl + "/filament?vendor.id=" + String(vendorId) + "&external_id=" + String(payload["artnr"].as<String>());
|
||||
Serial.print("Check filament with URL: ");
|
||||
@@ -852,30 +841,18 @@ uint16_t checkFilament(uint16_t vendorId, const JsonDocument& payload) {
|
||||
params->spoolsUrl = spoolsUrl;
|
||||
params->updatePayload = ""; // Empty for GET request
|
||||
|
||||
// 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!");
|
||||
// delete params;
|
||||
// return 0;
|
||||
//}
|
||||
// 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)
|
||||
);
|
||||
|
||||
// Wait for task completion
|
||||
while(spoolmanApiState != API_IDLE) {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
// Additional delay to ensure foundFilamentId is properly set after API state becomes IDLE
|
||||
while (foundFilamentId == NULL) {
|
||||
// Wait until foundFilamentId is updated by the API response (not 65535 anymore)
|
||||
while (foundFilamentId == 65535) {
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
@@ -902,7 +879,7 @@ uint16_t createSpool(uint16_t vendorId, uint16_t filamentId, JsonDocument& paylo
|
||||
// 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 = NULL; // Reset previous value
|
||||
createdSpoolId = 65535; // Reset to invalid value to detect when API response is received
|
||||
|
||||
String spoolsUrl = spoolmanUrl + apiUrl + "/spool";
|
||||
Serial.print("Create spool with URL: ");
|
||||
@@ -956,7 +933,7 @@ uint16_t createSpool(uint16_t vendorId, uint16_t filamentId, JsonDocument& paylo
|
||||
|
||||
// Wait for task completion and return the created spool ID
|
||||
// Note: createdSpoolId will be set by sendToApi when response is received
|
||||
while(createdSpoolId == NULL) {
|
||||
while(createdSpoolId == 65535) {
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user