Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4d1ba6c1c | |||
88598611c5 | |||
377f4bc146 | |||
7cbd34bc91 | |||
f7484f635e |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,5 +1,35 @@
|
|||||||
# Changelog
|
# 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
|
||||||
|
- Fixes types and some issues in the new graphics
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- update platformio.ini for version v1.5.8
|
||||||
|
- Merge pull request #45 from janecker/nfc_write_improvements
|
||||||
|
- Introduces periodic Spoolman Healthcheck
|
||||||
|
- Improves init - NFC reading now only starts after boot is finished
|
||||||
|
- Further improvements on NFC writing
|
||||||
|
- Merge pull request #44 from janecker/graphics_rework
|
||||||
|
- Graphic rework of the NFC writing process
|
||||||
|
- Remove unused parameter of sendNfcData()
|
||||||
|
- Reworks startup graphics and timings
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixes issue that scale not calibrated message was not shown
|
||||||
|
- Improves NFC writing workaround and removes debug output
|
||||||
|
- Fixes typos in upgrade page
|
||||||
|
- Reworks graphics of tag reading and some api fixes
|
||||||
|
- Replaces usage of String with const char* in heap debug function
|
||||||
|
|
||||||
|
|
||||||
## [1.5.7] - 2025-07-28
|
## [1.5.7] - 2025-07-28
|
||||||
### Changed
|
### Changed
|
||||||
- update platformio.ini for version v1.5.7
|
- update platformio.ini for version v1.5.7
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
version = "1.5.7"
|
version = "1.5.9"
|
||||||
to_old_version = "1.5.0"
|
to_old_version = "1.5.0"
|
||||||
|
|
||||||
##
|
##
|
||||||
|
82
src/api.cpp
82
src/api.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "commonFS.h"
|
#include "commonFS.h"
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "scale.h"
|
||||||
|
|
||||||
volatile spoolmanApiStateType spoolmanApiState = API_IDLE;
|
volatile spoolmanApiStateType spoolmanApiState = API_IDLE;
|
||||||
//bool spoolman_connected = false;
|
//bool spoolman_connected = false;
|
||||||
@@ -23,6 +24,10 @@ struct SendToApiParams {
|
|||||||
String spoolsUrl;
|
String spoolsUrl;
|
||||||
String updatePayload;
|
String updatePayload;
|
||||||
String octoToken;
|
String octoToken;
|
||||||
|
// Weight update parameters for sequential execution
|
||||||
|
bool triggerWeightUpdate;
|
||||||
|
String spoolIdForWeight;
|
||||||
|
uint16_t weightValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonDocument fetchSingleSpoolInfo(int spoolId) {
|
JsonDocument fetchSingleSpoolInfo(int spoolId) {
|
||||||
@@ -104,12 +109,15 @@ void sendToApi(void *parameter) {
|
|||||||
spoolmanApiState = API_TRANSMITTING;
|
spoolmanApiState = API_TRANSMITTING;
|
||||||
SendToApiParams* params = (SendToApiParams*)parameter;
|
SendToApiParams* params = (SendToApiParams*)parameter;
|
||||||
|
|
||||||
// Extrahiere die Werte
|
// Extract values including weight update parameters
|
||||||
SpoolmanApiRequestType requestType = params->requestType;
|
SpoolmanApiRequestType requestType = params->requestType;
|
||||||
String httpType = params->httpType;
|
String httpType = params->httpType;
|
||||||
String spoolsUrl = params->spoolsUrl;
|
String spoolsUrl = params->spoolsUrl;
|
||||||
String updatePayload = params->updatePayload;
|
String updatePayload = params->updatePayload;
|
||||||
String octoToken = params->octoToken;
|
String octoToken = params->octoToken;
|
||||||
|
bool triggerWeightUpdate = params->triggerWeightUpdate;
|
||||||
|
String spoolIdForWeight = params->spoolIdForWeight;
|
||||||
|
uint16_t weightValue = params->weightValue;
|
||||||
|
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setReuse(false);
|
http.setReuse(false);
|
||||||
@@ -163,6 +171,57 @@ void sendToApi(void *parameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
doc.clear();
|
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 {
|
} else {
|
||||||
switch(requestType){
|
switch(requestType){
|
||||||
case API_REQUEST_SPOOL_WEIGHT_UPDATE:
|
case API_REQUEST_SPOOL_WEIGHT_UPDATE:
|
||||||
@@ -211,7 +270,8 @@ bool updateSpoolTagId(String uidString, const char* payload) {
|
|||||||
return false;
|
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.print("Update Spule mit URL: ");
|
||||||
Serial.println(spoolsUrl);
|
Serial.println(spoolsUrl);
|
||||||
|
|
||||||
@@ -235,22 +295,26 @@ bool updateSpoolTagId(String uidString, const char* payload) {
|
|||||||
params->httpType = "PATCH";
|
params->httpType = "PATCH";
|
||||||
params->spoolsUrl = spoolsUrl;
|
params->spoolsUrl = spoolsUrl;
|
||||||
params->updatePayload = updatePayload;
|
params->updatePayload = updatePayload;
|
||||||
|
|
||||||
|
// Add weight update parameters for sequential execution
|
||||||
|
params->triggerWeightUpdate = (weight > 10);
|
||||||
|
params->spoolIdForWeight = spoolId;
|
||||||
|
params->weightValue = weight;
|
||||||
|
|
||||||
// Erstelle die Task
|
// Erstelle die Task mit erhöhter Stackgröße für zusätzliche HTTP-Anfrage
|
||||||
BaseType_t result = xTaskCreate(
|
BaseType_t result = xTaskCreate(
|
||||||
sendToApi, // Task-Funktion
|
sendToApi, // Task-Funktion
|
||||||
"SendToApiTask", // Task-Name
|
"SendToApiTask", // Task-Name
|
||||||
6144, // Stackgröße in Bytes
|
8192, // Erhöhte Stackgröße für zusätzliche HTTP-Anfrage
|
||||||
(void*)params, // Parameter
|
(void*)params, // Parameter
|
||||||
0, // Priorität
|
0, // Priorität
|
||||||
apiTask // Task-Handle (nicht benötigt)
|
apiTask // Task-Handle (nicht benötigt)
|
||||||
);
|
);
|
||||||
|
|
||||||
updateDoc.clear();
|
updateDoc.clear();
|
||||||
|
|
||||||
// Update Spool weight
|
// Update Spool weight now handled sequentially in sendToApi task
|
||||||
//TBD: how to handle this with spool and locatin tags? Also potential parallel access again
|
// to prevent parallel API access issues
|
||||||
//if (weight > 10) updateSpoolWeight(doc["sm_id"].as<String>(), weight);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user