mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 04:19:15 +03:00
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
7
data_svelte/lile.json
Normal file
7
data_svelte/lile.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "binary",
|
||||||
|
"subtype": "button-out",
|
||||||
|
"id": "btn1",
|
||||||
|
"gpio": 1,
|
||||||
|
"inv": false
|
||||||
|
}
|
||||||
107
include/Class/TCircularBuffer.h
Normal file
107
include/Class/TCircularBuffer.h
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
template <typename T, size_t BUFFER_SIZE>
|
||||||
|
|
||||||
|
class TCircularBuffer {
|
||||||
|
public:
|
||||||
|
TCircularBuffer() : _head{0}, _tail{0}, _full{false} {}
|
||||||
|
|
||||||
|
~TCircularBuffer() {}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
_head = _tail = _full = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const {
|
||||||
|
return _head == _tail && !_full;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool full() const {
|
||||||
|
return _full;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of elements currently stored in the circular_buffer.
|
||||||
|
*/
|
||||||
|
size_t size() const {
|
||||||
|
size_t res = 0;
|
||||||
|
if (!_full) {
|
||||||
|
if (_head < _tail)
|
||||||
|
res = BUFFER_SIZE + _head - _tail;
|
||||||
|
else
|
||||||
|
res = _head - _tail;
|
||||||
|
} else {
|
||||||
|
res = BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Push the transaction to the buffer. This overwrites the buffer if it's full.
|
||||||
|
* Загрузить данные в буфер
|
||||||
|
* @param data item to be pushed to the buffer.
|
||||||
|
*/
|
||||||
|
void push(const T &item) {
|
||||||
|
if (_full) {
|
||||||
|
_tail++;
|
||||||
|
if (_tail == BUFFER_SIZE)
|
||||||
|
_tail = 0;
|
||||||
|
}
|
||||||
|
_pool[_head++] = item;
|
||||||
|
if (_head == BUFFER_SIZE)
|
||||||
|
_head = 0;
|
||||||
|
if (_head == _tail)
|
||||||
|
_full = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pop from the buffer.
|
||||||
|
* Забрать данные из буфера
|
||||||
|
* @param data item to store the data to be popped from the buffer.
|
||||||
|
* @return True if data popped.
|
||||||
|
*/
|
||||||
|
bool pop(T &item) {
|
||||||
|
bool res = false;
|
||||||
|
if (!empty()) {
|
||||||
|
item = _pool[_tail++];
|
||||||
|
if (_tail == BUFFER_SIZE) _tail = 0;
|
||||||
|
_full = false;
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pop_back(T &item) {
|
||||||
|
bool res = false;
|
||||||
|
if (!empty()) {
|
||||||
|
item = _pool[--_head];
|
||||||
|
_full = false;
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Peek into circular buffer without popping.
|
||||||
|
*
|
||||||
|
* @param data item to be peeked from the buffer.
|
||||||
|
* @return True if the buffer is not empty and data contains a transaction, false otherwise.
|
||||||
|
*/
|
||||||
|
bool peek(T &item) const {
|
||||||
|
bool res = false;
|
||||||
|
if (!empty()) {
|
||||||
|
item = _pool[_tail];
|
||||||
|
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
T _pool[BUFFER_SIZE];
|
||||||
|
size_t _head;
|
||||||
|
size_t _tail;
|
||||||
|
bool _full;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern TCircularBuffer<char *, 1024> *myTCircularBuffer;
|
||||||
|
extern TCircularBuffer<char *, 20480> *myWsBuffer;
|
||||||
@@ -39,6 +39,7 @@ extern AsyncWebServer server;
|
|||||||
extern boolean just_load;
|
extern boolean just_load;
|
||||||
extern boolean telegramInitBeen;
|
extern boolean telegramInitBeen;
|
||||||
extern boolean savedFromWeb;
|
extern boolean savedFromWeb;
|
||||||
|
extern boolean wsSetupFlag;
|
||||||
|
|
||||||
// Json
|
// Json
|
||||||
extern String configSetupJson; //все настройки
|
extern String configSetupJson; //все настройки
|
||||||
@@ -65,8 +66,13 @@ extern int mqttConnectAttempts;
|
|||||||
extern bool changeBroker;
|
extern bool changeBroker;
|
||||||
extern int currentBroker;
|
extern int currentBroker;
|
||||||
|
|
||||||
|
// web sockets
|
||||||
|
extern int wsAttempts;
|
||||||
|
//extern char* wsBufChar;
|
||||||
|
|
||||||
// orders and events
|
// orders and events
|
||||||
extern String orderBuf;
|
extern String orderBuf;
|
||||||
|
extern String wsBuf;
|
||||||
extern String eventBuf;
|
extern String eventBuf;
|
||||||
extern String mysensorBuf;
|
extern String mysensorBuf;
|
||||||
extern String itemsFile;
|
extern String itemsFile;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern void testsPerform();
|
extern void testsPerform();
|
||||||
|
extern void testLoop();
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Class/TCircularBuffer.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
void wsInit();
|
void wsInit();
|
||||||
void wsSendSetup();
|
|
||||||
void wsPublishData(String topic, String data);
|
void wsPublishData(String topic, String data);
|
||||||
|
|
||||||
|
// void wsSendSetup();
|
||||||
|
// void wsSendSetupBuffer();
|
||||||
|
//
|
||||||
|
// void sendDataWs();
|
||||||
|
// void loopWsExecute();
|
||||||
|
|||||||
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;
|
||||||
@@ -18,6 +18,7 @@ AsyncWebServer server(80);
|
|||||||
boolean just_load = true;
|
boolean just_load = true;
|
||||||
boolean telegramInitBeen = false;
|
boolean telegramInitBeen = false;
|
||||||
boolean savedFromWeb = false;
|
boolean savedFromWeb = false;
|
||||||
|
boolean wsSetupFlag = false;
|
||||||
|
|
||||||
// Json
|
// Json
|
||||||
String configSetupJson = "{}";
|
String configSetupJson = "{}";
|
||||||
@@ -43,8 +44,13 @@ int mqttConnectAttempts = 0;
|
|||||||
bool changeBroker = false;
|
bool changeBroker = false;
|
||||||
int currentBroker = 1;
|
int currentBroker = 1;
|
||||||
|
|
||||||
|
// web sockets
|
||||||
|
int wsAttempts = 100;
|
||||||
|
//char* wsBufChar = "";
|
||||||
|
|
||||||
// orders and events
|
// orders and events
|
||||||
String orderBuf = "";
|
String orderBuf = "";
|
||||||
|
String wsBuf = "";
|
||||||
String eventBuf = "";
|
String eventBuf = "";
|
||||||
String mysensorBuf = "";
|
String mysensorBuf = "";
|
||||||
String itemsFile = "";
|
String itemsFile = "";
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ void deviceInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
savedFromWeb = false;
|
savedFromWeb = false;
|
||||||
//publishWidgets();
|
// publishWidgets();
|
||||||
//publishState();
|
// publishState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadScenario() {
|
void loadScenario() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Tests.h"
|
#include "Tests.h"
|
||||||
|
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
#include "Class/TCircularBuffer.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "ItemsList.h"
|
#include "ItemsList.h"
|
||||||
#include "Macro.h"
|
#include "Macro.h"
|
||||||
@@ -8,31 +9,51 @@
|
|||||||
#include "Utils/StringUtils.h"
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
void testsPerform() {
|
void testsPerform() {
|
||||||
//Serial.println("====some tests section====");
|
Serial.println("====some tests section====");
|
||||||
////===========================================================================
|
//ТЕСТ КОЛЬЦЕВОГО БУФЕРА=============================================================================
|
||||||
//String str = "0;1;2;3;4";
|
myTCircularBuffer = new TCircularBuffer<char*, 1024>;
|
||||||
//char* mychar = new char[str.length() + 1];
|
|
||||||
//strcpy(mychar, str.c_str());
|
char* buf = "text";
|
||||||
//test(mychar);
|
|
||||||
////===========================================================================
|
for (int i = 1; i <= 5; i++) {
|
||||||
//String myJson;
|
myTCircularBuffer->push(buf);
|
||||||
//const int capacity = JSON_ARRAY_SIZE(2) + 3 * JSON_OBJECT_SIZE(3);
|
}
|
||||||
//StaticJsonBuffer<capacity> jb;
|
|
||||||
//JsonArray& arr = jb.createArray();
|
char* item;
|
||||||
//JsonObject& obj1 = jb.createObject();
|
|
||||||
//obj1["test1"] = 1;
|
while (myTCircularBuffer->pop(item)) {
|
||||||
//obj1["test2"] = 2;
|
Serial.println(item);
|
||||||
//obj1["test3"] = 3;
|
}
|
||||||
//arr.add(obj1);
|
//===================================================================================================
|
||||||
//arr.printTo(myJson);
|
// String str = "0;1;2;3;4";
|
||||||
//Serial.println(myJson);
|
// char* mychar = new char[str.length() + 1];
|
||||||
|
// strcpy(mychar, str.c_str());
|
||||||
|
// test(mychar);
|
||||||
|
//===========================================================================
|
||||||
|
// String myJson;
|
||||||
|
// const int capacity = JSON_ARRAY_SIZE(2) + 3 * JSON_OBJECT_SIZE(3);
|
||||||
|
// StaticJsonBuffer<capacity> jb;
|
||||||
|
// JsonArray& arr = jb.createArray();
|
||||||
|
// JsonObject& obj1 = jb.createObject();
|
||||||
|
// obj1["test1"] = 1;
|
||||||
|
// obj1["test2"] = 2;
|
||||||
|
// obj1["test3"] = 3;
|
||||||
|
// arr.add(obj1);
|
||||||
|
// arr.printTo(myJson);
|
||||||
|
// Serial.println(myJson);
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
////===========================================================================
|
//===========================================================================
|
||||||
////Serial.println(isDigitDotCommaStr("-12552.5555"));
|
// Serial.println(isDigitDotCommaStr("-12552.5555"));
|
||||||
////String str = "Geeks for Geeks ";
|
// String str = "Geeks for Geeks ";
|
||||||
////Serial.println(itemsCount2(str, " "));
|
// Serial.println(itemsCount2(str, " "));
|
||||||
//
|
//
|
||||||
//Serial.println("==========end============");
|
Serial.println("==========end============");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testLoop() {
|
||||||
|
// char* item;
|
||||||
|
// myCircularBuffer->pop(item);
|
||||||
|
// Serial.println(item);
|
||||||
}
|
}
|
||||||
16
src/Web.cpp
16
src/Web.cpp
@@ -1,4 +1,5 @@
|
|||||||
#include "Web.h"
|
#include "Web.h"
|
||||||
|
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
@@ -174,7 +175,7 @@ void web_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//==============================mqtt settings=============================================
|
//==============================mqtt settings=============================================
|
||||||
//primary
|
// primary
|
||||||
if (request->hasArg(F("mqttServer"))) {
|
if (request->hasArg(F("mqttServer"))) {
|
||||||
jsonWriteStr(configSetupJson, F("mqttServer"), request->getParam(F("mqttServer"))->value());
|
jsonWriteStr(configSetupJson, F("mqttServer"), request->getParam(F("mqttServer"))->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
@@ -206,7 +207,7 @@ void web_init() {
|
|||||||
myNotAsyncActions->make(do_MQTTPARAMSCHANGED);
|
myNotAsyncActions->make(do_MQTTPARAMSCHANGED);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//secondary
|
// secondary
|
||||||
if (request->hasArg(F("mqttServer2"))) {
|
if (request->hasArg(F("mqttServer2"))) {
|
||||||
jsonWriteStr(configSetupJson, F("mqttServer2"), request->getParam(F("mqttServer2"))->value());
|
jsonWriteStr(configSetupJson, F("mqttServer2"), request->getParam(F("mqttServer2"))->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
@@ -240,7 +241,7 @@ void web_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("mqttsend")) {
|
if (request->hasArg("mqttsend")) {
|
||||||
//myNotAsyncActions->make(do_MQTTUDP);
|
// myNotAsyncActions->make(do_MQTTUDP);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +337,7 @@ void web_init() {
|
|||||||
serverIP = jsonReadStr(configSetupJson, "serverip");
|
serverIP = jsonReadStr(configSetupJson, "serverip");
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
//set?order=button_1
|
// set?order=button_1
|
||||||
if (request->hasArg("order")) {
|
if (request->hasArg("order")) {
|
||||||
String order = request->getParam("order")->value();
|
String order = request->getParam("order")->value();
|
||||||
order.replace("_", " ");
|
order.replace("_", " ");
|
||||||
@@ -351,7 +352,7 @@ void web_init() {
|
|||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
//gate mode
|
// gate mode
|
||||||
|
|
||||||
if (request->hasArg("gateAuto")) {
|
if (request->hasArg("gateAuto")) {
|
||||||
bool value = request->getParam("gateAuto")->value().toInt();
|
bool value = request->getParam("gateAuto")->value().toInt();
|
||||||
@@ -359,10 +360,9 @@ void web_init() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
|
// server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
// if (request->hasArg("file") && request->hasArg("line")) {
|
// if (request->hasArg("file") && request->hasArg("line")) {
|
||||||
// String fileName = request->getParam("file")->value();
|
// String fileName = request->getParam("file")->value();
|
||||||
// Serial.println(fileName);
|
// Serial.println(fileName);
|
||||||
@@ -371,7 +371,7 @@ void web_init() {
|
|||||||
// myNotAsyncActions->make(do_delChoosingItems);
|
// myNotAsyncActions->make(do_delChoosingItems);
|
||||||
// request->redirect(F("/?set.device"));
|
// request->redirect(F("/?set.device"));
|
||||||
// }
|
// }
|
||||||
//});
|
// });
|
||||||
|
|
||||||
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
myNotAsyncActions->make(do_GETLASTVERSION);
|
myNotAsyncActions->make(do_GETLASTVERSION);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ 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
|
||||||
@@ -20,6 +19,12 @@ void HttpServerinit() {
|
|||||||
server.addHandler(new FSEditor(login, pass));
|
server.addHandler(new FSEditor(login, pass));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//#ifdef CORS_DEBUG
|
||||||
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Origin"), F("*"));
|
||||||
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Headers"), F("content-type"));
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
// server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||||
server.serveStatic("/css/", FileFS, "/css/").setCacheControl("max-age=600");
|
server.serveStatic("/css/", FileFS, "/css/").setCacheControl("max-age=600");
|
||||||
server.serveStatic("/js/", FileFS, "/js/").setCacheControl("max-age=600");
|
server.serveStatic("/js/", FileFS, "/js/").setCacheControl("max-age=600");
|
||||||
server.serveStatic("/favicon.ico", FileFS, "/favicon.ico").setCacheControl("max-age=600");
|
server.serveStatic("/favicon.ico", FileFS, "/favicon.ico").setCacheControl("max-age=600");
|
||||||
@@ -32,9 +37,17 @@ void HttpServerinit() {
|
|||||||
server.serveStatic("/", FileFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str());
|
server.serveStatic("/", FileFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
|
// SerialPrint("[E]", "WebServer", "not found:\n" + getRequestInfo(request));
|
||||||
|
// request->send(404);
|
||||||
|
//});
|
||||||
|
|
||||||
server.onNotFound([](AsyncWebServerRequest *request) {
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
SerialPrint("[E]", "WebServer", "not found:\n" + getRequestInfo(request));
|
if (request->method() == HTTP_OPTIONS) {
|
||||||
|
request->send(200);
|
||||||
|
} else {
|
||||||
request->send(404);
|
request->send(404);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.onFileUpload([](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) {
|
server.onFileUpload([](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
@@ -47,6 +60,11 @@ void HttpServerinit() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.on("/file.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
|
String file = readFile("file.json", 1024);
|
||||||
|
request->send(200, "application/json", file);
|
||||||
|
});
|
||||||
|
|
||||||
// динамические данные
|
// динамические данные
|
||||||
server.on("/config.live.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
server.on("/config.live.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
request->send(200, "application/json", configLiveJson);
|
request->send(200, "application/json", configLiveJson);
|
||||||
@@ -116,7 +134,8 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
|||||||
Serial.printf("%s\n", msg.c_str());
|
Serial.printf("%s\n", msg.c_str());
|
||||||
|
|
||||||
if (msg.startsWith("/config")) {
|
if (msg.startsWith("/config")) {
|
||||||
myNotAsyncActions->make(do_webSocketSendSetup);
|
// myNotAsyncActions->make(do_webSocketSendSetup);
|
||||||
|
// wsSetupFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->opcode == WS_TEXT) {
|
if (info->opcode == WS_TEXT) {
|
||||||
|
|||||||
@@ -1,39 +1,135 @@
|
|||||||
#include "WebSocket.h"
|
#include "WebSocket.h"
|
||||||
|
|
||||||
|
#include "ArduinoJson.h"
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
|
#include "Class/TCircularBuffer.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
void wsInit() {
|
void wsInit() {
|
||||||
myNotAsyncActions->add(
|
// myWsBuffer = new TCircularBuffer<char*, 20480>;
|
||||||
do_webSocketSendSetup, [&](void*) {
|
// myNotAsyncActions->add(
|
||||||
wsSendSetup();
|
// do_webSocketSendSetup, [&](void*) {
|
||||||
},
|
// delay(100);
|
||||||
nullptr);
|
// wsSendSetup();
|
||||||
|
// },
|
||||||
|
// nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wsSendSetup() {
|
void wsPublishData(String topic, String data) {
|
||||||
SerialPrint("I", F("WS"), F("start send config"));
|
if (ws.enabled()) {
|
||||||
|
if (ws.availableForWriteAll()) {
|
||||||
|
data = "[" + topic + "]" + data;
|
||||||
|
ws.textAll(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//отправка setup массива в sockets способом через буфер string, рабочий способ но буфер стринг - плохой метод
|
||||||
|
void wsSendSetup3() {
|
||||||
File file = seekFile("/setup.json");
|
File file = seekFile("/setup.json");
|
||||||
|
|
||||||
DynamicJsonDocument doc(2048);
|
DynamicJsonDocument doc(2048);
|
||||||
|
int i = 0;
|
||||||
file.find("[");
|
file.find("[");
|
||||||
|
SerialPrint("I", F("WS"), F("start send config"));
|
||||||
do {
|
do {
|
||||||
|
i++;
|
||||||
deserializeJson(doc, file);
|
deserializeJson(doc, file);
|
||||||
|
wsBuf += doc.as<String>() + "\n";
|
||||||
ws.textAll("[config]" + doc.as<char>());
|
|
||||||
|
|
||||||
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wsPublishData(String topic, String data) {
|
void loopWsExecute3() {
|
||||||
data = "[" + topic + "]" + data;
|
static int attampts = wsAttempts;
|
||||||
ws.textAll(data);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wsPublishData(F("config"), doc.as<String>());
|
//отправка setup массива в sockets способом через кольцевой буфер char
|
||||||
// if (ws.enabled()) {
|
// 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 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"));
|
||||||
|
//}
|
||||||
|
|
||||||
|
//Пример прямого доступа к 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);
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
// if (ws.enabled()) Serial.println("on");
|
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@@ -20,6 +20,7 @@
|
|||||||
#include "Utils/Timings.h"
|
#include "Utils/Timings.h"
|
||||||
#include "Utils/WebUtils.h"
|
#include "Utils/WebUtils.h"
|
||||||
#include "WebServer.h"
|
#include "WebServer.h"
|
||||||
|
#include "WebSocket.h"
|
||||||
#include "items/ButtonInClass.h"
|
#include "items/ButtonInClass.h"
|
||||||
#include "items/vCountDown.h"
|
#include "items/vCountDown.h"
|
||||||
#include "items/vImpulsOut.h"
|
#include "items/vImpulsOut.h"
|
||||||
@@ -52,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();
|
||||||
@@ -84,7 +87,7 @@ void setup() {
|
|||||||
|
|
||||||
getFSInfo();
|
getFSInfo();
|
||||||
|
|
||||||
// testsPerform();
|
testsPerform();
|
||||||
|
|
||||||
just_load = false;
|
just_load = false;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
@@ -107,6 +110,16 @@ void loop() {
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testLoop();
|
||||||
|
|
||||||
|
// if (wsSetupFlag) {
|
||||||
|
// wsSetupFlag = false;
|
||||||
|
// wsSendSetup();
|
||||||
|
//}
|
||||||
|
|
||||||
|
// loopWsExecute();
|
||||||
|
|
||||||
#ifdef OTA_UPDATES_ENABLED
|
#ifdef OTA_UPDATES_ENABLED
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user