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


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

@ -156,7 +156,8 @@ void handleSave() {
Serial.println(F("[WEBSERVER] Request: /save"));
#endif
bool disconnectMQTT = false;
bool dirty = false;
bool dirtyMQTT = false;
for (unsigned int i=0; i<server.args(); i++) {
@ -172,18 +173,17 @@ void handleSave() {
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", "{}");
saveSettings();
if (dirty) saveSettings();
#if ENABLE_RF
rfBuildCodes();
@ -199,7 +199,7 @@ void handleSave() {
wifiDisconnect();
// else check if we should reconigure MQTT connection
} else if (disconnectMQTT) {
} else if (dirtyMQTT) {
mqttDisconnect();
}


Loading…
Cancel
Save