From 618b2b5275131c671c3ce33550c12a9fc36bf945 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Thu, 16 Dec 2021 01:35:46 +0100 Subject: [PATCH] test --- data_svelte/setup.json | 534 +++++++++++++++++++++++++++++++++++++- src/Utils/SerialPrint.cpp | 2 +- src/WebServer.cpp | 3 +- src/WebSocket.cpp | 38 ++- 4 files changed, 570 insertions(+), 7 deletions(-) diff --git a/data_svelte/setup.json b/data_svelte/setup.json index 92ca22b3..efa38a10 100644 --- a/data_svelte/setup.json +++ b/data_svelte/setup.json @@ -7,7 +7,7 @@ "inv": false }, { - "type": "sensor", + "type": "sensor1", "subtype": "bme280", "units": "temp", "id": "tmp1", @@ -17,7 +17,537 @@ "s": 0 }, { - "type": "sensor", + "type": "sensor2", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor3", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor4", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor5", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor6", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor7", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor8", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor9", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor10", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor11", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor12", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor13", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor14", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor15", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor16", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor17", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor18", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor19", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor20", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor21", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor22", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor23", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor24", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor25", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor26", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor27", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor28", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor29", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor30", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor31", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor32", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor33", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor34", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor35", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor36", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor37", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor38", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor39", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor40", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor41", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor42", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor43", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor44", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor45", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor46", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor47", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor48", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor49", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor50", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor51", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor52", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor53", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor54", + "subtype": "bme280", + "units": "temp", + "id": "tmp2", + "addr": "0x48", + "int": 10, + "c": 1, + "s": 0 + }, + { + "type": "sensor55", "subtype": "bme280", "units": "temp", "id": "tmp2", diff --git a/src/Utils/SerialPrint.cpp b/src/Utils/SerialPrint.cpp index eb215703..fcf39c46 100644 --- a/src/Utils/SerialPrint.cpp +++ b/src/Utils/SerialPrint.cpp @@ -7,5 +7,5 @@ void SerialPrint(String errorLevel, String module, String msg) { String tosend = prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg; Serial.println(tosend); - wsPublishData(F("log"), tosend); + // wsPublishData(F("log"), tosend); } \ No newline at end of file diff --git a/src/WebServer.cpp b/src/WebServer.cpp index 52ee5076..b388ec9e 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -114,8 +114,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp Serial.printf("%s\n", msg.c_str()); if (msg.startsWith("/config")) { - SerialPrint("I", F("WS"), F("config send")); - wsSendSetup(); + wsSendSetup(); // publishWidgetsWS(); // publishStateWS(); diff --git a/src/WebSocket.cpp b/src/WebSocket.cpp index 05e356b3..0998e6ea 100644 --- a/src/WebSocket.cpp +++ b/src/WebSocket.cpp @@ -3,16 +3,50 @@ #include "Global.h" void wsSendSetup() { + SerialPrint("I", F("WS"), F("start send config")); File file = seekFile("/setup.json"); - DynamicJsonDocument doc(1024); + + DynamicJsonDocument doc(2048); + // AsyncWebSocketMessageBuffer(20480); + file.find("["); do { deserializeJson(doc, file); - wsPublishData(F("config"), doc.as()); + + // wsPublishData(F("config"), doc.as()); + // if (ws.enabled()) { + ws.textAll("[config]" + doc.as()); + //} + + // if (ws.enabled()) Serial.println("on"); + + Serial.println(doc.as()); + } while (file.findUntil(",", "]")); + SerialPrint("I", F("WS"), F("completed send config")); } void wsPublishData(String topic, String data) { data = "[" + topic + "]" + data; ws.textAll(data); } + +// void sendDataWs(AsyncWebSocketClient* client) { +// // DynamicJsonBuffer jsonBuffer; +// // JsonObject& root = jsonBuffer.createObject(); +// // root["a"] = "abc"; +// // root["b"] = "abcd"; +// // root["c"] = "abcde"; +// // root["d"] = "abcdef"; +// // root["e"] = "abcdefg"; +// // size_t len = root.measureLength(); +// AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you. +// if (buffer) { +// root.printTo((char*)buffer->get(), len + 1); +// if (client) { +// client->text(buffer); +// } else { +// ws.textAll(buffer); +// } +// } +// }