mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-28 15:12:19 +03:00
проверка
This commit is contained in:
14
src/Main.cpp
14
src/Main.cpp
@@ -37,9 +37,10 @@ void setup() {
|
||||
//инициализация mqtt
|
||||
mqttInit();
|
||||
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
sendConfigJson = new SendJson;
|
||||
sendWigdetsJson = new SendJson;
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
#ifdef QUEUE_FROM_STR
|
||||
sendJsonFiles = new SendJson;
|
||||
#endif
|
||||
|
||||
configure("/config.json");
|
||||
|
||||
@@ -61,9 +62,10 @@ void loop() {
|
||||
//обновление задач таскера
|
||||
ts.update();
|
||||
|
||||
//отправка json
|
||||
if (sendConfigJson) sendConfigJson->loop();
|
||||
if (sendWigdetsJson) sendWigdetsJson->loop();
|
||||
//отправка json
|
||||
#ifdef QUEUE_FROM_STR
|
||||
if (sendJsonFiles) sendJsonFiles->loop();
|
||||
#endif
|
||||
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
//обработка web сервера
|
||||
|
||||
@@ -218,9 +218,10 @@ 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);
|
||||
#ifdef QUEUE_FROM_STR
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
||||
|
||||
32
src/classes/QueueFromStruct.cpp
Normal file
32
src/classes/QueueFromStruct.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "classes/QueueFromStruct.h"
|
||||
#ifdef QUEUE_FROM_STR
|
||||
QueueFromStruct::QueueFromStruct() {}
|
||||
QueueFromStruct::~QueueFromStruct() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueFromStruct::push(QueueItems word) {
|
||||
queue1.push(word);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueFromStruct::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueItems QueueFromStruct::front() {
|
||||
if (!queue1.empty()) {
|
||||
tmpItem = queue1.front();
|
||||
queue1.pop();
|
||||
}
|
||||
return tmpItem;
|
||||
}
|
||||
|
||||
bool QueueFromStruct::empty() {
|
||||
return queue1.empty();
|
||||
}
|
||||
|
||||
QueueFromStruct* filesQueue;
|
||||
#endif
|
||||
@@ -1,18 +1,33 @@
|
||||
#include "classes/SendJson.h"
|
||||
#ifdef QUEUE_FROM_STR
|
||||
|
||||
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 +39,5 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
|
||||
// mqtt send to do
|
||||
}
|
||||
|
||||
SendJson* sendConfigJson;
|
||||
SendJson* sendWigdetsJson;
|
||||
SendJson* sendJsonFiles;
|
||||
#endif
|
||||
Reference in New Issue
Block a user