2021-12-16 00:19:08 +01:00
|
|
|
#include "WebSocket.h"
|
|
|
|
|
|
2021-12-16 01:56:14 +01:00
|
|
|
#include "Class/NotAsync.h"
|
2021-12-16 00:19:08 +01:00
|
|
|
#include "Global.h"
|
|
|
|
|
|
2021-12-16 01:56:14 +01:00
|
|
|
void wsInit() {
|
|
|
|
|
myNotAsyncActions->add(
|
|
|
|
|
do_webSocketSendSetup, [&](void*) {
|
|
|
|
|
wsSendSetup();
|
|
|
|
|
},
|
|
|
|
|
nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 00:19:08 +01:00
|
|
|
void wsSendSetup() {
|
2021-12-16 01:35:46 +01:00
|
|
|
SerialPrint("I", F("WS"), F("start send config"));
|
2021-12-16 00:19:08 +01:00
|
|
|
File file = seekFile("/setup.json");
|
2021-12-16 01:35:46 +01:00
|
|
|
|
|
|
|
|
DynamicJsonDocument doc(2048);
|
|
|
|
|
|
2021-12-16 00:19:08 +01:00
|
|
|
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>());
|
|
|
|
|
|
2021-12-16 00:19:08 +01:00
|
|
|
} while (file.findUntil(",", "]"));
|
2021-12-16 01:35:46 +01:00
|
|
|
SerialPrint("I", F("WS"), F("completed send config"));
|
2021-12-16 00:19:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wsPublishData(String topic, String data) {
|
|
|
|
|
data = "[" + topic + "]" + data;
|
|
|
|
|
ws.textAll(data);
|
|
|
|
|
}
|