feat: implement backup and restore functionality for Bambu credentials and Spoolman URL
This commit is contained in:
parent
8c5e7e26ac
commit
9eee89fac7
@ -23,6 +23,10 @@ AsyncWebSocket ws("/ws");
|
|||||||
uint8_t lastSuccess = 0;
|
uint8_t lastSuccess = 0;
|
||||||
uint8_t lastHasReadRfidTag = 0;
|
uint8_t lastHasReadRfidTag = 0;
|
||||||
|
|
||||||
|
// Globale Variablen für Config Backups hinzufügen
|
||||||
|
String bambuCredentialsBackup;
|
||||||
|
String spoolmanUrlBackup;
|
||||||
|
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
if (type == WS_EVT_CONNECT) {
|
if (type == WS_EVT_CONNECT) {
|
||||||
Serial.println("Neuer Client verbunden!");
|
Serial.println("Neuer Client verbunden!");
|
||||||
@ -490,23 +494,47 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
|
|
||||||
|
|
||||||
void backupJsonConfigs() {
|
void backupJsonConfigs() {
|
||||||
const char* configs[] = {"/bambu_credentials.json", "/spoolman_url.json"};
|
// Bambu Credentials backup
|
||||||
for (const char* config : configs) {
|
if (SPIFFS.exists("/bambu_credentials.json")) {
|
||||||
if (SPIFFS.exists(config)) {
|
File file = SPIFFS.open("/bambu_credentials.json", "r");
|
||||||
String backupPath = String(config) + ".bak";
|
if (file) {
|
||||||
SPIFFS.remove(backupPath);
|
bambuCredentialsBackup = file.readString();
|
||||||
SPIFFS.rename(config, backupPath);
|
file.close();
|
||||||
|
Serial.println("Bambu credentials backed up");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spoolman URL backup
|
||||||
|
if (SPIFFS.exists("/spoolman_url.json")) {
|
||||||
|
File file = SPIFFS.open("/spoolman_url.json", "r");
|
||||||
|
if (file) {
|
||||||
|
spoolmanUrlBackup = file.readString();
|
||||||
|
file.close();
|
||||||
|
Serial.println("Spoolman URL backed up");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreJsonConfigs() {
|
void restoreJsonConfigs() {
|
||||||
const char* configs[] = {"/bambu_credentials.json", "/spoolman_url.json"};
|
// Restore Bambu credentials
|
||||||
for (const char* config : configs) {
|
if (bambuCredentialsBackup.length() > 0) {
|
||||||
String backupPath = String(config) + ".bak";
|
File file = SPIFFS.open("/bambu_credentials.json", "w");
|
||||||
if (SPIFFS.exists(backupPath)) {
|
if (file) {
|
||||||
SPIFFS.remove(config);
|
file.print(bambuCredentialsBackup);
|
||||||
SPIFFS.rename(backupPath, config);
|
file.close();
|
||||||
|
Serial.println("Bambu credentials restored");
|
||||||
}
|
}
|
||||||
|
bambuCredentialsBackup = ""; // Clear backup
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore Spoolman URL
|
||||||
|
if (spoolmanUrlBackup.length() > 0) {
|
||||||
|
File file = SPIFFS.open("/spoolman_url.json", "w");
|
||||||
|
if (file) {
|
||||||
|
file.print(spoolmanUrlBackup);
|
||||||
|
file.close();
|
||||||
|
Serial.println("Spoolman URL restored");
|
||||||
|
}
|
||||||
|
spoolmanUrlBackup = ""; // Clear backup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user