mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
websocket try to send array
This commit is contained in:
@@ -4,3 +4,4 @@
|
|||||||
void wsInit();
|
void wsInit();
|
||||||
void wsSendSetup();
|
void wsSendSetup();
|
||||||
void wsPublishData(String topic, String data);
|
void wsPublishData(String topic, String data);
|
||||||
|
void sendDataWs();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "WebSocket.h"
|
#include "WebSocket.h"
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
@@ -12,28 +14,71 @@ void wsInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wsSendSetup() {
|
void wsSendSetup() {
|
||||||
SerialPrint("I", F("WS"), F("start send config"));
|
|
||||||
File file = seekFile("/setup.json");
|
File file = seekFile("/setup.json");
|
||||||
|
|
||||||
DynamicJsonDocument doc(2048);
|
DynamicJsonDocument doc(2048);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
file.find("[");
|
file.find("[");
|
||||||
|
|
||||||
|
SerialPrint("I", F("WS"), F("start send config"));
|
||||||
do {
|
do {
|
||||||
|
i++;
|
||||||
|
|
||||||
|
// static bool flag = false;
|
||||||
deserializeJson(doc, file);
|
deserializeJson(doc, file);
|
||||||
|
size_t len = measureJson(doc);
|
||||||
|
AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len);
|
||||||
|
if (buffer) {
|
||||||
|
serializeJson(doc, (char*)buffer->get(), len);
|
||||||
|
if (ws.enabled()) {
|
||||||
|
while (!ws.availableForWriteAll()) {
|
||||||
|
Serial.println(String(i) + ") not ready");
|
||||||
|
}
|
||||||
|
ws.textAll(buffer);
|
||||||
|
Serial.println(String(i) + ") ready");
|
||||||
|
|
||||||
ws.textAll("[config]" + doc.as<char>());
|
// if (ws.availableForWriteAll()) {
|
||||||
|
// ws.textAll(buffer);
|
||||||
|
// Serial.println(String(i) + ") ready");
|
||||||
|
// } else {
|
||||||
|
// Serial.println(String(i) + ") not ready");
|
||||||
|
// delay(100);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Serial.println(doc.as<String>());
|
||||||
|
|
||||||
Serial.println(doc.as<String>());
|
|
||||||
} while (file.findUntil(",", "]"));
|
} while (file.findUntil(",", "]"));
|
||||||
|
|
||||||
SerialPrint("I", F("WS"), F("completed send config"));
|
SerialPrint("I", F("WS"), F("completed send config"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wsPublishData(String topic, String data) {
|
void wsPublishData(String topic, String data) {
|
||||||
data = "[" + topic + "]" + data;
|
if (ws.enabled()) {
|
||||||
ws.textAll(data);
|
data = "[" + topic + "]" + data;
|
||||||
|
ws.textAll(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wsPublishData(F("config"), doc.as<String>());
|
// wsPublishData(F("config"), doc.as<String>());
|
||||||
// if (ws.enabled()) {
|
// if (ws.enabled()) {
|
||||||
//}
|
//}
|
||||||
// if (ws.enabled()) Serial.println("on");
|
// if (ws.enabled()) Serial.println("on");
|
||||||
|
|
||||||
|
// void sendDataWs() {
|
||||||
|
// DynamicJsonDocument doc(1024);
|
||||||
|
//
|
||||||
|
// doc["a"] = "abc";
|
||||||
|
// doc["b"] = "abcd";
|
||||||
|
// doc["c"] = "abcde";
|
||||||
|
// doc["d"] = "abcdef";
|
||||||
|
// doc["e"] = "abcdefg";
|
||||||
|
// size_t len = measureJson(doc);
|
||||||
|
// AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you.
|
||||||
|
// if (buffer) {
|
||||||
|
// serializeJson(doc, (char*)buffer->get(), len);
|
||||||
|
// ws.textAll(buffer);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "Utils/Timings.h"
|
#include "Utils/Timings.h"
|
||||||
#include "Utils/WebUtils.h"
|
#include "Utils/WebUtils.h"
|
||||||
#include "WebServer.h"
|
#include "WebServer.h"
|
||||||
|
#include "WebSocket.h"
|
||||||
#include "items/ButtonInClass.h"
|
#include "items/ButtonInClass.h"
|
||||||
#include "items/vCountDown.h"
|
#include "items/vCountDown.h"
|
||||||
#include "items/vImpulsOut.h"
|
#include "items/vImpulsOut.h"
|
||||||
@@ -100,13 +101,14 @@ void setup() {
|
|||||||
|
|
||||||
// setupESP();
|
// setupESP();
|
||||||
|
|
||||||
SerialPrint("I", F("System"), F("✔ Initialization completed"));
|
SerialPrint("I", F("System"), F("✔ Initialization completed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OTA_UPDATES_ENABLED
|
#ifdef OTA_UPDATES_ENABLED
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user