Files
IoTManager/src/WebSocket.cpp

53 lines
1.4 KiB
C++
Raw Normal View History

#include "WebSocket.h"
#include "Global.h"
void wsSendSetup() {
2021-12-16 01:35:46 +01:00
SerialPrint("I", F("WS"), F("start send config"));
File file = seekFile("/setup.json");
2021-12-16 01:35:46 +01:00
DynamicJsonDocument doc(2048);
// AsyncWebSocketMessageBuffer(20480);
file.find("[");
do {
deserializeJson(doc, file);
2021-12-16 01:35:46 +01:00
// 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(",", "]"));
2021-12-16 01:35:46 +01:00
SerialPrint("I", F("WS"), F("completed send config"));
}
void wsPublishData(String topic, String data) {
data = "[" + topic + "]" + data;
ws.textAll(data);
}
2021-12-16 01:35:46 +01:00
// 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);
// }
// }
// }