mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
реорганизация файлов, перенос лишнего, рабочая версия
This commit is contained in:
@@ -37,11 +37,6 @@ void setup() {
|
||||
//инициализация mqtt
|
||||
mqttInit();
|
||||
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
#ifdef QUEUE_FROM_STR
|
||||
sendJsonFiles = new SendJson;
|
||||
#endif
|
||||
|
||||
configure("/config.json");
|
||||
|
||||
// readFileBin("/config.json");
|
||||
|
||||
@@ -216,14 +216,14 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
payloadStr += (char)payload[i];
|
||||
}
|
||||
|
||||
//если прилетел url страницы /config то отправим widgets.json и config.json
|
||||
if (payloadStr.startsWith("/config")) {
|
||||
//если прилетел url страницы /config то отправим widgets.json и config.json
|
||||
|
||||
sendFileToWs5("/widgets.json", num);
|
||||
sendFileToWs5("/config.json", num);
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("/gifnoc.json")) { //если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл, пока переписываем целеком
|
||||
//если прилетел измененный пакет с меткой /gifnoc (config наоборот) то перепишем файл
|
||||
if (payloadStr.startsWith("/gifnoc.json")) {
|
||||
payloadStr.replace("/gifnoc.json", "");
|
||||
writeFile(F("config.json"), payloadStr);
|
||||
}
|
||||
@@ -282,39 +282,7 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void sendFileToWs(const String& filename, uint8_t num) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
if (!file) {
|
||||
SerialPrint(F("E"), F("FS"), F("reed file error"));
|
||||
}
|
||||
|
||||
size_t fileSize = file.size();
|
||||
|
||||
uint8_t bufuint[fileSize];
|
||||
|
||||
SerialPrint(F("i"), F("WS"), "Send file '" + filename + "', file size: " + String(fileSize));
|
||||
|
||||
long st = millis();
|
||||
int i = 0;
|
||||
while (file.available()) {
|
||||
bufuint[i] = file.read();
|
||||
i++;
|
||||
yield();
|
||||
}
|
||||
long end = millis();
|
||||
SerialPrint(F("i"), F("WS"), "Time '" + String(end - st));
|
||||
|
||||
standWebSocket.sendTXT(num, bufuint, i);
|
||||
}
|
||||
|
||||
void sendFileToWs2(const String& filename, uint8_t num) {
|
||||
String file = readFile(filename, 5000);
|
||||
size_t fileSize = sizeof(file);
|
||||
SerialPrint(F("i"), F("WS"), String(fileSize));
|
||||
standWebSocket.sendTXT(num, file);
|
||||
}
|
||||
|
||||
//посылка данных из файла в string
|
||||
void sendFileToWs3(const String& filename, uint8_t num) {
|
||||
standWebSocket.sendTXT(num, "/st" + filename);
|
||||
size_t ws_buffer = 512;
|
||||
@@ -337,6 +305,7 @@ void sendFileToWs3(const String& filename, uint8_t num) {
|
||||
standWebSocket.sendTXT(num, "/end" + filename);
|
||||
}
|
||||
|
||||
//посылка данных из файла в char
|
||||
void sendFileToWs4(const String& filename, uint8_t num) {
|
||||
standWebSocket.sendTXT(num, "/st" + filename);
|
||||
size_t ws_buffer = 512;
|
||||
@@ -354,9 +323,9 @@ void sendFileToWs4(const String& filename, uint8_t num) {
|
||||
standWebSocket.sendTXT(num, temp, countRead);
|
||||
countRead = file.readBytes(temp, sizeof(temp) - 1);
|
||||
}
|
||||
standWebSocket.sendTXT(num, "/end" + filename);
|
||||
}
|
||||
|
||||
//посылка данных из файла в бинарном виде
|
||||
void sendFileToWs5(const String& filename, uint8_t num) {
|
||||
standWebSocket.sendTXT(num, "/st" + filename);
|
||||
// standWebSocket.createHeader();
|
||||
@@ -375,5 +344,4 @@ void sendFileToWs5(const String& filename, uint8_t num) {
|
||||
standWebSocket.sendBIN(num, payload, countRead); //, true);
|
||||
countRead = file.read(payload, sizeof(payload) - 1);
|
||||
}
|
||||
standWebSocket.sendTXT(num, "/end" + filename);
|
||||
}
|
||||
|
||||
@@ -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,44 +0,0 @@
|
||||
#include "classes/SendJson.h"
|
||||
#ifdef QUEUE_FROM_STR
|
||||
|
||||
SendJson::SendJson() {
|
||||
filesQueue = new QueueFromStruct;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
//опсылает массив json по объектно в сокеты
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void SendJson::sendWs(String& jsonArrayElement) {
|
||||
standWebSocket.sendTXT(_num, jsonArrayElement);
|
||||
}
|
||||
|
||||
void SendJson::sendMqtt(String& jsonArrayElement) {
|
||||
// mqtt send to do
|
||||
}
|
||||
|
||||
SendJson* sendJsonFiles;
|
||||
#endif
|
||||
Reference in New Issue
Block a user