diff --git a/wled00/json.cpp b/wled00/json.cpp index 74e12b5470..b4388d27ef 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -520,7 +520,9 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) if (root["win"].isNull() && getVal(root["ps"], presetCycCurr, 1, 250) && presetCycCurr > 0 && presetCycCurr < 251 && presetCycCurr != currentPreset) { DEBUG_PRINTF_P(PSTR("Preset select: %d\n"), presetCycCurr); // b) preset ID only or preset that does not change state (use embedded cycling limits if they exist in getVal()) - applyPreset(presetCycCurr, callMode); // async load from file system (only preset ID was specified) + // async load from file system (only preset ID was specified) + // avoid propogating CALL_MODE_INIT, which may cause accidental recursion + applyPreset(presetCycCurr, callMode == CALL_MODE_INIT ? CALL_MODE_DIRECT_CHANGE : callMode); return stateResponse; } else presetCycCurr = currentPreset; // restore presetCycCurr } diff --git a/wled00/presets.cpp b/wled00/presets.cpp index 9023baf344..e3ad2e9f6a 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -194,8 +194,8 @@ void handlePresets() changePreset = true; } else { if (!fdo["seg"].isNull() || !fdo["on"].isNull() || !fdo["bri"].isNull() || !fdo["nl"].isNull() || !fdo["ps"].isNull() || !fdo[F("playlist")].isNull()) changePreset = true; - if (!(tmpMode == CALL_MODE_BUTTON_PRESET && fdo["ps"].is() && strchr(fdo["ps"].as(),'~') != strrchr(fdo["ps"].as(),'~'))) - fdo.remove("ps"); // remove load request for presets to prevent recursive crash (if not called by button and contains preset cycling string "1~5~") + if (!(tmpMode == CALL_MODE_INIT || (tmpMode == CALL_MODE_BUTTON_PRESET && fdo["ps"].is() && strchr(fdo["ps"].as(),'~') != strrchr(fdo["ps"].as(),'~')))) + fdo.remove("ps"); // remove load request for presets to prevent recursive crash (if not called by boot preset or button which contains preset cycling string "1~5~") deserializeState(fdo, CALL_MODE_NO_NOTIFY, tmpPreset); // may change presetToApply by calling applyPreset() } if (!errorFlag && tmpPreset < 255 && changePreset) currentPreset = tmpPreset; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index eb6019e6bf..493c687700 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -503,6 +503,12 @@ void WLED::setup() if (needsCfgSave) serializeConfigToFS(); // usermods required new parameters; need to wait for strip to be initialised #4752 + if (bootPreset > 0) { + handlePresets(); // handle boot preset + handlePlaylist(); // handle playlist if preset queued one + handlePresets(); // handle presets again to give a chance for anything queued by the boot preset or playlist + } + if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0 && !configBackupExists()) showWelcomePage = true;