mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
добавил очередь отправки файлов в сокеты
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#define USE_LITTLEFS false
|
||||
#endif
|
||||
|
||||
#define QUEUE_FROM_STR
|
||||
|
||||
//задачи таскера
|
||||
enum TimerTask_t { WIFI_SCAN,
|
||||
WIFI_MQTT_CONNECTION_CHECK,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "classes/NotAsync.h"
|
||||
#include "ESPConfiguration.h"
|
||||
#include "MqttClient.h"
|
||||
#include "classes/QueueFromChar.h"
|
||||
#include "classes/QueueFromInstance.h"
|
||||
//#include "queue/QueueFromChar.h"
|
||||
//#include "queue/QueueFromInstance.h"
|
||||
//#include "queue/QueueInst.h"
|
||||
#include "classes/QueueFromStruct.h"
|
||||
#include "classes/QueueInst.h"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_STR
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
@@ -7,6 +8,7 @@ using namespace std;
|
||||
|
||||
struct QueueItems {
|
||||
String myword;
|
||||
uint8_t num;
|
||||
};
|
||||
|
||||
class QueueFromStruct;
|
||||
@@ -19,13 +21,14 @@ class QueueFromStruct {
|
||||
void push(QueueItems word);
|
||||
void pop();
|
||||
QueueItems front();
|
||||
bool empty();
|
||||
|
||||
private:
|
||||
queue<QueueItems> queue1;
|
||||
QueueItems tmpItem;
|
||||
};
|
||||
|
||||
extern QueueFromStruct* myQueueStruct;
|
||||
extern QueueFromStruct* filesQueue;
|
||||
|
||||
//=======проверка очереди из структур=================
|
||||
// myQueueStruct = new QueueFromStruct;
|
||||
@@ -39,3 +42,5 @@ extern QueueFromStruct* myQueueStruct;
|
||||
// Serial.println(myQueueStruct->front().myword);
|
||||
// Serial.println(myQueueStruct->front().myword);
|
||||
// Serial.println(myQueueStruct->front().myword);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include "classes/QueueFromStruct.h"
|
||||
|
||||
class SendJson;
|
||||
|
||||
@@ -8,7 +9,7 @@ class SendJson {
|
||||
SendJson();
|
||||
~SendJson();
|
||||
|
||||
void sendFile(String path, uint8_t num);
|
||||
void addFileToQueue(String path, uint8_t num);
|
||||
|
||||
void loop();
|
||||
|
||||
@@ -16,12 +17,13 @@ class SendJson {
|
||||
|
||||
void sendMqtt(String& jsonArrayElement);
|
||||
|
||||
uint8_t _num;
|
||||
QueueItems myItem;
|
||||
|
||||
private:
|
||||
File file;
|
||||
String _path;
|
||||
uint8_t _num;
|
||||
bool sendingInProgress = false;
|
||||
};
|
||||
|
||||
extern SendJson* sendConfigJson;
|
||||
extern SendJson* sendWigdetsJson;
|
||||
extern SendJson* sendJsonFiles;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_CHAR
|
||||
|
||||
#define MAX_COMMAND_LENGTH 16
|
||||
#define BUFFER 128
|
||||
@@ -25,7 +26,7 @@ class QueueFromChar {
|
||||
int commandCount = 0;
|
||||
};
|
||||
|
||||
extern QueueFromChar* myBuf;
|
||||
// extern QueueFromChar* myBuf;
|
||||
|
||||
//========проверка очереди=====================
|
||||
// myBuf = new QueueFromChar;
|
||||
@@ -37,3 +38,5 @@ extern QueueFromChar* myBuf;
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->printCommands();
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "classes/QueueInst.h"
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include "classes/QueueInst.h"
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
@@ -21,4 +22,5 @@ class QueueFromInstance {
|
||||
queue<QueueInstance> queue1;
|
||||
};
|
||||
|
||||
extern QueueFromInstance* myQueue;
|
||||
// extern QueueFromInstance* myQueue;
|
||||
#endif
|
||||
@@ -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 сервера
|
||||
|
||||
@@ -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 наоборот) то перепишем файл, пока переписываем целеком
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "classes/QueueInst.h"
|
||||
#include "queue/QueueInst.h"
|
||||
|
||||
QueueInstance::QueueInstance(String text) {
|
||||
_text = text;
|
||||
Reference in New Issue
Block a user