mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
много изменений
This commit is contained in:
7
.vscode/extensions.json
vendored
Normal file
7
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
template <typename T, size_t BUFFER_SIZE>
|
||||
|
||||
class CircularBuffer {
|
||||
class TCircularBuffer {
|
||||
public:
|
||||
CircularBuffer() : _head{0}, _tail{0}, _full{false} {}
|
||||
TCircularBuffer() : _head{0}, _tail{0}, _full{false} {}
|
||||
|
||||
~CircularBuffer() {}
|
||||
~TCircularBuffer() {}
|
||||
|
||||
void reset() {
|
||||
_head = _tail = _full = 0;
|
||||
@@ -103,4 +103,5 @@ class CircularBuffer {
|
||||
bool _full;
|
||||
};
|
||||
|
||||
extern CircularBuffer<char *, 20480> *myWsBuffer;
|
||||
extern TCircularBuffer<char *, 1024> *myTCircularBuffer;
|
||||
extern TCircularBuffer<char *, 20480> *myWsBuffer;
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "Class/CircularBuffer.h"
|
||||
#include "Class/TCircularBuffer.h"
|
||||
#include "Global.h"
|
||||
void wsInit();
|
||||
void wsSendSetup();
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "Class/CircularBuffer.h"
|
||||
|
||||
CircularBuffer<char *, 20480> *myWsBuffer;
|
||||
4
src/Class/TCircularBuffer.cpp
Normal file
4
src/Class/TCircularBuffer.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "Class/TCircularBuffer.h"
|
||||
|
||||
TCircularBuffer<char *, 1024> *myTCircularBuffer;
|
||||
TCircularBuffer<char *, 20480> *myWsBuffer;
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Tests.h"
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/CircularBuffer.h"
|
||||
#include "Class/TCircularBuffer.h"
|
||||
#include "Global.h"
|
||||
#include "ItemsList.h"
|
||||
#include "Macro.h"
|
||||
@@ -11,20 +11,19 @@
|
||||
void testsPerform() {
|
||||
Serial.println("====some tests section====");
|
||||
//ТЕСТ КОЛЬЦЕВОГО БУФЕРА=============================================================================
|
||||
// CircularBuffer<char*, 2048>* myCircularBuffer;
|
||||
// myCircularBuffer = new CircularBuffer<char*, 1024>;
|
||||
//
|
||||
// char* buf = "text";
|
||||
//
|
||||
// for (int i = 1; i <= 5; i++) {
|
||||
// myCircularBuffer->push(buf);
|
||||
//}
|
||||
//
|
||||
// char* item;
|
||||
//
|
||||
// while (myCircularBuffer->pop(item)) {
|
||||
// Serial.println(item);
|
||||
//}
|
||||
myTCircularBuffer = new TCircularBuffer<char*, 1024>;
|
||||
|
||||
char* buf = "text";
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
myTCircularBuffer->push(buf);
|
||||
}
|
||||
|
||||
char* item;
|
||||
|
||||
while (myTCircularBuffer->pop(item)) {
|
||||
Serial.println(item);
|
||||
}
|
||||
//===================================================================================================
|
||||
// String str = "0;1;2;3;4";
|
||||
// char* mychar = new char[str.length() + 1];
|
||||
|
||||
@@ -11,7 +11,7 @@ AsyncWebSocket ws("/ws");
|
||||
AsyncEventSource events("/events");
|
||||
|
||||
void HttpServerinit() {
|
||||
wsInit();
|
||||
|
||||
String login = jsonReadStr(configSetupJson, "weblogin");
|
||||
String pass = jsonReadStr(configSetupJson, "webpass");
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "WebSocket.h"
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
#include "Class/CircularBuffer.h"
|
||||
#include "Class/NotAsync.h"
|
||||
#include "Class/TCircularBuffer.h"
|
||||
#include "Global.h"
|
||||
|
||||
void wsInit() {
|
||||
myWsBuffer = new TCircularBuffer<char*, 20480>;
|
||||
// myNotAsyncActions->add(
|
||||
// do_webSocketSendSetup, [&](void*) {
|
||||
// delay(100);
|
||||
@@ -24,104 +25,111 @@ void wsPublishData(String topic, String data) {
|
||||
}
|
||||
|
||||
//отправка setup массива в sockets способом через буфер string, рабочий способ но буфер стринг - плохой метод
|
||||
void wsSendSetup() {
|
||||
File file = seekFile("/setup.json");
|
||||
DynamicJsonDocument doc(2048);
|
||||
int i = 0;
|
||||
file.find("[");
|
||||
SerialPrint("I", F("WS"), F("start send config"));
|
||||
do {
|
||||
i++;
|
||||
deserializeJson(doc, file);
|
||||
wsBuf += doc.as<String>() + "\n";
|
||||
} while (file.findUntil(",", "]"));
|
||||
SerialPrint("I", F("WS"), F("completed send config"));
|
||||
}
|
||||
// void wsSendSetup3() {
|
||||
// File file = seekFile("/setup.json");
|
||||
// DynamicJsonDocument doc(2048);
|
||||
// int i = 0;
|
||||
// file.find("[");
|
||||
// SerialPrint("I", F("WS"), F("start send config"));
|
||||
// do {
|
||||
// i++;
|
||||
// deserializeJson(doc, file);
|
||||
// wsBuf += doc.as<String>() + "\n";
|
||||
// } while (file.findUntil(",", "]"));
|
||||
// SerialPrint("I", F("WS"), F("completed send config"));
|
||||
//}
|
||||
|
||||
void loopWsExecute() {
|
||||
static int attampts = wsAttempts;
|
||||
if (wsBuf.length()) {
|
||||
if (attampts > 0) {
|
||||
if (ws.availableForWriteAll()) {
|
||||
String tmp = selectToMarker(wsBuf, "\n");
|
||||
wsPublishData("config", tmp);
|
||||
wsBuf = deleteBeforeDelimiter(wsBuf, "\n");
|
||||
attampts = wsAttempts;
|
||||
} else {
|
||||
attampts--;
|
||||
SerialPrint("I", F("WS"), String(attampts));
|
||||
}
|
||||
} else {
|
||||
SerialPrint("I", F("WS"), F("socket fatal error"));
|
||||
attampts = wsAttempts;
|
||||
}
|
||||
}
|
||||
}
|
||||
// void loopWsExecute3() {
|
||||
// static int attampts = wsAttempts;
|
||||
// if (wsBuf.length()) {
|
||||
// if (attampts > 0) {
|
||||
// if (ws.availableForWriteAll()) {
|
||||
// String tmp = selectToMarker(wsBuf, "\n");
|
||||
// wsPublishData("config", tmp);
|
||||
// wsBuf = deleteBeforeDelimiter(wsBuf, "\n");
|
||||
// attampts = wsAttempts;
|
||||
// } else {
|
||||
// attampts--;
|
||||
// SerialPrint("I", F("WS"), String(attampts));
|
||||
// }
|
||||
// } else {
|
||||
// SerialPrint("I", F("WS"), F("socket fatal error"));
|
||||
// attampts = wsAttempts;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//отправка setup массива в sockets способом через кольщевой буфер char
|
||||
void wsSendSetup2() {
|
||||
// myWsBuffer = new CircularBuffer<char*, 20480>;
|
||||
// File file = seekFile("/setup.json");
|
||||
// DynamicJsonDocument doc(2048);
|
||||
// int i = 0;
|
||||
// file.find("[");
|
||||
// SerialPrint("I", F("WS"), F("start send config"));
|
||||
// do {
|
||||
// i++;
|
||||
// deserializeJson(doc, file);
|
||||
// char* element = "";
|
||||
// serializeJson(doc, (char*)element, 1024);
|
||||
// Serial.println(element);
|
||||
// myWsBuffer->push(element);
|
||||
//
|
||||
//} while (file.findUntil(",", "]"));
|
||||
// SerialPrint("I", F("WS"), F("completed send config"));
|
||||
}
|
||||
//отправка setup массива в sockets способом через кольцевой буфер char
|
||||
// void wsSendSetup() {
|
||||
// File file = seekFile("/setup.json");
|
||||
// DynamicJsonDocument doc(2048);
|
||||
// int i = 0;
|
||||
// file.find("[");
|
||||
// SerialPrint("I", F("WS"), F("start send config"));
|
||||
// do {
|
||||
// i++;
|
||||
// deserializeJson(doc, file);
|
||||
// char* element;
|
||||
// char* element = new char[1024];
|
||||
// serializeJson(doc, (char*)element, 1024);
|
||||
// Serial.println(element);
|
||||
//
|
||||
// } while (file.findUntil(",", "]"));
|
||||
// SerialPrint("I", F("WS"), F("completed send config"));
|
||||
//
|
||||
// char* itemsend = "element";
|
||||
// myWsBuffer->push(itemsend);
|
||||
//
|
||||
// char* item;
|
||||
// while (myWsBuffer->pop(item)) {
|
||||
// Serial.println(item);
|
||||
// }
|
||||
//}
|
||||
|
||||
void loopWsExecute2() {
|
||||
// char* item;
|
||||
// if (myWsBuffer->pop(item)) {
|
||||
// Serial.println(item);
|
||||
// }
|
||||
}
|
||||
// void loopWsExecute() {
|
||||
// char* item;
|
||||
// if (myWsBuffer->pop(item)) {
|
||||
// Serial.println(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
//отправка setup массива в sockets способом прямой загрузки в ws buffer
|
||||
void wsSendSetupBuffer() {
|
||||
File file = seekFile("/setup.json");
|
||||
DynamicJsonDocument doc(2048);
|
||||
int i = 0;
|
||||
file.find("[");
|
||||
SerialPrint("I", F("WS"), F("start send config"));
|
||||
do {
|
||||
i++;
|
||||
deserializeJson(doc, file);
|
||||
size_t len = measureJson(doc);
|
||||
AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len);
|
||||
if (buffer) {
|
||||
serializeJson(doc, (char*)buffer->get(), len);
|
||||
if (ws.enabled()) {
|
||||
if (ws.availableForWriteAll()) {
|
||||
ws.textAll(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Serial.println(doc.as<String>());
|
||||
} while (file.findUntil(",", "]"));
|
||||
SerialPrint("I", F("WS"), F("completed send config"));
|
||||
}
|
||||
// void wsSendSetupBuffer() {
|
||||
// File file = seekFile("/setup.json");
|
||||
// DynamicJsonDocument doc(2048);
|
||||
// int i = 0;
|
||||
// file.find("[");
|
||||
// SerialPrint("I", F("WS"), F("start send config"));
|
||||
// do {
|
||||
// i++;
|
||||
// deserializeJson(doc, file);
|
||||
// size_t len = measureJson(doc);
|
||||
// AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len);
|
||||
// if (buffer) {
|
||||
// serializeJson(doc, (char*)buffer->get(), len);
|
||||
// if (ws.enabled()) {
|
||||
// if (ws.availableForWriteAll()) {
|
||||
// ws.textAll(buffer);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// // Serial.println(doc.as<String>());
|
||||
// } while (file.findUntil(",", "]"));
|
||||
// SerialPrint("I", F("WS"), F("completed send config"));
|
||||
//}
|
||||
|
||||
//Пример прямого доступа к web socket buffer переделанный для arduino json 6
|
||||
void sendDataWs() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["a"] = "abc";
|
||||
doc["b"] = "abcd";
|
||||
doc["c"] = "abcde";
|
||||
doc["d"] = "abcdef";
|
||||
doc["e"] = "abcdefg";
|
||||
size_t len = measureJson(doc);
|
||||
AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len);
|
||||
if (buffer) {
|
||||
serializeJson(doc, (char*)buffer->get(), len);
|
||||
ws.textAll(buffer);
|
||||
}
|
||||
}
|
||||
// void sendDataWs() {
|
||||
// DynamicJsonDocument doc(1024);
|
||||
// doc["a"] = "abc";
|
||||
// doc["b"] = "abcd";
|
||||
// doc["c"] = "abcde";
|
||||
// doc["d"] = "abcdef";
|
||||
// doc["e"] = "abcdefg";
|
||||
// size_t len = measureJson(doc);
|
||||
// AsyncWebSocketMessageBuffer* buffer = ws.makeBuffer(len);
|
||||
// if (buffer) {
|
||||
// serializeJson(doc, (char*)buffer->get(), len);
|
||||
// ws.textAll(buffer);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -53,6 +53,8 @@ void setup() {
|
||||
myNotAsyncActions = new NotAsync(do_LAST);
|
||||
myScenario = new Scenario();
|
||||
|
||||
wsInit();
|
||||
|
||||
//=========================================initialisation==============================================================
|
||||
setChipId();
|
||||
fileSystemInit();
|
||||
|
||||
Reference in New Issue
Block a user