mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
добавил наследника для класса отправки в сокеты
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include "Web.h"
|
||||
#include "сlasses/sendJson.h"
|
||||
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
extern void standWebServerInit();
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
#include "Utils/WiFiUtils.h"
|
||||
#include "AsyncWebServer.h"
|
||||
#include "StandWebServer.h"
|
||||
#include "Web.h"
|
||||
#include "сlasses/sendJson.h"
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include "сlasses/sendJsonWs.h"
|
||||
|
||||
class StreamJsonArray;
|
||||
class SendJson;
|
||||
|
||||
class StreamJsonArray {
|
||||
class SendJson : SendJsonWs {
|
||||
public:
|
||||
StreamJsonArray();
|
||||
~StreamJsonArray();
|
||||
SendJson();
|
||||
~SendJson();
|
||||
|
||||
void sendFile(String path, uint8_t num);
|
||||
|
||||
void loop();
|
||||
|
||||
uint8_t _num;
|
||||
|
||||
private:
|
||||
File file;
|
||||
String _path;
|
||||
uint8_t _num;
|
||||
};
|
||||
|
||||
extern StreamJsonArray* myStreamJsonArray;
|
||||
extern SendJson* mySendJson;
|
||||
12
include/сlasses/sendJsonWs.h
Normal file
12
include/сlasses/sendJsonWs.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
|
||||
class SendJsonWs;
|
||||
|
||||
class SendJsonWs {
|
||||
public:
|
||||
SendJsonWs();
|
||||
~SendJsonWs();
|
||||
|
||||
void send(String& jsonArrayElement, uint8_t& _num);
|
||||
};
|
||||
@@ -211,7 +211,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("/config")) {
|
||||
if (myStreamJsonArray) myStreamJsonArray->sendFile("/config.json", num);
|
||||
if (mySendJson) mySendJson->sendFile("/config.json", num);
|
||||
}
|
||||
|
||||
if (payloadStr.startsWith("/changed")) {
|
||||
|
||||
26
src/Web.cpp
26
src/Web.cpp
@@ -1,26 +0,0 @@
|
||||
#include "Web.h"
|
||||
|
||||
StreamJsonArray::StreamJsonArray() {}
|
||||
|
||||
StreamJsonArray::~StreamJsonArray() {}
|
||||
|
||||
void StreamJsonArray::sendFile(String path, uint8_t num) {
|
||||
_path = path;
|
||||
_num = num;
|
||||
file = seekFile(path);
|
||||
// file.find("[");
|
||||
}
|
||||
|
||||
void StreamJsonArray::loop() {
|
||||
// if (ws.availableForWriteAll()) {
|
||||
if (file.available()) {
|
||||
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
||||
//jsonArrayElement.replace("]}", "]");
|
||||
// Serial.println(jsonArrayElement);
|
||||
standWebSocket.sendTXT(_num, jsonArrayElement);
|
||||
// ws.textAll(jsonArrayElement);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
StreamJsonArray* myStreamJsonArray;
|
||||
@@ -32,7 +32,7 @@ void setup() {
|
||||
#endif
|
||||
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
myStreamJsonArray = new StreamJsonArray;
|
||||
mySendJson = new SendJson;
|
||||
|
||||
//выводим остаток оперативной памяти после старта
|
||||
// 22.12.21 пустой код без wifi остаток = 50.28 kB
|
||||
@@ -52,7 +52,7 @@ void loop() {
|
||||
//обновление задач таскера
|
||||
ts.update();
|
||||
|
||||
if (myStreamJsonArray) myStreamJsonArray->loop();
|
||||
if (mySendJson) mySendJson->loop();
|
||||
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
HTTP.handleClient();
|
||||
|
||||
21
src/сlasses/sendJson.cpp
Normal file
21
src/сlasses/sendJson.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "сlasses/sendJson.h"
|
||||
|
||||
//базовый класс
|
||||
|
||||
SendJson::SendJson() {}
|
||||
SendJson::~SendJson() {}
|
||||
|
||||
void SendJson::sendFile(String path, uint8_t num) {
|
||||
_path = path;
|
||||
_num = num;
|
||||
file = seekFile(path);
|
||||
}
|
||||
|
||||
void SendJson::loop() {
|
||||
if (file.available()) {
|
||||
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
||||
send(jsonArrayElement, _num);
|
||||
}
|
||||
}
|
||||
|
||||
SendJson* mySendJson;
|
||||
8
src/сlasses/sendJsonWs.cpp
Normal file
8
src/сlasses/sendJsonWs.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "сlasses/sendJsonWs.h"
|
||||
|
||||
SendJsonWs::SendJsonWs() {}
|
||||
SendJsonWs::~SendJsonWs() {}
|
||||
|
||||
void SendJsonWs::send(String& jsonArrayElement, uint8_t& _num) {
|
||||
standWebSocket.sendTXT(_num, jsonArrayElement);
|
||||
}
|
||||
Reference in New Issue
Block a user