small fixes (save settings)
This commit is contained in:
lumapu 2023-03-18 02:12:12 +01:00
parent 57bda044e5
commit d7c06fd5d8
4 changed files with 11 additions and 17 deletions

View file

@ -72,7 +72,7 @@ class app : public IApp, public ah::Scheduler {
mShowRebootRequest = true; // only message on index, no reboot mShowRebootRequest = true; // only message on index, no reboot
mSavePending = true; mSavePending = true;
mSaveReboot = reboot; mSaveReboot = reboot;
once(std::bind(&app::tickSave, this), 2, "save"); once(std::bind(&app::tickSave, this), 3, "save");
return true; return true;
} }
@ -226,11 +226,12 @@ class app : public IApp, public ah::Scheduler {
} }
void tickSave(void) { void tickSave(void) {
mSettings.saveSettings(); if(!mSettings.saveSettings())
mSaveReboot = false;
mSavePending = false; mSavePending = false;
if(mSaveReboot) if(mSaveReboot)
once(std::bind(&app::tickReboot, this), 2, "rboot"); setRebootFlag();
} }
void tickNtpUpdate(void); void tickNtpUpdate(void);

View file

@ -576,18 +576,18 @@ class settings {
obj[F("name")] = cfg->name; obj[F("name")] = cfg->name;
obj[F("sn")] = cfg->serial.u64; obj[F("sn")] = cfg->serial.u64;
for(uint8_t i = 0; i < 4; i++) { for(uint8_t i = 0; i < 4; i++) {
obj[F("yc")][i] = cfg->yieldCor[i]; obj[F("yield")][i] = cfg->yieldCor[i];
obj[F("pwr")][i] = cfg->chMaxPwr[i]; obj[F("pwr")][i] = cfg->chMaxPwr[i];
obj[F("chn")][i] = cfg->chName[i]; obj[F("chName")][i] = cfg->chName[i];
} }
} else { } else {
cfg->enabled = (bool)obj[F("en")]; cfg->enabled = (bool)obj[F("en")];
snprintf(cfg->name, MAX_NAME_LENGTH, "%s", obj[F("name")].as<const char*>()); snprintf(cfg->name, MAX_NAME_LENGTH, "%s", obj[F("name")].as<const char*>());
cfg->serial.u64 = obj[F("sn")]; cfg->serial.u64 = obj[F("sn")];
for(uint8_t i = 0; i < 4; i++) { for(uint8_t i = 0; i < 4; i++) {
cfg->yieldCor[i] = obj[F("yc")][i]; cfg->yieldCor[i] = obj[F("yield")][i];
cfg->chMaxPwr[i] = obj[F("pwr")][i]; cfg->chMaxPwr[i] = obj[F("pwr")][i];
snprintf(cfg->chName[i], MAX_NAME_LENGTH, "%s", obj[F("chn")][i].as<const char*>()); snprintf(cfg->chName[i], MAX_NAME_LENGTH, "%s", obj[F("chName")][i].as<const char*>());
} }
} }
} }

View file

@ -80,7 +80,7 @@ class RestApi {
if(path == "html/system") getHtmlSystem(root); if(path == "html/system") getHtmlSystem(root);
else if(path == "html/logout") getHtmlLogout(root); else if(path == "html/logout") getHtmlLogout(root);
else if(path == "html/save") getHtmlSave(root); else if(path == "html/save") getHtmlSave(root);
else if(path == "html/chk_save") getHtmlChkSave(root); else if(path == "html/chk_save") getHtmlSave(root);
else if(path == "system") getSysInfo(root); else if(path == "system") getSysInfo(root);
else if(path == "generic") getGeneric(root); else if(path == "generic") getGeneric(root);
else if(path == "reboot") getReboot(root); else if(path == "reboot") getReboot(root);
@ -268,13 +268,6 @@ class RestApi {
void getHtmlSave(JsonObject obj) { void getHtmlSave(JsonObject obj) {
getGeneric(obj.createNestedObject(F("generic"))); getGeneric(obj.createNestedObject(F("generic")));
obj[F("refresh")] = 1; obj[F("refresh")] = 1;
obj[F("refresh_url")] = F("/chk_save");
obj[F("html")] = F("saving settings ...");
}
void getHtmlChkSave(JsonObject obj) {
getGeneric(obj.createNestedObject(F("generic")));
obj[F("refresh")] = (mApp->getLastSaveSucceed()) ? 10 : 1;
obj[F("refresh_url")] = mApp->getSavePending() ? F("/chk_save") : F("/setup"); obj[F("refresh_url")] = mApp->getSavePending() ? F("/chk_save") : F("/setup");
if(mApp->getSavePending()) if(mApp->getSavePending())
obj[F("html")] = F("saving settings ..."); obj[F("html")] = F("saving settings ...");

View file

@ -67,8 +67,8 @@ class Web {
mWeb.on("/factory", HTTP_ANY, std::bind(&Web::showFactoryRst, this, std::placeholders::_1)); mWeb.on("/factory", HTTP_ANY, std::bind(&Web::showFactoryRst, this, std::placeholders::_1));
mWeb.on("/setup", HTTP_GET, std::bind(&Web::onSetup, this, std::placeholders::_1)); mWeb.on("/setup", HTTP_GET, std::bind(&Web::onSetup, this, std::placeholders::_1));
mWeb.on("/save", HTTP_ANY, std::bind(&Web::showSave, this, std::placeholders::_1)); mWeb.on("/save", HTTP_POST, std::bind(&Web::showSave, this, std::placeholders::_1));
mWeb.on("/chk_save", HTTP_ANY, std::bind(&Web::onCheckSave, this, std::placeholders::_1)); mWeb.on("/chk_save", HTTP_GET, std::bind(&Web::onCheckSave, this, std::placeholders::_1));
mWeb.on("/live", HTTP_ANY, std::bind(&Web::onLive, this, std::placeholders::_1)); mWeb.on("/live", HTTP_ANY, std::bind(&Web::onLive, this, std::placeholders::_1));
//mWeb.on("/api1", HTTP_POST, std::bind(&Web::showWebApi, this, std::placeholders::_1)); //mWeb.on("/api1", HTTP_POST, std::bind(&Web::showWebApi, this, std::placeholders::_1));