2022-01-14 20:22:52 +01:00
|
|
|
#include "classes/SendJson.h"
|
2022-01-20 13:36:00 +01:00
|
|
|
#ifdef QUEUE_FROM_STR
|
2021-12-28 00:01:01 +01:00
|
|
|
|
2022-01-20 13:36:00 +01:00
|
|
|
SendJson::SendJson() {
|
|
|
|
|
filesQueue = new QueueFromStruct;
|
|
|
|
|
}
|
2021-12-28 00:01:01 +01:00
|
|
|
SendJson::~SendJson() {}
|
|
|
|
|
|
2022-01-20 13:36:00 +01:00
|
|
|
void SendJson::addFileToQueue(String path, uint8_t num) {
|
|
|
|
|
myItem.myword = path;
|
|
|
|
|
myItem.num = num;
|
|
|
|
|
filesQueue->push(myItem);
|
|
|
|
|
SerialPrint(F("i"), F("WS"), "file added to Queue " + path);
|
2021-12-28 00:01:01 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 17:34:11 +01:00
|
|
|
//опсылает массив json по объектно в сокеты
|
2021-12-28 00:01:01 +01:00
|
|
|
void SendJson::loop() {
|
2022-01-20 13:36:00 +01:00
|
|
|
if (!filesQueue->empty() && !sendingInProgress) {
|
|
|
|
|
Serial.println("Queue not empty");
|
|
|
|
|
myItem = filesQueue->front();
|
|
|
|
|
_path = myItem.myword;
|
|
|
|
|
_num = myItem.num;
|
|
|
|
|
file = seekFile(_path);
|
|
|
|
|
SerialPrint(F("i"), F("WS"), "seek File to WS " + _path);
|
|
|
|
|
sendingInProgress = true;
|
|
|
|
|
}
|
2021-12-28 00:01:01 +01:00
|
|
|
if (file.available()) {
|
|
|
|
|
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
2021-12-30 23:58:56 +01:00
|
|
|
sendWs(jsonArrayElement);
|
2022-01-20 13:36:00 +01:00
|
|
|
} else {
|
|
|
|
|
sendingInProgress = false;
|
2021-12-28 00:01:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 23:58:56 +01:00
|
|
|
void SendJson::sendWs(String& jsonArrayElement) {
|
|
|
|
|
standWebSocket.sendTXT(_num, jsonArrayElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SendJson::sendMqtt(String& jsonArrayElement) {
|
|
|
|
|
// mqtt send to do
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-20 13:36:00 +01:00
|
|
|
SendJson* sendJsonFiles;
|
|
|
|
|
#endif
|