From 715d20c21f8c12f8622181315dfc3f8ca0b94137 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Mon, 13 Dec 2021 02:36:55 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B2=D0=B5=D1=82=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D0=BC=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/WebServer.h | 3 +++ src/WebServer.cpp | 21 +++++++++++++++++++-- src/main.cpp | 4 +++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/WebServer.h b/include/WebServer.h index 5c96e22a..64c0bcef 100644 --- a/include/WebServer.h +++ b/include/WebServer.h @@ -7,3 +7,6 @@ extern void initMDNS(); extern void HttpServerinitWS(); extern void HttpServerinit(); + +//===========web sockets============================== +extern void sendEspSetupToWS(); \ No newline at end of file diff --git a/src/WebServer.cpp b/src/WebServer.cpp index 514fde05..529def17 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -112,8 +112,10 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp } Serial.printf("%s\n", msg.c_str()); - if (msg.startsWith("HELLO")) { - SerialPrint("I", F("WS"), F("Full update")); + if (msg.startsWith("config")) { + SerialPrint("I", F("WS"), F("config send")); + sendEspSetupToWS(); + // publishWidgetsWS(); // publishStateWS(); // choose_log_date_and_send(); // функцию выгрузки архива с графиком я не сделал. Забираю при выгрузке по MQTT @@ -209,3 +211,18 @@ void HttpServerinitWS() { server.addHandler(&events); #endif } + +//===========web sockets============================== +void sendEspSetupToWS() { + File file = seekFile("/setup.json"); + DynamicJsonDocument doc(1024); + file.find("["); + + do { + deserializeJson(doc, file); + + // Serial.println(doc.as()); + ws.textAll(doc.as()); + + } while (file.findUntil(",", "]")); +} diff --git a/src/main.cpp b/src/main.cpp index 4f794144..e19df772 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,7 +98,9 @@ void setup() { }, nullptr, true); - setupESP(); + // setupESP(); + + sendEspSetupToWS(); SerialPrint("I", F("System"), F("✔ Initialization completed")); }