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")); }