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", "stop_token": "cpp",
"thread": "cpp" "thread": "cpp"
}, },
"cmake.configureOnOpen": false,
} }

13
src/CHANGES.md

@ -2,6 +2,19 @@
(starting from release version `0.5.66`) (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 ## 0.5.100
* fix add inverter `setup.html` #766 * fix add inverter `setup.html` #766
* fix MQTT retained flag for total values #726 * fix MQTT retained flag for total values #726

31
src/config/settings.h

@ -14,6 +14,12 @@
#include "../utils/dbg.h" #include "../utils/dbg.h"
#include "../utils/helper.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: * More info:
* https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout * https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout
@ -224,8 +230,9 @@ class settings {
else { else {
//DPRINTLN(DBG_INFO, fp.readString()); //DPRINTLN(DBG_INFO, fp.readString());
//fp.seek(0, SeekSet); //fp.seek(0, SeekSet);
DynamicJsonDocument root(5500); DynamicJsonDocument root(MAX_ALLOWED_BUF_SIZE);
DeserializationError err = deserializeJson(root, fp); DeserializationError err = deserializeJson(root, fp);
root.shrinkToFit();
if(!err && (root.size() > 0)) { if(!err && (root.size() > 0)) {
mCfg.valid = true; mCfg.valid = true;
jsonWifi(root[F("wifi")]); jsonWifi(root[F("wifi")]);
@ -249,13 +256,8 @@ class settings {
bool saveSettings(bool stopFs = false) { bool saveSettings(bool stopFs = false) {
DPRINTLN(DBG_DEBUG, F("save settings")); 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>(); JsonObject root = json.to<JsonObject>();
jsonWifi(root.createNestedObject(F("wifi")), true); jsonWifi(root.createNestedObject(F("wifi")), true);
jsonNrf(root.createNestedObject(F("nrf")), true); jsonNrf(root.createNestedObject(F("nrf")), true);
@ -267,12 +269,27 @@ class settings {
jsonPlugin(root.createNestedObject(F("plugin")), true); jsonPlugin(root.createNestedObject(F("plugin")), true);
jsonInst(root.createNestedObject(F("inst")), 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)) { if(0 == serializeJson(root, fp)) {
DPRINTLN(DBG_ERROR, F("can't write settings file!")); DPRINTLN(DBG_ERROR, F("can't write settings file!"));
return false; return false;
} }
fp.close(); fp.close();
DPRINTLN(DBG_INFO, F("settings saved")); DPRINTLN(DBG_INFO, F("settings saved"));
if(stopFs) if(stopFs)
stop(); stop();

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 101 #define VERSION_PATCH 102
//------------------------------------- //-------------------------------------
typedef struct { 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)); //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 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 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>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12 col-sm-3 my-2">Luminance</div> <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> </div>
<p class="des">Pinout</p> <p class="des">Pinout</p>
<div id="dispPins"></div> <div id="dispPins"></div>

24
src/web/web.h

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