Browse Source

Save settings only if they have changed

fastled
Xose Pérez 8 years ago
parent
commit
2173d1a4e5
2 changed files with 14 additions and 8 deletions
  1. +6
    -0
      code/src/settings.ino
  2. +8
    -8
      code/src/webserver.ino

+ 6
- 0
code/src/settings.ino View File

@ -31,6 +31,9 @@ void settingsSetup() {
[]() {} []() {}
#endif #endif
); );
#if DEBUG
Serial.println("[SETTINGS] Initialized");
#endif
} }
void settingsLoop() { void settingsLoop() {
@ -52,6 +55,9 @@ bool delSetting(const String& key) {
} }
void saveSettings() { void saveSettings() {
#if DEBUG
Serial.println("[SETTINGS] Saving");
#endif
#if not AUTO_SAVE #if not AUTO_SAVE
EEPROM.commit(); EEPROM.commit();
#endif #endif


+ 8
- 8
code/src/webserver.ino View File

@ -156,7 +156,8 @@ void handleSave() {
Serial.println(F("[WEBSERVER] Request: /save")); Serial.println(F("[WEBSERVER] Request: /save"));
#endif #endif
bool disconnectMQTT = false;
bool dirty = false;
bool dirtyMQTT = false;
for (unsigned int i=0; i<server.args(); i++) { for (unsigned int i=0; i<server.args(); i++) {
@ -172,18 +173,17 @@ void handleSave() {
continue; continue;
} }
// Check wether we will have to reconfigure MQTT connection
if (!disconnectMQTT && key.startsWith("mqtt")) {
if (value != getSetting(key)) disconnectMQTT = true;
if (value != getSetting(key)) {
setSetting(key, value);
dirty = true;
if (key.startsWith("mqtt")) dirtyMQTT = true;
} }
if (value != getSetting(key)) setSetting(key, value);
} }
server.send(202, "text/json", "{}"); server.send(202, "text/json", "{}");
saveSettings();
if (dirty) saveSettings();
#if ENABLE_RF #if ENABLE_RF
rfBuildCodes(); rfBuildCodes();
@ -199,7 +199,7 @@ void handleSave() {
wifiDisconnect(); wifiDisconnect();
// else check if we should reconigure MQTT connection // else check if we should reconigure MQTT connection
} else if (disconnectMQTT) {
} else if (dirtyMQTT) {
mqttDisconnect(); mqttDisconnect();
} }


Loading…
Cancel
Save