diff --git a/src/CHANGES.md b/src/CHANGES.md
index 45179967..c28d4c6b 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -7,6 +7,7 @@
* removed MQTT subscription `sync_ntp`, `set_time` with a value of `0` does the same #696
* simplified MQTT subscription for `limit`. Check [User-Manual.md](../User-Manual.md) for new syntax #696, #713
* repaired inverter wise limit control
+* fix upload settings #686
## 0.5.97
* Attention: re-ordered display types, check your settings! #746
diff --git a/src/app.h b/src/app.h
index 41a77c07..64510eef 100644
--- a/src/app.h
+++ b/src/app.h
@@ -68,9 +68,9 @@ class app : public IApp, public ah::Scheduler {
return Scheduler::getTimestamp();
}
- bool saveSettings() {
- mShowRebootRequest = true;
- return mSettings.saveSettings();
+ bool saveSettings(bool stopFs = false) {
+ mShowRebootRequest = true; // only message on index, no reboot
+ return mSettings.saveSettings(stopFs);
}
bool readSettings(const char *path) {
diff --git a/src/appInterface.h b/src/appInterface.h
index f9a13b03..4c7d6042 100644
--- a/src/appInterface.h
+++ b/src/appInterface.h
@@ -14,7 +14,7 @@
class IApp {
public:
virtual ~IApp() {}
- virtual bool saveSettings() = 0;
+ virtual bool saveSettings(bool stopFs) = 0;
virtual bool readSettings(const char *path) = 0;
virtual bool eraseSettings(bool eraseWifi) = 0;
virtual void setOnUpdate() = 0;
diff --git a/src/config/settings.h b/src/config/settings.h
index 9dcca1c4..fab8327e 100644
--- a/src/config/settings.h
+++ b/src/config/settings.h
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// 2023 Ahoy, https://ahoydtu.de
-// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
+// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
//-----------------------------------------------------------------------------
#ifndef __SETTINGS_H__
@@ -247,7 +247,7 @@ class settings {
return mCfg.valid;
}
- bool saveSettings(void) {
+ bool saveSettings(bool stopFs = false) {
DPRINTLN(DBG_DEBUG, F("save settings"));
File fp = LittleFS.open("/settings.json", "w");
if(!fp) {
@@ -273,6 +273,9 @@ class settings {
}
fp.close();
+ if(stopFs)
+ stop();
+
return true;
}
@@ -280,7 +283,7 @@ class settings {
if(true == eraseWifi)
return LittleFS.format();
loadDefaults(!eraseWifi);
- return saveSettings();
+ return saveSettings(true);
}
private:
@@ -403,6 +406,11 @@ class settings {
mCfg.nrf.pinCe = obj[F("ce")];
mCfg.nrf.pinIrq = obj[F("irq")];
mCfg.nrf.amplifierPower = obj[F("pwr")];
+ if((obj[F("cs")] == obj[F("ce")])) {
+ mCfg.nrf.pinCs = DEF_CS_PIN;
+ mCfg.nrf.pinCe = DEF_CE_PIN;
+ mCfg.nrf.pinIrq = DEF_IRQ_PIN;
+ }
}
}
diff --git a/src/web/html/setup.html b/src/web/html/setup.html
index e3188f05..588fd51b 100644
--- a/src/web/html/setup.html
+++ b/src/web/html/setup.html
@@ -279,25 +279,34 @@
Reboot device after successful save
-
-
-
-
+
+
{#HTML_FOOTER}
diff --git a/src/web/web.h b/src/web/web.h
index fe4a53e6..1b8833bf 100644
--- a/src/web/web.h
+++ b/src/web/web.h
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778
-// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
+// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
//-----------------------------------------------------------------------------
#ifndef __WEB_H__
@@ -170,11 +170,15 @@ class Web {
if (!fp)
mUploadFail = true;
else {
+ char pwd[PWD_LEN];
+ strncpy(pwd, mConfig->sys.stationPwd, PWD_LEN); // backup WiFi PWD
if (!mApp->readSettings("tmp.json")) {
mUploadFail = true;
DPRINTLN(DBG_ERROR, F("upload JSON error!"));
- } else
- mApp->saveSettings();
+ } else {
+ strncpy(mConfig->sys.stationPwd, pwd, PWD_LEN); // restore WiFi PWD
+ mApp->saveSettings(true);
+ }
}
DPRINTLN(DBG_INFO, F("upload finished!"));
}
@@ -414,10 +418,8 @@ class Web {
refresh = 120;
}
request->send(200, F("text/html; charset=UTF-8"), F("Factory Reset") + content + F(""));
- if (refresh == 10) {
- delay(1000);
- ESP.restart();
- }
+ if (refresh == 10)
+ onReboot(request);
}
void onSetup(AsyncWebServerRequest *request) {
@@ -590,7 +592,7 @@ class Web {
mConfig->plugin.display.disp_dc = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : request->arg("disp_dc").toInt();
mConfig->plugin.display.disp_busy = (mConfig->plugin.display.type < 10) ? DEF_PIN_OFF : request->arg("disp_bsy").toInt();
- mApp->saveSettings();
+ mApp->saveSettings((request->arg("reboot") == "on"));
if (request->arg("reboot") == "on")
onReboot(request);
@@ -618,71 +620,6 @@ class Web {
request->send(response);
}
- /*void showWebApi(AsyncWebServerRequest *request) {
- // TODO: remove
- DPRINTLN(DBG_VERBOSE, F("web::showWebApi"));
- DPRINTLN(DBG_DEBUG, request->arg("plain"));
- const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
- DynamicJsonDocument response(capacity);
-
- // Parse JSON object
- deserializeJson(response, request->arg("plain"));
- // ToDo: error handling for payload
- uint8_t iv_id = response["inverter"];
- uint8_t cmd = response["cmd"];
- Inverter<> *iv = mSys->getInverterByPos(iv_id);
- if (NULL != iv) {
- if (response["tx_request"] == (uint8_t)TX_REQ_INFO) {
- // if the AlarmData is requested set the Alarm Index to the requested one
- if (cmd == AlarmData || cmd == AlarmUpdate) {
- // set the AlarmMesIndex for the request from user input
- iv->alarmMesIndex = response["payload"];
- }
- DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(cmd) + F(" and payload ") + String((uint16_t) response["payload"]));
- // process payload from web request corresponding to the cmd
- iv->enqueCommand(cmd);
- }
-
-
- if (response["tx_request"] == (uint8_t)TX_REQ_DEVCONTROL) {
- if (response["cmd"] == (uint8_t)ActivePowerContr) {
- uint16_t webapiPayload = response["payload"];
- uint16_t webapiPayload2 = response["payload2"];
- if (webapiPayload > 0 && webapiPayload < 10000) {
- iv->devControlCmd = ActivePowerContr;
- iv->powerLimit[0] = webapiPayload;
- if (webapiPayload2 > 0)
- iv->powerLimit[1] = webapiPayload2; // dev option, no sanity check
- else // if not set, set it to 0x0000 default
- iv->powerLimit[1] = AbsolutNonPersistent; // payload will be seted temporary in Watt absolut
- if (iv->powerLimit[1] & 0x0001)
- DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("% via REST API"));
- else
- DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("W via REST API"));
- iv->devControlRequest = true; // queue it in the request loop
- }
- }
- if (response["cmd"] == (uint8_t)TurnOff) {
- iv->devControlCmd = TurnOff;
- iv->devControlRequest = true; // queue it in the request loop
- }
- if (response["cmd"] == (uint8_t)TurnOn) {
- iv->devControlCmd = TurnOn;
- iv->devControlRequest = true; // queue it in the request loop
- }
- if (response["cmd"] == (uint8_t)CleanState_LockAndAlarm) {
- iv->devControlCmd = CleanState_LockAndAlarm;
- iv->devControlRequest = true; // queue it in the request loop
- }
- if (response["cmd"] == (uint8_t)Restart) {
- iv->devControlCmd = Restart;
- iv->devControlRequest = true; // queue it in the request loop
- }
- }
- }
- request->send(200, "text/json", "{success:true}");
- }*/
-
void onDebug(AsyncWebServerRequest *request) {
mApp->getSchedulerNames();
AsyncWebServerResponse *response = request->beginResponse(200, F("text/html; charset=UTF-8"), "ok");