mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
откат изменений из-за потери оперативной памяти
This commit is contained in:
@@ -35,11 +35,11 @@ void setup() {
|
||||
#endif
|
||||
|
||||
//инициализация mqtt
|
||||
// mqttInit();
|
||||
mqttInit();
|
||||
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
|
||||
sendJsonFiles = new SendJson;
|
||||
sendConfigJson = new SendJson;
|
||||
sendWigdetsJson = new SendJson;
|
||||
|
||||
configure("/config.json");
|
||||
|
||||
@@ -62,7 +62,8 @@ void loop() {
|
||||
ts.update();
|
||||
|
||||
//отправка json
|
||||
if (sendJsonFiles) sendJsonFiles->loop();
|
||||
if (sendConfigJson) sendConfigJson->loop();
|
||||
if (sendWigdetsJson) sendWigdetsJson->loop();
|
||||
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
//обработка web сервера
|
||||
|
||||
@@ -219,8 +219,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
// очередь задавалась бы так: /widgets.json,/config.json,
|
||||
// хорошая идея на завтра)
|
||||
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
|
||||
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
|
||||
if (sendWigdetsJson) sendWigdetsJson->sendFile("/widgets.json", num);
|
||||
if (sendConfigJson) sendConfigJson->sendFile("/config.json", num);
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#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,32 +1,18 @@
|
||||
#include "classes/SendJson.h"
|
||||
|
||||
SendJson::SendJson() {
|
||||
filesQueue = new QueueFromStruct;
|
||||
}
|
||||
SendJson::SendJson() {}
|
||||
SendJson::~SendJson() {}
|
||||
|
||||
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::sendFile(String path, uint8_t num) {
|
||||
_path = path;
|
||||
_num = num;
|
||||
file = seekFile(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +24,5 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
|
||||
// mqtt send to do
|
||||
}
|
||||
|
||||
SendJson* sendJsonFiles;
|
||||
SendJson* sendConfigJson;
|
||||
SendJson* sendWigdetsJson;
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifdef QUEUE_FROM_CHAR
|
||||
#include "classes/QueueFromChar.h"
|
||||
|
||||
QueueFromChar::QueueFromChar() {
|
||||
commandList = NULL;
|
||||
commandCount = 0;
|
||||
}
|
||||
QueueFromChar::~QueueFromChar() {}
|
||||
|
||||
//добавление команды в буфер
|
||||
void QueueFromChar::addCommand(const char* command) {
|
||||
commandList = (CharBufferStruct*)realloc(commandList, (commandCount + 1) * sizeof(CharBufferStruct));
|
||||
strncpy(commandList[commandCount].command, command, MAX_COMMAND_LENGTH);
|
||||
Serial.println("command added: " + String(command) + " " + String(commandCount));
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
//распечатаем все добавленные команды
|
||||
void QueueFromChar::printCommands() {
|
||||
if (commandCount > 0 && commandList != NULL) {
|
||||
for (int i = 0; i < commandCount; i++) {
|
||||
Serial.println(commandList[i].command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//заберем последнюю из положенных в буфер команд
|
||||
String QueueFromChar::getLastCommand() {
|
||||
String ret = "empty";
|
||||
if (commandList != NULL) {
|
||||
int cnt = commandCount - 1;
|
||||
ret = commandList[cnt].command;
|
||||
if (cnt > 0) {
|
||||
delete commandList[cnt].command;
|
||||
} else if (cnt == 0) {
|
||||
commandList = NULL;
|
||||
}
|
||||
Serial.println("command deleted: " + ret + " " + String(cnt));
|
||||
commandCount--;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// QueueFromChar* myBuf;
|
||||
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include "classes/QueueFromInstance.h"
|
||||
|
||||
QueueFromInstance::QueueFromInstance() {}
|
||||
QueueFromInstance::~QueueFromInstance() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueFromInstance::push(QueueInstance instance) {
|
||||
queue1.push(instance);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueFromInstance::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueInstance QueueFromInstance::front() {
|
||||
QueueInstance instance("");
|
||||
if (!queue1.empty()) {
|
||||
instance = queue1.front();
|
||||
queue1.pop();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
// QueueFromInstance* myQueue;
|
||||
#endif
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "queue/QueueInst.h"
|
||||
|
||||
QueueInstance::QueueInstance(String text) {
|
||||
_text = text;
|
||||
}
|
||||
QueueInstance::~QueueInstance() {}
|
||||
|
||||
String QueueInstance::get() {
|
||||
return _text;
|
||||
}
|
||||
|
||||
//========проверка очереди из экземпляров======
|
||||
|
||||
// myQueue = new QueueFromInstance;
|
||||
|
||||
// myQueue->push(QueueInstance("text1"));
|
||||
// myQueue->push(QueueInstance("text2"));
|
||||
// myQueue->push(QueueInstance("text3"));
|
||||
|
||||
// Serial.println(myQueue->front().get());
|
||||
// Serial.println(myQueue->front().get());
|
||||
// Serial.println(myQueue->front().get());
|
||||
Reference in New Issue
Block a user