mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-24 14:26:11 +02:00
fix upload settings #686
This commit is contained in:
parent
499e1e44f5
commit
2d9f53c941
6 changed files with 49 additions and 94 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -279,25 +279,34 @@
|
|||
|
||||
<div class="row mb-4 mt-4">
|
||||
<div class="col-8 col-sm-3">Reboot device after successful save</div>
|
||||
<div class="col-2 col-md-6">
|
||||
<div class="col-4 col-sm-9">
|
||||
<input type="checkbox" name="reboot" checked />
|
||||
<input type="submit" value="save" class="btn right"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<div class="hr mb-3 mt-3"></div>
|
||||
<div class="mb-4 mt-4">
|
||||
<a class="btn" href="/erase">ERASE SETTINGS (not WiFi)</a>
|
||||
<fieldset class="mb-4">
|
||||
<legend class="des">Upload / Store JSON Settings</legend>
|
||||
<legend class="des">Import / Export JSON Settings</legend>
|
||||
<div class="row mb-4 mt-4">
|
||||
<div class="col-8 col-sm-3">Import</div>
|
||||
<div class="col-4 col-sm-9">
|
||||
<form id="form" method="POST" action="/upload" enctype="multipart/form-data" accept-charset="utf-8">
|
||||
<input type="file" name="upload">
|
||||
<input type="button" class="btn" value="Upload" onclick="hide()">
|
||||
</form>
|
||||
</fieldset>
|
||||
<a class="btn" href="/get_setup" target="_blank">Download settings (JSON file)</a><span> (only saved values, passwords will be removed!)</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="row mb-4 mt-4">
|
||||
<div class="col-8 col-sm-3">Export</div>
|
||||
<div class="col-4 col-sm-9">
|
||||
<a class="btn" href="/get_setup" target="_blank">Download settings (JSON file)</a><span> (only values, passwords will be removed!)</span>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#HTML_FOOTER}
|
||||
|
|
|
@ -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("<!doctype html><html><head><title>Factory Reset</title><meta http-equiv=\"refresh\" content=\"") + String(refresh) + F("; URL=/\"></head><body>") + content + F("</body></html>"));
|
||||
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<InfoCommand>(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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue