mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
рабочая версия выгрузки длинного пассива в веб
This commit is contained in:
@@ -61,25 +61,25 @@
|
||||
//#define SSDP_ENABLED
|
||||
|
||||
#ifdef ESP_MODE
|
||||
//#define EnableButtonIn
|
||||
//#define EnableButtonOut
|
||||
//#define EnableCountDown
|
||||
//#define EnableImpulsOut
|
||||
//#define EnableInput
|
||||
//#define EnableLogging
|
||||
//#define EnableOutput
|
||||
//#define EnablePwmOut
|
||||
//#define EnableSensorAnalog
|
||||
//#define EnableSensorBme280
|
||||
//#define EnableSensorBmp280
|
||||
//#define EnableSensorCcs811
|
||||
//#define EnableSensorDallas
|
||||
//#define EnableSensorDht
|
||||
//#define EnableSensorPzem
|
||||
//#define EnableSensorUltrasonic
|
||||
//#define EnableSensorUptime
|
||||
//#define EnableTelegram
|
||||
//#define EnableUart
|
||||
#define EnableButtonIn
|
||||
#define EnableButtonOut
|
||||
#define EnableCountDown
|
||||
#define EnableImpulsOut
|
||||
#define EnableInput
|
||||
#define EnableLogging
|
||||
#define EnableOutput
|
||||
#define EnablePwmOut
|
||||
#define EnableSensorAnalog
|
||||
#define EnableSensorBme280
|
||||
#define EnableSensorBmp280
|
||||
#define EnableSensorCcs811
|
||||
#define EnableSensorDallas
|
||||
#define EnableSensorDht
|
||||
#define EnableSensorPzem
|
||||
#define EnableSensorUltrasonic
|
||||
#define EnableSensorUptime
|
||||
#define EnableTelegram
|
||||
#define EnableUart
|
||||
#endif
|
||||
|
||||
#ifdef GATE_MODE
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
//===================Libraries===================================================================================================================================================
|
||||
#include <Arduino.h>
|
||||
#include "CTBot.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <PubSubClient.h>
|
||||
@@ -10,7 +9,7 @@
|
||||
#include <Wire.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#include "CTBot.h"
|
||||
#include "Clock.h"
|
||||
#include "Consts.h"
|
||||
#include "ESP32.h"
|
||||
@@ -40,6 +39,7 @@ extern AsyncWebServer server;
|
||||
extern boolean just_load;
|
||||
extern boolean telegramInitBeen;
|
||||
extern boolean savedFromWeb;
|
||||
extern boolean wsSetupFlag;
|
||||
|
||||
// Json
|
||||
extern String configSetupJson; //все настройки
|
||||
@@ -68,6 +68,7 @@ extern int currentBroker;
|
||||
|
||||
// orders and events
|
||||
extern String orderBuf;
|
||||
extern String wsBuf;
|
||||
extern String eventBuf;
|
||||
extern String mysensorBuf;
|
||||
extern String itemsFile;
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
#include "Global.h"
|
||||
void wsInit();
|
||||
void wsSendSetup();
|
||||
void wsSendSetupBuffer();
|
||||
void wsPublishData(String topic, String data);
|
||||
void sendDataWs();
|
||||
void loopWsExecute();
|
||||
|
||||
@@ -18,6 +18,7 @@ AsyncWebServer server(80);
|
||||
boolean just_load = true;
|
||||
boolean telegramInitBeen = false;
|
||||
boolean savedFromWeb = false;
|
||||
boolean wsSetupFlag = false;
|
||||
|
||||
// Json
|
||||
String configSetupJson = "{}";
|
||||
@@ -45,6 +46,7 @@ int currentBroker = 1;
|
||||
|
||||
// orders and events
|
||||
String orderBuf = "";
|
||||
String wsBuf = "";
|
||||
String eventBuf = "";
|
||||
String mysensorBuf = "";
|
||||
String itemsFile = "";
|
||||
|
||||
@@ -116,7 +116,8 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
Serial.printf("%s\n", msg.c_str());
|
||||
|
||||
if (msg.startsWith("/config")) {
|
||||
myNotAsyncActions->make(do_webSocketSendSetup);
|
||||
// myNotAsyncActions->make(do_webSocketSendSetup);
|
||||
wsSetupFlag = true;
|
||||
}
|
||||
|
||||
if (info->opcode == WS_TEXT) {
|
||||
|
||||
@@ -1,84 +1,92 @@
|
||||
#include "WebSocket.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
#include "Class/NotAsync.h"
|
||||
#include "Global.h"
|
||||
|
||||
void wsInit() {
|
||||
myNotAsyncActions->add(
|
||||
do_webSocketSendSetup, [&](void*) {
|
||||
wsSendSetup();
|
||||
},
|
||||
nullptr);
|
||||
// myNotAsyncActions->add(
|
||||
// do_webSocketSendSetup, [&](void*) {
|
||||
// delay(100);
|
||||
// wsSendSetup();
|
||||
// },
|
||||
// nullptr);
|
||||
}
|
||||
|
||||
void wsPublishData(String topic, String data) {
|
||||
if (ws.enabled()) {
|
||||
// if (ws.availableForWriteAll()) {
|
||||
data = "[" + topic + "]" + data;
|
||||
ws.textAll(data);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
//отправка setup массива в sockets способом через string
|
||||
void wsSendSetup() {
|
||||
File file = seekFile("/setup.json");
|
||||
|
||||
DynamicJsonDocument doc(2048);
|
||||
|
||||
AsyncWebSocketMessageBuffer(20480);
|
||||
int i = 0;
|
||||
|
||||
file.find("[");
|
||||
|
||||
SerialPrint("I", F("WS"), F("start send config"));
|
||||
do {
|
||||
i++;
|
||||
deserializeJson(doc, file);
|
||||
wsBuf += doc.as<String>() + "\n";
|
||||
// wsPublishData("config", doc.as<String>());
|
||||
// Serial.println(doc.as<String>());
|
||||
} while (file.findUntil(",", "]"));
|
||||
SerialPrint("I", F("WS"), F("completed send config"));
|
||||
}
|
||||
|
||||
// static bool flag = false;
|
||||
void loopWsExecute() {
|
||||
if (wsBuf.length()) {
|
||||
if (ws.availableForWriteAll()) {
|
||||
String tmp = selectToMarker(wsBuf, "\n");
|
||||
wsPublishData("config", tmp);
|
||||
wsBuf = deleteBeforeDelimiter(wsBuf, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//отправка 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()) {
|
||||
while (!ws.availableForWriteAll()) {
|
||||
Serial.println(String(i) + ") not ready");
|
||||
if (ws.availableForWriteAll()) {
|
||||
ws.textAll(buffer);
|
||||
}
|
||||
ws.textAll(buffer);
|
||||
Serial.println(String(i) + ") ready");
|
||||
|
||||
// if (ws.availableForWriteAll()) {
|
||||
// ws.textAll(buffer);
|
||||
// Serial.println(String(i) + ") ready");
|
||||
// } else {
|
||||
// Serial.println(String(i) + ") not ready");
|
||||
// delay(100);
|
||||
// }
|
||||
}
|
||||
}
|
||||
//Serial.println(doc.as<String>());
|
||||
|
||||
// Serial.println(doc.as<String>());
|
||||
} while (file.findUntil(",", "]"));
|
||||
|
||||
SerialPrint("I", F("WS"), F("completed send config"));
|
||||
}
|
||||
|
||||
void wsPublishData(String topic, String data) {
|
||||
if (ws.enabled()) {
|
||||
data = "[" + topic + "]" + data;
|
||||
ws.textAll(data);
|
||||
//Пример прямого доступа к 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);
|
||||
}
|
||||
}
|
||||
|
||||
// wsPublishData(F("config"), doc.as<String>());
|
||||
// if (ws.enabled()) {
|
||||
//}
|
||||
// if (ws.enabled()) Serial.println("on");
|
||||
|
||||
// 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); // creates a buffer (len + 1) for you.
|
||||
// if (buffer) {
|
||||
// serializeJson(doc, (char*)buffer->get(), len);
|
||||
// ws.textAll(buffer);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -109,6 +109,13 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wsSetupFlag) {
|
||||
wsSetupFlag = false;
|
||||
wsSendSetup();
|
||||
}
|
||||
|
||||
loopWsExecute();
|
||||
|
||||
#ifdef OTA_UPDATES_ENABLED
|
||||
ArduinoOTA.handle();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user