mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 04:19:15 +03:00
добавил очередь отправки файлов в сокеты
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
#define USE_LITTLEFS false
|
#define USE_LITTLEFS false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define QUEUE_FROM_STR
|
||||||
|
|
||||||
//задачи таскера
|
//задачи таскера
|
||||||
enum TimerTask_t { WIFI_SCAN,
|
enum TimerTask_t { WIFI_SCAN,
|
||||||
WIFI_MQTT_CONNECTION_CHECK,
|
WIFI_MQTT_CONNECTION_CHECK,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "classes/NotAsync.h"
|
#include "classes/NotAsync.h"
|
||||||
#include "ESPConfiguration.h"
|
#include "ESPConfiguration.h"
|
||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
#include "classes/QueueFromChar.h"
|
//#include "queue/QueueFromChar.h"
|
||||||
#include "classes/QueueFromInstance.h"
|
//#include "queue/QueueFromInstance.h"
|
||||||
|
//#include "queue/QueueInst.h"
|
||||||
#include "classes/QueueFromStruct.h"
|
#include "classes/QueueFromStruct.h"
|
||||||
#include "classes/QueueInst.h"
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#ifdef QUEUE_FROM_STR
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ using namespace std;
|
|||||||
|
|
||||||
struct QueueItems {
|
struct QueueItems {
|
||||||
String myword;
|
String myword;
|
||||||
|
uint8_t num;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QueueFromStruct;
|
class QueueFromStruct;
|
||||||
@@ -19,13 +21,14 @@ class QueueFromStruct {
|
|||||||
void push(QueueItems word);
|
void push(QueueItems word);
|
||||||
void pop();
|
void pop();
|
||||||
QueueItems front();
|
QueueItems front();
|
||||||
|
bool empty();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
queue<QueueItems> queue1;
|
queue<QueueItems> queue1;
|
||||||
QueueItems tmpItem;
|
QueueItems tmpItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern QueueFromStruct* myQueueStruct;
|
extern QueueFromStruct* filesQueue;
|
||||||
|
|
||||||
//=======проверка очереди из структур=================
|
//=======проверка очереди из структур=================
|
||||||
// myQueueStruct = new QueueFromStruct;
|
// 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);
|
// Serial.println(myQueueStruct->front().myword);
|
||||||
// Serial.println(myQueueStruct->front().myword);
|
// Serial.println(myQueueStruct->front().myword);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "classes/QueueFromStruct.h"
|
||||||
|
|
||||||
class SendJson;
|
class SendJson;
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ class SendJson {
|
|||||||
SendJson();
|
SendJson();
|
||||||
~SendJson();
|
~SendJson();
|
||||||
|
|
||||||
void sendFile(String path, uint8_t num);
|
void addFileToQueue(String path, uint8_t num);
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
@@ -16,12 +17,13 @@ class SendJson {
|
|||||||
|
|
||||||
void sendMqtt(String& jsonArrayElement);
|
void sendMqtt(String& jsonArrayElement);
|
||||||
|
|
||||||
uint8_t _num;
|
QueueItems myItem;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
File file;
|
File file;
|
||||||
String _path;
|
String _path;
|
||||||
|
uint8_t _num;
|
||||||
|
bool sendingInProgress = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SendJson* sendConfigJson;
|
extern SendJson* sendJsonFiles;
|
||||||
extern SendJson* sendWigdetsJson;
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#ifdef QUEUE_FROM_CHAR
|
||||||
|
|
||||||
#define MAX_COMMAND_LENGTH 16
|
#define MAX_COMMAND_LENGTH 16
|
||||||
#define BUFFER 128
|
#define BUFFER 128
|
||||||
@@ -25,7 +26,7 @@ class QueueFromChar {
|
|||||||
int commandCount = 0;
|
int commandCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern QueueFromChar* myBuf;
|
// extern QueueFromChar* myBuf;
|
||||||
|
|
||||||
//========проверка очереди=====================
|
//========проверка очереди=====================
|
||||||
// myBuf = new QueueFromChar;
|
// myBuf = new QueueFromChar;
|
||||||
@@ -37,3 +38,5 @@ extern QueueFromChar* myBuf;
|
|||||||
// myBuf->getLastCommand();
|
// myBuf->getLastCommand();
|
||||||
// myBuf->getLastCommand();
|
// myBuf->getLastCommand();
|
||||||
// myBuf->printCommands();
|
// myBuf->printCommands();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "classes/QueueInst.h"
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#ifdef QUEUE_FROM_INST
|
||||||
|
#include "classes/QueueInst.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -21,4 +22,5 @@ class QueueFromInstance {
|
|||||||
queue<QueueInstance> queue1;
|
queue<QueueInstance> queue1;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern QueueFromInstance* myQueue;
|
// extern QueueFromInstance* myQueue;
|
||||||
|
#endif
|
||||||
@@ -35,11 +35,11 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//инициализация mqtt
|
//инициализация mqtt
|
||||||
mqttInit();
|
// mqttInit();
|
||||||
|
|
||||||
//создаем объект класса выгружающего json массив из файла
|
//создаем объект класса выгружающего json массив из файла
|
||||||
sendConfigJson = new SendJson;
|
|
||||||
sendWigdetsJson = new SendJson;
|
sendJsonFiles = new SendJson;
|
||||||
|
|
||||||
configure("/config.json");
|
configure("/config.json");
|
||||||
|
|
||||||
@@ -62,8 +62,7 @@ void loop() {
|
|||||||
ts.update();
|
ts.update();
|
||||||
|
|
||||||
//отправка json
|
//отправка json
|
||||||
if (sendConfigJson) sendConfigJson->loop();
|
if (sendJsonFiles) sendJsonFiles->loop();
|
||||||
if (sendWigdetsJson) sendWigdetsJson->loop();
|
|
||||||
|
|
||||||
#ifdef STANDARD_WEB_SERVER
|
#ifdef STANDARD_WEB_SERVER
|
||||||
//обработка web сервера
|
//обработка web сервера
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
// очередь задавалась бы так: /widgets.json,/config.json,
|
// очередь задавалась бы так: /widgets.json,/config.json,
|
||||||
// хорошая идея на завтра)
|
// хорошая идея на завтра)
|
||||||
|
|
||||||
if (sendWigdetsJson) sendWigdetsJson->sendFile("/widgets.json", num);
|
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/widgets.json", num);
|
||||||
if (sendConfigJson) sendConfigJson->sendFile("/config.json", num);
|
if (sendJsonFiles) sendJsonFiles->addFileToQueue("/config.json", num);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "classes/QueueFromStruct.h"
|
#include "classes/QueueFromStruct.h"
|
||||||
|
#ifdef QUEUE_FROM_STR
|
||||||
QueueFromStruct::QueueFromStruct() {}
|
QueueFromStruct::QueueFromStruct() {}
|
||||||
QueueFromStruct::~QueueFromStruct() {}
|
QueueFromStruct::~QueueFromStruct() {}
|
||||||
|
|
||||||
@@ -24,4 +24,9 @@ QueueItems QueueFromStruct::front() {
|
|||||||
return tmpItem;
|
return tmpItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueFromStruct* myQueueStruct;
|
bool QueueFromStruct::empty() {
|
||||||
|
return queue1.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueFromStruct* filesQueue;
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,18 +1,32 @@
|
|||||||
#include "classes/SendJson.h"
|
#include "classes/SendJson.h"
|
||||||
|
|
||||||
SendJson::SendJson() {}
|
SendJson::SendJson() {
|
||||||
|
filesQueue = new QueueFromStruct;
|
||||||
|
}
|
||||||
SendJson::~SendJson() {}
|
SendJson::~SendJson() {}
|
||||||
|
|
||||||
void SendJson::sendFile(String path, uint8_t num) {
|
void SendJson::addFileToQueue(String path, uint8_t num) {
|
||||||
_path = path;
|
myItem.myword = path;
|
||||||
_num = num;
|
myItem.num = num;
|
||||||
file = seekFile(path);
|
filesQueue->push(myItem);
|
||||||
|
SerialPrint(F("i"), F("WS"), "file added to Queue " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendJson::loop() {
|
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()) {
|
if (file.available()) {
|
||||||
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
||||||
sendWs(jsonArrayElement);
|
sendWs(jsonArrayElement);
|
||||||
|
} else {
|
||||||
|
sendingInProgress = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,5 +38,4 @@ void SendJson::sendMqtt(String& jsonArrayElement) {
|
|||||||
// mqtt send to do
|
// mqtt send to do
|
||||||
}
|
}
|
||||||
|
|
||||||
SendJson* sendConfigJson;
|
SendJson* sendJsonFiles;
|
||||||
SendJson* sendWigdetsJson;
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#ifdef QUEUE_FROM_CHAR
|
||||||
#include "classes/QueueFromChar.h"
|
#include "classes/QueueFromChar.h"
|
||||||
|
|
||||||
QueueFromChar::QueueFromChar() {
|
QueueFromChar::QueueFromChar() {
|
||||||
@@ -40,4 +41,6 @@ String QueueFromChar::getLastCommand() {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueFromChar* myBuf;
|
// QueueFromChar* myBuf;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#ifdef QUEUE_FROM_INST
|
||||||
#include "classes/QueueFromInstance.h"
|
#include "classes/QueueFromInstance.h"
|
||||||
|
|
||||||
QueueFromInstance::QueueFromInstance() {}
|
QueueFromInstance::QueueFromInstance() {}
|
||||||
@@ -25,4 +26,5 @@ QueueInstance QueueFromInstance::front() {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueFromInstance* myQueue;
|
// QueueFromInstance* myQueue;
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "classes/QueueInst.h"
|
#include "queue/QueueInst.h"
|
||||||
|
|
||||||
QueueInstance::QueueInstance(String text) {
|
QueueInstance::QueueInstance(String text) {
|
||||||
_text = text;
|
_text = text;
|
||||||
Reference in New Issue
Block a user