Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit 8184185

Browse files
authored
feat: store initial config
1 parent 4928c58 commit 8184185

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/ConfigManager.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ void ConfigManager::setup() {
7676
}
7777

7878
void ConfigManager::loop() {
79-
8079
if (this->getMode() == ap) {
81-
if (apTimeout > 0 &&
82-
((millis() - apStart) / 1000) > (uint16_t)apTimeout) {
80+
if (apTimeout > 0 && ((millis() - apStart) / 1000) > (uint16_t)apTimeout) {
8381
ESP.restart();
8482
}
8583

@@ -234,8 +232,7 @@ bool ConfigManager::wifiConnect(char* ssid, char* password) {
234232
return connected;
235233
}
236234

237-
void ConfigManager::storeWifiSettings(String ssid,
238-
String password) {
235+
void ConfigManager::storeWifiSettings(String ssid, String password) {
239236
char ssidChar[SSID_LENGTH];
240237
char passwordChar[PASSWORD_LENGTH];
241238

@@ -380,6 +377,7 @@ void ConfigManager::writeConfig() {
380377
}
381378
this->commitChanges();
382379
}
380+
383381
void ConfigManager::save() {
384382
this->writeConfig();
385383
}
@@ -461,7 +459,7 @@ void ConfigManager::streamFile(const char* file, const char mime[]) {
461459
f = SPIFFS.open(file, "r");
462460
} else {
463461
size_t len = strlen(file);
464-
char filepath[len+1];
462+
char filepath[len + 1];
465463
strcpy(filepath, "/");
466464
strcat(filepath, file);
467465
f = SPIFFS.open(filepath, "r");
@@ -475,7 +473,6 @@ void ConfigManager::streamFile(const char* file, const char mime[]) {
475473
DebugPrintln(file);
476474
handleNotFound();
477475
}
478-
479476
}
480477

481478
void ConfigManager::handleAPGet() {
@@ -505,9 +502,13 @@ void ConfigManager::handleAPPost() {
505502
}
506503

507504
storeWifiSettings(ssid, password);
505+
if (this->getMode() != station) {
506+
this->writeConfig();
507+
}
508508

509509
server->send(204, FPSTR(mimePlain), F("Saved. Will attempt to reboot."));
510-
delay(500); // Allow enough time for the response to be sent before restarting.
510+
// Allow enough time for the response to be sent before restarting.
511+
delay(500);
511512

512513
ESP.restart();
513514
}

src/ConfigManager.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ class ConfigParameter : public BaseParameter {
7272

7373
ParameterMode getMode() { return this->mode; }
7474

75-
void update(T value) {
76-
*ptr = value;
77-
}
75+
void update(T value) { *ptr = value; }
7876

7977
void fromJson(JsonObject* json) {
8078
if (json->containsKey(name) && json->getMember(name).is<T>()) {
@@ -125,12 +123,12 @@ class ConfigStringParameter : public BaseParameter {
125123
void fromJson(JsonObject* json) {
126124
if (json->containsKey(name) && json->getMember(name).is<char*>()) {
127125
const char* value = json->getMember(name).as<const char*>();
128-
this->update(value);
126+
this->update(value);
129127
}
130128
}
131129

132130
void toJson(JsonObject* json) {
133-
json->getOrAddMember(name).set((const char*) ptr);
131+
json->getOrAddMember(name).set((const char*)ptr);
134132
}
135133

136134
void clearData() {

0 commit comments

Comments
 (0)