добавил очередь отправки файлов в сокеты

This commit is contained in:
Dmitry Borisenko
2022-01-19 22:54:33 +01:00
parent 003c130eef
commit 221ad5f5d4
14 changed files with 66 additions and 30 deletions

View File

@@ -35,11 +35,11 @@ void setup() {
#endif
//инициализация mqtt
mqttInit();
// mqttInit();
//создаем объект класса выгружающего json массив из файла
sendConfigJson = new SendJson;
sendWigdetsJson = new SendJson;
sendJsonFiles = new SendJson;
configure("/config.json");
@@ -62,8 +62,7 @@ void loop() {
ts.update();
//отправка json
if (sendConfigJson) sendConfigJson->loop();
if (sendWigdetsJson) sendWigdetsJson->loop();
if (sendJsonFiles) sendJsonFiles->loop();
#ifdef STANDARD_WEB_SERVER
//обработка web сервера

View File

@@ -219,8 +219,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// очередь задавалась бы так: /widgets.json,/config.json,
// хорошая идея на завтра)
if (sendWigdetsJson) sendWigdetsJson->sendFile("/widgets.json", num);
if (sendConfigJson) sendConfigJson->sendFile("/config.json", num);
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
}
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком

View File

@@ -1,5 +1,5 @@
#include "classes/QueueFromStruct.h"
#ifdef QUEUE_FROM_STR
QueueFromStruct::QueueFromStruct() {}
QueueFromStruct::~QueueFromStruct() {}
@@ -24,4 +24,9 @@ QueueItems QueueFromStruct::front() {
return tmpItem;
}
QueueFromStruct* myQueueStruct;
bool QueueFromStruct::empty() {
return queue1.empty();
}
QueueFromStruct* filesQueue;
#endif

View File

@@ -1,18 +1,32 @@
#include "classes/SendJson.h"
SendJson::SendJson() {}
SendJson::SendJson() {
filesQueue = new QueueFromStruct;
}
SendJson::~SendJson() {}
void SendJson::sendFile(String path, uint8_t num) {
_path = path;
_num = num;
file = seekFile(path);
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);
}
void SendJson::loop() {
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;
}
if (file.available()) {
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
sendWs(jsonArrayElement);
} else {
sendingInProgress = false;
}
}
@@ -24,5 +38,4 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
// mqtt send to do
}
SendJson* sendConfigJson;
SendJson* sendWigdetsJson;
SendJson* sendJsonFiles;

View File

@@ -1,3 +1,4 @@
#ifdef QUEUE_FROM_CHAR
#include "classes/QueueFromChar.h"
QueueFromChar::QueueFromChar() {
@@ -40,4 +41,6 @@ String QueueFromChar::getLastCommand() {
return ret;
}
QueueFromChar* myBuf;
// QueueFromChar* myBuf;
#endif

View File

@@ -1,3 +1,4 @@
#ifdef QUEUE_FROM_INST
#include "classes/QueueFromInstance.h"
QueueFromInstance::QueueFromInstance() {}
@@ -25,4 +26,5 @@ QueueInstance QueueFromInstance::front() {
return instance;
}
QueueFromInstance* myQueue;
// QueueFromInstance* myQueue;
#endif

View File

@@ -1,4 +1,4 @@
#include "classes/QueueInst.h"
#include "queue/QueueInst.h"
QueueInstance::QueueInstance(String text) {
_text = text;