реорганизация файлов, перенос лишнего, рабочая версия

This commit is contained in:
Dmitry Borisenko
2022-01-24 22:28:33 +01:00
parent eca80d7dba
commit 9d56087973
10 changed files with 7 additions and 50 deletions

File diff suppressed because one or more lines are too long

View File

@@ -12,8 +12,6 @@
#define STANDARD_WEB_SERVER
#define STANDARD_WEB_SOCKETS
#define QUEUE_FROM_STR
//#define REST_FILE_OPERATIONS
#define MQTT_RECONNECT_INTERVAL 20000

View File

@@ -5,7 +5,6 @@
#include "Utils/WiFiUtils.h"
#include "AsyncWebServer.h"
#include "StandWebServer.h"
#include "classes/SendJson.h"
#include "classes/NotAsync.h"
#include "ESPConfiguration.h"
#include "MqttClient.h"

View File

@@ -1,6 +1,5 @@
#pragma once
#include "Global.h"
#include "classes/SendJson.h"
#ifdef STANDARD_WEB_SERVER
extern void standWebServerInit();
@@ -22,8 +21,6 @@ extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
#endif
#endif
void sendFileToWs(const String& filename, uint8_t num);
void sendFileToWs2(const String& filename, uint8_t num);
void sendFileToWs3(const String& filename, uint8_t num);
void sendFileToWs4(const String& filename, uint8_t num);
void sendFileToWs5(const String& filename, uint8_t num);

View File

@@ -37,11 +37,6 @@ void setup() {
//инициализация mqtt
mqttInit();
//создаем объект класса выгружающего json массив из файла
#ifdef QUEUE_FROM_STR
sendJsonFiles = new SendJson;
#endif
configure("/config.json");
// readFileBin("/config.json");

View File

@@ -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);
}