Changes configuration storage of spoolman and bambu values

Change that moves configuration values of spoolman and bambu credentials to use NVS storage. Also fixes some typos and missing translation.
This commit is contained in:
Jan Philipp Ecker
2025-07-27 17:33:09 +02:00
parent 3bb6c1caf5
commit cb5d8ac10a
11 changed files with 158 additions and 157 deletions

View File

@@ -2,6 +2,7 @@
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "commonFS.h"
#include <Preferences.h>
volatile spoolmanApiStateType spoolmanApiState = API_INIT;
//bool spoolman_connected = false;
@@ -565,42 +566,36 @@ bool checkSpoolmanInstance(const String& url) {
return false;
}
bool saveSpoolmanUrl(const String& url, bool octoOn, const String& octoWh, const String& octoTk) {
if (!checkSpoolmanInstance(url)) return false;
bool saveSpoolmanUrl(const String& url, bool octoOn, const String& octo_url, const String& octoTk) {
Preferences preferences;
preferences.begin(NVS_NAMESPACE_API, false); // false = readwrite
preferences.putString(NVS_KEY_SPOOLMAN_URL, url);
preferences.putBool(NVS_KEY_OCTOPRINT_ENABLED, octoOn);
preferences.putString(NVS_KEY_OCTOPRINT_URL, octo_url);
preferences.putString(NVS_KEY_OCTOPRINT_TOKEN, octoTk);
preferences.end();
JsonDocument doc;
doc["url"] = url;
doc["octoEnabled"] = octoOn;
doc["octoUrl"] = octoWh;
doc["octoToken"] = octoTk;
Serial.print("Speichere Spoolman Data in Datei: ");
Serial.println(doc.as<String>());
if (!saveJsonValue("/spoolman_url.json", doc)) {
Serial.println("Fehler beim Speichern der Spoolman-URL.");
return false;
}
//TBD: This could be handled nicer in the future
spoolmanUrl = url;
octoEnabled = octoOn;
octoUrl = octoWh;
octoUrl = octo_url;
octoToken = octoTk;
return true;
}
String loadSpoolmanUrl() {
JsonDocument doc;
if (loadJsonValue("/spoolman_url.json", doc) && doc["url"].is<String>()) {
octoEnabled = (doc["octoEnabled"].is<bool>()) ? doc["octoEnabled"].as<bool>() : false;
if (octoEnabled && doc["octoToken"].is<String>() && doc["octoUrl"].is<String>())
{
octoUrl = doc["octoUrl"].as<String>();
octoToken = doc["octoToken"].as<String>();
}
return doc["url"].as<String>();
Preferences preferences;
preferences.begin(NVS_NAMESPACE_API, true);
String spoolmanUrl = preferences.getString(NVS_KEY_SPOOLMAN_URL, "");
octoEnabled = preferences.getBool(NVS_KEY_OCTOPRINT_ENABLED, false);
if(octoEnabled)
{
octoUrl = preferences.getString(NVS_KEY_OCTOPRINT_URL, "");
octoToken = preferences.getString(NVS_KEY_OCTOPRINT_TOKEN, "");
}
Serial.println("Keine gültige Spoolman-URL gefunden.");
return "";
preferences.end();
return spoolmanUrl;
}
bool initSpoolman() {