From 5ec1e59957809d9a375fcf477e9a4f611d6e0fa0 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Fri, 28 Jan 2022 00:47:13 +0100 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ESPConfiguration.cpp | 4 ++-- src/StandWebServer.cpp | 7 ++++--- src/utils/FileUtils.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ESPConfiguration.cpp b/src/ESPConfiguration.cpp index a6891696..2743c54d 100644 --- a/src/ESPConfiguration.cpp +++ b/src/ESPConfiguration.cpp @@ -16,7 +16,7 @@ void configure(String path) { if (jsonArrayElement.startsWith(",")) { jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии } - + String subtype; if (!jsonRead(jsonArrayElement, F("subtype"), subtype)) { //если нет такого ключа в представленном json или он не валидный SerialPrint(F("E"), F("Config"), "json error " + subtype); @@ -25,7 +25,7 @@ void configure(String path) { myIoTSensor = (IoTSensor*)getAPI(subtype, jsonArrayElement); if (myIoTSensor) { iotSensors.push_back(myIoTSensor); - createWidget(jsonArrayElement); + // createWidget(jsonArrayElement); } } } diff --git a/src/StandWebServer.cpp b/src/StandWebServer.cpp index 6377eec8..1547472b 100644 --- a/src/StandWebServer.cpp +++ b/src/StandWebServer.cpp @@ -14,11 +14,11 @@ void standWebServerInit() { }); HTTP.on("/config.json", HTTP_GET, []() { - HTTP.send(200, "application/json", readFile(F("config.json"), 10000)); + HTTP.send(200, "application/json", readFile(F("config.json"), 20000)); }); HTTP.on("/layout.json", HTTP_GET, []() { - HTTP.send(200, "application/json", readFile(F("layout.json"), 10000)); + HTTP.send(200, "application/json", readFile(F("layout.json"), 20000)); }); HTTP.on("/restart", HTTP_GET, []() { @@ -291,9 +291,10 @@ void sendFileToWs5(const char* filename, uint8_t num) { auto file = FileFS.open(path, "r"); if (!file) { SerialPrint(F("E"), F("FS"), F("reed file error")); + return; } size_t fileSize = file.size(); - SerialPrint(F("i"), F("WS"), "Send file '" + String(filename) + "', file size: " + String(fileSize)); + SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize)); uint8_t payload[ws_buffer + 1]; int countRead = file.read(payload, sizeof(payload) - 1); while (countRead > 0) { diff --git a/src/utils/FileUtils.cpp b/src/utils/FileUtils.cpp index dfee0dbc..a5319b5d 100644 --- a/src/utils/FileUtils.cpp +++ b/src/utils/FileUtils.cpp @@ -5,11 +5,17 @@ void writeFileUint8(const String& filename, uint8_t*& payload, size_t length, si auto file = FileFS.open(path, "w"); if (!file) { Serial.println(F("failed write file uint8")); + return; } + size_t every = 0; for (size_t i = 0; i < length; i++) { if (i >= headerLenth) { + every++; file.print((char)payload[i]); - yield(); + if (every > 256) { + yield(); + every = 0; + } } } file.close();