diff --git a/data/index.html b/data/index.html index 3f6d3ba..136c498 100644 --- a/data/index.html +++ b/data/index.html @@ -227,7 +227,7 @@ Gets or sets the webhook unlock hook - /users + /users GET, POST N/A lists all local / backup user diff --git a/src/settings.cpp b/src/settings.cpp index 0311fba..1b85aff 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -7,8 +7,8 @@ Settings::Settings() : disableDoor(false), doorMode("LATCH") { void Settings::loadFromEEPROM() { settings_preferences.begin("settings", false); - disableDoor = settings_preferences.getBool("disableDoor", false); - doorMode = settings_preferences.getString("doorMode", "LATCH"); + disableDoor = settings_preferences.getBool("dd", false); + doorMode = settings_preferences.getString("dm", "LATCH"); settings_preferences.end(); settings_preferences.begin("t2", false); @@ -30,38 +30,37 @@ void Settings::loadFromEEPROM() { } void Settings::saveSetting(const String& namespaceStr, const String& key, const String& value, const String& typeStr) { + settings_preferences.begin(namespaceStr.c_str(), false); if (typeStr == "bool") { bool currentValue = settings_preferences.getBool(key.c_str()); - bool newValue = value; + bool newValue = (value == "1") ? true : false; if (currentValue != newValue) { - settings_preferences.begin(namespaceStr.c_str(), false); settings_preferences.putBool(key.c_str(), newValue); - settings_preferences.end(); } + } else if (typeStr == "int") { int currentValue = settings_preferences.getInt(key.c_str()); int newValue = atoi(value.c_str()); if (currentValue != newValue) { - settings_preferences.begin(namespaceStr.c_str(), false); settings_preferences.putInt(key.c_str(), newValue); - settings_preferences.end(); } + } else if (typeStr == "float") { float currentValue = settings_preferences.getFloat(key.c_str()); float newValue = atof(value.c_str()); if (currentValue != newValue) { - settings_preferences.begin(namespaceStr.c_str(), false); settings_preferences.putFloat(key.c_str(), newValue); - settings_preferences.end(); } + } else if (typeStr == "string") { String currentValue = settings_preferences.getString(key.c_str()); if (currentValue != value) { - settings_preferences.begin(namespaceStr.c_str(), false); settings_preferences.putString(key.c_str(), value); - settings_preferences.end(); } + + settings_preferences.end(); + } else { // Handle other types here if needed } @@ -71,18 +70,18 @@ void Settings::saveSetting(const String& namespaceStr, const String& key, const void Settings::setDisableDoor(bool value) { if (disableDoor != value) { disableDoor = value; - + #ifdef WIFI #ifdef TINANCE2_BACKEND - tinance2logrequest("Settings::setDisableDoor: " + String(value)); + tinance2logrequest("Settings::setDisableDoor: " + String(disableDoor)); #endif #endif #ifdef SERIAL_DEBUG - Serial.print("Settings::setDisableDoor: " + String(value)); - Serial.println(disableDoor); + Serial.print("Settings::setDisableDoor: " + String(disableDoor)); #endif - saveSetting("settings", "disableDoor", String(disableDoor), "bool"); + + saveSetting("settings", "dd", String(disableDoor), "bool"); } } @@ -104,7 +103,7 @@ void Settings::setDoorMode(const String mode) { #ifdef SERIAL_DEBUG Serial.print("Settings::setDoorMode: " + mode); #endif - saveSetting("settings", "doorMode", doorMode, "string"); + saveSetting("settings", "dm", doorMode, "string"); } } }