Compare commits

...

5 Commits

Author SHA1 Message Date
9e58b042c8 fix: improve weight processing logic and add auto-send feature for Bambu spool ID 2025-08-27 17:21:29 +02:00
65967ca047 Changed Amazon Link for PN532 2025-08-23 19:01:07 +02:00
e4d1ba6c1c docs: update changelog and header for version v1.5.9
All checks were successful
Release Workflow / detect-provider (push) Successful in 4s
Release Workflow / github-release (push) Has been skipped
Release Workflow / gitea-release (push) Successful in 3m31s
2025-08-11 14:18:12 +02:00
88598611c5 docs: update platformio.ini for version v1.5.9 2025-08-11 14:18:12 +02:00
377f4bc146 Enhance API to support weight updates after successful spool tag updates 2025-08-11 14:17:57 +02:00
7 changed files with 93 additions and 20 deletions

1
.gitignore vendored
View File

@@ -32,6 +32,7 @@ test/README
data/*
!data/
!data/.gitkeep
# important
html/bambu_credentials.json
html/spoolman_url.json
_local/*

View File

@@ -1,5 +1,11 @@
# Changelog
## [1.5.9] - 2025-08-11
### Changed
- update platformio.ini for version v1.5.9
- Enhance API to support weight updates after successful spool tag updates
## [1.5.8] - 2025-08-10
### Added
- Adds a link to the spool in spoolman when reading a spool tag

View File

@@ -62,7 +62,7 @@ Discord Server: [https://discord.gg/my7Gvaxj2v](https://discord.gg/my7Gvaxj2v)
- **OLED 0.96 Zoll I2C white/yellow Display:** 128x64 SSD1306.
[Amazon Link](https://amzn.to/445aaa9)
- **PN532 NFC NXP RFID-Modul V3:** For NFC tag operations.
[Amazon Link](https://amzn.to/4iO6CO4)
[Amazon Link](https://amzn.eu/d/gy9vaBX)
- **NFC Tags NTAG213 NTAG215:** RFID Tag
[Amazon Link](https://amzn.to/3E071xO)
- **TTP223 Touch Sensor (optional):** For reTARE per Button/Touch

View File

@@ -66,7 +66,7 @@ Discord Server: [https://discord.gg/my7Gvaxj2v](https://discord.gg/my7Gvaxj2v)
- **OLED 0.96 Zoll I2C white/yellow Display:** 128x64 SSD1306.
[Amazon Link](https://amzn.to/445aaa9)
- **PN532 NFC NXP RFID-Modul V3:** For NFC tag operations.
[Amazon Link](https://amzn.to/4iO6CO4)
[Amazon Link](https://amzn.eu/d/gy9vaBX)
- **NFC Tags NTAG213 NTAG215:** RFID Tag
[Amazon Link](https://amzn.to/3E071xO)
- **TTP223 Touch Sensor (optional):** For reTARE per Button/Touch

View File

@@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html
[common]
version = "1.5.8"
version = "1.5.9"
to_old_version = "1.5.0"
##

View File

@@ -4,6 +4,7 @@
#include "commonFS.h"
#include <Preferences.h>
#include "debug.h"
#include "scale.h"
volatile spoolmanApiStateType spoolmanApiState = API_IDLE;
//bool spoolman_connected = false;
@@ -23,6 +24,10 @@ struct SendToApiParams {
String spoolsUrl;
String updatePayload;
String octoToken;
// Weight update parameters for sequential execution
bool triggerWeightUpdate;
String spoolIdForWeight;
uint16_t weightValue;
};
JsonDocument fetchSingleSpoolInfo(int spoolId) {
@@ -104,12 +109,15 @@ void sendToApi(void *parameter) {
spoolmanApiState = API_TRANSMITTING;
SendToApiParams* params = (SendToApiParams*)parameter;
// Extrahiere die Werte
// Extract values including weight update parameters
SpoolmanApiRequestType requestType = params->requestType;
String httpType = params->httpType;
String spoolsUrl = params->spoolsUrl;
String updatePayload = params->updatePayload;
String octoToken = params->octoToken;
bool triggerWeightUpdate = params->triggerWeightUpdate;
String spoolIdForWeight = params->spoolIdForWeight;
uint16_t weightValue = params->weightValue;
HTTPClient http;
http.setReuse(false);
@@ -163,6 +171,57 @@ void sendToApi(void *parameter) {
}
}
doc.clear();
// Execute weight update if requested and tag update was successful
if (triggerWeightUpdate && requestType == API_REQUEST_SPOOL_TAG_ID_UPDATE && weightValue > 10) {
Serial.println("Executing weight update after successful tag update");
// Prepare weight update request
String weightUrl = spoolmanUrl + apiUrl + "/spool/" + spoolIdForWeight + "/measure";
JsonDocument weightDoc;
weightDoc["weight"] = weightValue;
String weightPayload;
serializeJson(weightDoc, weightPayload);
Serial.print("Weight update URL: ");
Serial.println(weightUrl);
Serial.print("Weight update payload: ");
Serial.println(weightPayload);
// Execute weight update
http.begin(weightUrl);
http.addHeader("Content-Type", "application/json");
int weightHttpCode = http.PUT(weightPayload);
if (weightHttpCode == HTTP_CODE_OK) {
Serial.println("Weight update successful");
String weightResponse = http.getString();
JsonDocument weightResponseDoc;
DeserializationError weightError = deserializeJson(weightResponseDoc, weightResponse);
if (!weightError) {
remainingWeight = weightResponseDoc["remaining_weight"].as<uint16_t>();
Serial.print("Updated weight: ");
Serial.println(remainingWeight);
if (!octoEnabled) {
oledShowProgressBar(1, 1, "Spool Tag", ("Done: " + String(remainingWeight) + " g remain").c_str());
remainingWeight = 0;
} else {
sendOctoUpdate = true;
}
}
weightResponseDoc.clear();
} else {
Serial.print("Weight update failed with HTTP code: ");
Serial.println(weightHttpCode);
oledShowProgressBar(1, 1, "Failure!", "Weight update");
}
weightDoc.clear();
}
} else {
switch(requestType){
case API_REQUEST_SPOOL_WEIGHT_UPDATE:
@@ -211,7 +270,8 @@ bool updateSpoolTagId(String uidString, const char* payload) {
return false;
}
String spoolsUrl = spoolmanUrl + apiUrl + "/spool/" + doc["sm_id"].as<String>();
String spoolId = doc["sm_id"].as<String>();
String spoolsUrl = spoolmanUrl + apiUrl + "/spool/" + spoolId;
Serial.print("Update Spule mit URL: ");
Serial.println(spoolsUrl);
@@ -236,21 +296,25 @@ bool updateSpoolTagId(String uidString, const char* payload) {
params->spoolsUrl = spoolsUrl;
params->updatePayload = updatePayload;
// Erstelle die Task
// Add weight update parameters for sequential execution
params->triggerWeightUpdate = (weight > 10);
params->spoolIdForWeight = spoolId;
params->weightValue = weight;
// Erstelle die Task mit erhöhter Stackgröße für zusätzliche HTTP-Anfrage
BaseType_t result = xTaskCreate(
sendToApi, // Task-Funktion
"SendToApiTask", // Task-Name
6144, // Stackgröße in Bytes
8192, // Erhöhte Stackgröße für zusätzliche HTTP-Anfrage
(void*)params, // Parameter
0, // Priorität
apiTask // Task-Handle (nicht benötigt)
apiTask // Task-Handle (nicht benötigt)
);
updateDoc.clear();
// Update Spool weight
//TBD: how to handle this with spool and locatin tags? Also potential parallel access again
//if (weight > 10) updateSpoolWeight(doc["sm_id"].as<String>(), weight);
// Update Spool weight now handled sequentially in sendToApi task
// to prevent parallel API access issues
return true;
}

View File

@@ -225,7 +225,8 @@ void loop() {
lastWeight = weight;
// Wenn ein Tag mit SM id erkannte wurde und der Waage Counter anspricht an SM Senden
if (activeSpoolId != "" && weigthCouterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS && tagProcessed == false && spoolmanApiState == API_IDLE) {
if (activeSpoolId != "" && weigthCouterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS && tagProcessed == false && spoolmanApiState == API_IDLE)
{
// set the current tag as processed to prevent it beeing processed again
tagProcessed = true;
@@ -233,6 +234,11 @@ void loop() {
{
weightSend = 1;
// Set Bambu spool ID for auto-send if enabled
if (bambuCredentials.autosend_enable)
{
autoSetToBambuSpoolId = activeSpoolId.toInt();
}
}
else
{
@@ -241,13 +247,9 @@ void loop() {
}
}
if(sendOctoUpdate && spoolmanApiState == API_IDLE){
autoSetToBambuSpoolId = activeSpoolId.toInt();
if(octoEnabled)
{
updateSpoolOcto(autoSetToBambuSpoolId);
}
if(octoEnabled && sendOctoUpdate && spoolmanApiState == API_IDLE)
{
updateSpoolOcto(autoSetToBambuSpoolId);
sendOctoUpdate = false;
}
}