Browse Source

0.5.102

fix JSON import #775
fix save settings, at least already stored settings are not lost #771
pull/788/head
lumapu 2 years ago
parent
commit
e1326698b9
  1. 1
      src/.vscode/settings.json
  2. 13
      src/CHANGES.md
  3. 31
      src/config/settings.h
  4. 2
      src/defines.h
  5. 2
      src/hm/miPayload.h
  6. 2
      src/web/html/setup.html
  7. 24
      src/web/web.h

1
src/.vscode/settings.json

@ -85,4 +85,5 @@
"stop_token": "cpp",
"thread": "cpp"
},
"cmake.configureOnOpen": false,
}

13
src/CHANGES.md

@ -2,6 +2,19 @@
(starting from release version `0.5.66`)
## 0.5.102
* fix JSON import #775
* fix save settings, at least already stored settings are not lost #771
## 0.5.101
* fix SSD1306
* update documentation
* Update miPayload.h
* Update README.md
* MI - remarks to user manual
* MI - fix AC calc
* MI - fix status msg. analysis
## 0.5.100
* fix add inverter `setup.html` #766
* fix MQTT retained flag for total values #726

31
src/config/settings.h

@ -14,6 +14,12 @@
#include "../utils/dbg.h"
#include "../utils/helper.h"
#if defined(ESP32)
#define MAX_ALLOWED_BUF_SIZE ESP.getMaxAllocHeap() - 2048
#else
#define MAX_ALLOWED_BUF_SIZE ESP.getMaxFreeBlockSize() - 2048
#endif
/**
* More info:
* https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout
@ -224,8 +230,9 @@ class settings {
else {
//DPRINTLN(DBG_INFO, fp.readString());
//fp.seek(0, SeekSet);
DynamicJsonDocument root(5500);
DynamicJsonDocument root(MAX_ALLOWED_BUF_SIZE);
DeserializationError err = deserializeJson(root, fp);
root.shrinkToFit();
if(!err && (root.size() > 0)) {
mCfg.valid = true;
jsonWifi(root[F("wifi")]);
@ -249,13 +256,8 @@ class settings {
bool saveSettings(bool stopFs = false) {
DPRINTLN(DBG_DEBUG, F("save settings"));
File fp = LittleFS.open("/settings.json", "w");
if(!fp) {
DPRINTLN(DBG_ERROR, F("can't open settings file!"));
return false;
}
DynamicJsonDocument json(6500);
DynamicJsonDocument json(MAX_ALLOWED_BUF_SIZE);
JsonObject root = json.to<JsonObject>();
jsonWifi(root.createNestedObject(F("wifi")), true);
jsonNrf(root.createNestedObject(F("nrf")), true);
@ -267,12 +269,27 @@ class settings {
jsonPlugin(root.createNestedObject(F("plugin")), true);
jsonInst(root.createNestedObject(F("inst")), true);
DPRINT(DBG_INFO, "memory usage: ");
DBGPRINTLN(String(json.memoryUsage()));
if(json.overflowed()) {
DPRINTLN(DBG_ERROR, F("buffer too small!"));
return false;
}
File fp = LittleFS.open("/settings.json", "w");
if(!fp) {
DPRINTLN(DBG_ERROR, F("can't open settings file!"));
return false;
}
if(0 == serializeJson(root, fp)) {
DPRINTLN(DBG_ERROR, F("can't write settings file!"));
return false;
}
fp.close();
DPRINTLN(DBG_INFO, F("settings saved"));
if(stopFs)
stop();

2
src/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 101
#define VERSION_PATCH 102
//-------------------------------------
typedef struct {

2
src/hm/miPayload.h

@ -118,7 +118,7 @@ class MiPayload {
//DPRINTLN(DBG_INFO, F("MI got data [0]=") + String(p->packet[0], HEX));
if (p->packet[0] == (0x08 + ALL_FRAMES)) { // 0x88; MI status response to 0x09
miStsDecode(iv, p), CH1;
miStsDecode(iv, p, CH1);
}
else if (p->packet[0] == (0x11 + SINGLE_FRAME)) { // 0x92; MI status response to 0x11

2
src/web/html/setup.html

@ -270,7 +270,7 @@
</div>
<div class="row mb-3">
<div class="col-12 col-sm-3 my-2">Luminance</div>
<div class="col-12 col-sm-9"><input type="number" name="disp_cont" min="1" max="100"></select></div>
<div class="col-12 col-sm-9"><input type="number" name="disp_cont" min="0" max="100"></select></div>
</div>
<p class="des">Pinout</p>
<div id="dispPins"></div>

24
src/web/web.h

@ -161,26 +161,24 @@ class Web {
DPRINTLN(DBG_ERROR, F("can't open file!"));
mUploadFail = true;
mUploadFp.close();
return;
}
}
mUploadFp.write(data, len);
if (final) {
mUploadFp.close();
File fp = LittleFS.open("/tmp.json", "r");
if (!fp)
char pwd[PWD_LEN];
strncpy(pwd, mConfig->sys.stationPwd, PWD_LEN); // backup WiFi PWD
if (!mApp->readSettings("/tmp.json")) {
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 {
strncpy(mConfig->sys.stationPwd, pwd, PWD_LEN); // restore WiFi PWD
mApp->saveSettings(true);
}
DPRINTLN(DBG_ERROR, F("upload JSON error!"));
} else {
LittleFS.remove("/tmp.json");
strncpy(mConfig->sys.stationPwd, pwd, PWD_LEN); // restore WiFi PWD
mApp->saveSettings(true);
}
DPRINTLN(DBG_INFO, F("upload finished!"));
if (!mUploadFail)
DPRINTLN(DBG_INFO, F("upload finished!"));
}
}

Loading…
Cancel
Save