compiling

This commit is contained in:
Dmitry Borisenko
2021-12-13 00:58:42 +01:00
parent 7486ba7438
commit b8a8290928
188 changed files with 14925 additions and 45 deletions

49
src/SetupESP.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include "SetupESP.h"
void setupESP() {
File file1 = seekFile("/setup.json"); //читаем первый файл из памяти стримом
File file2 = FileFS.open("/setup.json.tmp", "w"); //открыл второй файл для записи
file2.println("[");
// WriteBufferingStream bfile2(file2, 64); //записываем стрим во второй файл для записи
// ReadBufferingStream bfile1{file1, 64}; //стримим первый файл
DynamicJsonDocument doc(1024);
Serial.println("during " + prettyBytes(ESP.getFreeHeap()));
int i = 0;
file1.find("[");
do {
i++;
deserializeJson(doc, file1);
doc["web"]["order"] = i;
serializeJsonPretty(doc, file2);
file2.println(",");
// DeserializationError error =
// if (error) {
// Serial.print("json error: ");
// Serial.println(error.f_str());
// }
Serial.println(
String(i) + ") " +
doc["type"].as<String>() + " " +
doc["set"]["gpio"].as<String>() + " " +
doc["web"]["order"].as<String>());
} while (file1.findUntil(",", "]"));
file2.println("]");
file2.close();
// if (cutFile("/setup.json.tmp", "/setup.json")) Serial.println("file overwrited");
Serial.println("-------------");
Serial.println(readFile("/setup.json.tmp", 20000));
Serial.println("-------------");
}

View File

@@ -180,4 +180,29 @@ const String getConfigFile(uint8_t preset, ConfigType_t type) {
char buf[64];
sprintf(buf, "/conf/%s%03d.txt", (type == CT_CONFIG) ? "c" : "s", preset);
return String(buf);
}
bool cutFile(const String& src, const String& dst) {
String srcPath = filepath(src);
String dstPath = filepath(dst);
Serial.println("cut " + srcPath + " to " + dstPath);
if (!FileFS.exists(srcPath)) {
Serial.println("not exist: " + srcPath);
return false;
}
if (FileFS.exists(dstPath)) {
FileFS.remove(dstPath);
}
auto srcFile = FileFS.open(srcPath, "r");
auto dstFile = FileFS.open(dstPath, "w");
uint8_t buf[512];
while (srcFile.available()) {
size_t len = srcFile.read(buf, 512);
dstFile.write(buf, len);
}
srcFile.close();
dstFile.close();
FileFS.remove(srcPath);
return true;
}

View File

@@ -1,7 +1,7 @@
#include "Utils\SerialPrint.h"
#include "Global.h"
#include "HttpServer.h"
#include "WebServer.h"
void SerialPrint(String errorLevel, String module, String msg) {
String tosend = prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg;

View File

@@ -9,7 +9,6 @@
#include "Cmd.h"
#include "FileSystem.h"
#include "Global.h"
#include "HttpServer.h"
#include "Init.h"
#include "ItemsList.h"
#include "MySensorsDataParse.h"
@@ -20,6 +19,7 @@
#include "Utils/StatUtils.h"
#include "Utils/Timings.h"
#include "Utils/WebUtils.h"
#include "WebServer.h"
#include "items/ButtonInClass.h"
#include "items/vCountDown.h"
#include "items/vImpulsOut.h"
@@ -34,6 +34,9 @@
#include "items/vSensorPzem.h"
#include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h"
//=========================================
#include "SetupESP.h"
#include "WebServer.h"
void not_async_actions();
@@ -66,8 +69,8 @@ void setup() {
#endif
uptime_init();
upgradeInit();
HttpServer::init();
HttpServer::initWS();
HttpServerinit();
HttpServerinitWS();
web_init();
initSt();
busInit();
@@ -95,6 +98,8 @@ void setup() {
},
nullptr, true);
setupESP();
SerialPrint("I", F("System"), F("✔ Initialization completed"));
}