This commit is contained in:
Dmitry Borisenko
2021-12-16 01:35:46 +01:00
parent f7a97c2d36
commit 618b2b5275
4 changed files with 570 additions and 7 deletions

View File

@@ -7,7 +7,7 @@
"inv": false "inv": false
}, },
{ {
"type": "sensor", "type": "sensor1",
"subtype": "bme280", "subtype": "bme280",
"units": "temp", "units": "temp",
"id": "tmp1", "id": "tmp1",
@@ -17,7 +17,537 @@
"s": 0 "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", "subtype": "bme280",
"units": "temp", "units": "temp",
"id": "tmp2", "id": "tmp2",

View File

@@ -7,5 +7,5 @@
void SerialPrint(String errorLevel, String module, String msg) { void SerialPrint(String errorLevel, String module, String msg) {
String tosend = prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg; String tosend = prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg;
Serial.println(tosend); Serial.println(tosend);
wsPublishData(F("log"), tosend); // wsPublishData(F("log"), tosend);
} }

View File

@@ -114,8 +114,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
Serial.printf("%s\n", msg.c_str()); Serial.printf("%s\n", msg.c_str());
if (msg.startsWith("/config")) { if (msg.startsWith("/config")) {
SerialPrint("I", F("WS"), F("config send")); wsSendSetup();
wsSendSetup();
// publishWidgetsWS(); // publishWidgetsWS();
// publishStateWS(); // publishStateWS();

View File

@@ -3,16 +3,50 @@
#include "Global.h" #include "Global.h"
void wsSendSetup() { void wsSendSetup() {
SerialPrint("I", F("WS"), F("start send config"));
File file = seekFile("/setup.json"); File file = seekFile("/setup.json");
DynamicJsonDocument doc(1024);
DynamicJsonDocument doc(2048);
// AsyncWebSocketMessageBuffer(20480);
file.find("["); file.find("[");
do { do {
deserializeJson(doc, file); deserializeJson(doc, file);
wsPublishData(F("config"), doc.as<String>());
// wsPublishData(F("config"), doc.as<String>());
// if (ws.enabled()) {
ws.textAll("[config]" + doc.as<String>());
//}
// if (ws.enabled()) Serial.println("on");
Serial.println(doc.as<String>());
} while (file.findUntil(",", "]")); } while (file.findUntil(",", "]"));
SerialPrint("I", F("WS"), F("completed send config"));
} }
void wsPublishData(String topic, String data) { void wsPublishData(String topic, String data) {
data = "[" + topic + "]" + data; data = "[" + topic + "]" + data;
ws.textAll(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);
// }
// }
// }