Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings and OTA lock state to info #4279

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(wifiLock, ota[F("lock-wifi")]);
CJSON(aOtaEnabled, ota[F("aota")]);
getStringFromJson(otaPass, pwd, 33); //normally not present due to security
interfaceUpdateCallMode = CALL_MODE_WS_SEND;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is necessary to add this here as cfg is only read at boot time.

stateChanged = true;
}

#ifdef WLED_ENABLE_DMX
Expand Down
3 changes: 3 additions & 0 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ void serializeInfo(JsonObject root)
os += 0x40;
#endif

root[F("settingsLocked")] = !correctPIN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shorter text would be preferrable to reduce flash usage.


//os += 0x20; // indicated now removed Blynk support, may be reused to indicate another build-time option

#ifdef USERMOD_CRONIXIE
Expand All @@ -818,6 +820,7 @@ void serializeInfo(JsonObject root)
#endif
#ifndef WLED_DISABLE_OTA
os += 0x01;
root[F("otaLocked")] = otaLock;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the if enclosing is enough (and its bitfield of options).
Adding another key seems wasteful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the docs do not explain how you read this info out of that field, can you at least explain here how to read that value

#endif
root[F("opt")] = os;

Expand Down
2 changes: 2 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
wifiLock = request->hasArg(F("OW"));
aOtaEnabled = request->hasArg(F("AO"));
//createEditHandler(correctPIN && !otaLock);
interfaceUpdateCallMode = CALL_MODE_WS_SEND;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is really necessart to broadcast state/info after settings are saved?
IMO not but I may be missing a usecase.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. If this PR is that you know if the settings value, then you need to send the new value when you save

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it would allow an app using websockets to update its state right away

stateChanged = true;
}
}

Expand Down
6 changes: 5 additions & 1 deletion wled00/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ void checkSettingsPIN(const char* pin) {
if (!correctPIN && millis() - lastEditTime < PIN_RETRY_COOLDOWN) return; // guard against PIN brute force
bool correctBefore = correctPIN;
correctPIN = (strlen(settingsPIN) == 0 || strncmp(settingsPIN, pin, 4) == 0);
if (correctBefore != correctPIN) createEditHandler(correctPIN);
if (correctBefore != correctPIN) {
createEditHandler(correctPIN);
interfaceUpdateCallMode = CALL_MODE_WS_SEND;
stateChanged = true;
}
lastEditTime = millis();
}

Expand Down
1 change: 1 addition & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void WLED::loop()
if (strlen(settingsPIN)>0 && correctPIN && millis() - lastEditTime > PIN_TIMEOUT) {
correctPIN = false;
createEditHandler(false);
interfaceUpdateCallMode = CALL_MODE_WS_SEND; // schedule WS update
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing stateUpdated if we want same behaviour as elsewhere.

}

// reconnect WiFi to clear stale allocations if heap gets too low
Expand Down
Loading