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