mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
страница конфигураций в процессе
This commit is contained in:
40
data_svelte/build/bundle.css
Normal file
40
data_svelte/build/bundle.css
Normal file
File diff suppressed because one or more lines are too long
2
data_svelte/build/bundle.js
Normal file
2
data_svelte/build/bundle.js
Normal file
File diff suppressed because one or more lines are too long
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
//Размер буфера json
|
//Размер буфера json
|
||||||
#define JSON_BUFFER_SIZE 2048
|
#define JSON_BUFFER_SIZE 2048
|
||||||
|
#define WEB_SOCKETS_FRAME_SIZE 2048
|
||||||
|
|
||||||
//выбор сервера
|
//выбор сервера
|
||||||
//#define ASYNC_WEB_SERVER
|
//#define ASYNC_WEB_SERVER
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ void sendFileToWs(String filename, int num, size_t frameSize);
|
|||||||
void publishStatusWs(const String& topic, const String& data);
|
void publishStatusWs(const String& topic, const String& data);
|
||||||
void publishChartWs(int num, String& path);
|
void publishChartWs(int num, String& path);
|
||||||
void periodicWsSend();
|
void periodicWsSend();
|
||||||
void sendStringToWs(const String& msg, uint8_t num, String name);
|
|
||||||
void publishChartToWs(String filename, int num, size_t frameSize, int maxCount, String id);
|
void publishChartToWs(String filename, int num, size_t frameSize, int maxCount, String id);
|
||||||
|
|
||||||
|
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize);
|
||||||
void sendBlobToWsStrHeader(const String& filename, const String& header, uint8_t client_id, size_t frameSize);
|
void sendStringToWs(const String& header, String& payload, uint8_t client_id);
|
||||||
|
|
||||||
// void sendMark(const char* filename, const char* mark, uint8_t num);
|
// void sendMark(const char* filename, const char* mark, uint8_t num);
|
||||||
// void sendFileToWs3(const String& filename, uint8_t num);
|
// void sendFileToWs3(const String& filename, uint8_t num);
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ void standWebServerInit() {
|
|||||||
// HTTP.on("/devicelist.json", HTTP_GET, []() {
|
// HTTP.on("/devicelist.json", HTTP_GET, []() {
|
||||||
// HTTP.send(200, "application/json", devListHeapJson);
|
// HTTP.send(200, "application/json", devListHeapJson);
|
||||||
// });
|
// });
|
||||||
// HTTP.on("/settings.h.json", HTTP_GET, []() {
|
HTTP.on("/settings.h.json", HTTP_GET, []() {
|
||||||
// HTTP.send(200, "application/json", settingsFlashJson);
|
HTTP.send(200, "application/json", settingsFlashJson);
|
||||||
// });
|
});
|
||||||
// HTTP.on("/settings.f.json", HTTP_GET, []() {
|
// HTTP.on("/settings.f.json", HTTP_GET, []() {
|
||||||
// HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
// HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
||||||
// });
|
// });
|
||||||
|
|||||||
154
src/WsServer.cpp
154
src/WsServer.cpp
@@ -93,12 +93,14 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
|
|
||||||
//отвечаем данными на запрос страницы
|
//отвечаем данными на запрос страницы
|
||||||
if (headerStr == "/config|") {
|
if (headerStr == "/config|") {
|
||||||
sendFileToWs("/items.json", num, 1024);
|
sendFileToWsByFrames("/items.json", "itemsj", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
sendFileToWs("/widgets.json", num, 1024);
|
sendFileToWsByFrames("/widgets.json", "widget", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
sendFileToWs("/config.json", num, 1024);
|
sendFileToWsByFrames("/config.json", "config", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
sendFileToWs("/scenario.txt", num, 1024);
|
sendFileToWsByFrames("/scenario.txt", "scenar", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
|
sendStringToWs("settin", settingsFlashJson, num);
|
||||||
|
|
||||||
//шлется для того что бы получить топик устройства
|
//шлется для того что бы получить топик устройства
|
||||||
standWebSocket.sendTXT(num, settingsFlashJson);
|
// standWebSocket.sendTXT(num, settingsFlashJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
//отправляем все графики в веб для экспорта
|
//отправляем все графики в веб для экспорта
|
||||||
@@ -222,7 +224,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (headerStr == "/test|") {
|
if (headerStr == "/test|") {
|
||||||
sendBlobToWsStrHeader("/items.json", "layout|0000|", num, 2048);
|
sendFileToWsByFrames("/items.json", "itemsj", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
|
sendFileToWsByFrames("/widgets.json", "widget", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
|
sendFileToWsByFrames("/config.json", "config", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
|
sendFileToWsByFrames("/scenario.txt", "scenar", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -350,16 +355,16 @@ void sendFileToWs(String filename, int num, size_t frameSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//посылка данных из string
|
//посылка данных из string
|
||||||
void sendStringToWs(const String& msg, uint8_t num, String name) {
|
// void sendStringToWs(const String& msg, uint8_t num, String name) {
|
||||||
String st = "/st" + String(name);
|
// String st = "/st" + String(name);
|
||||||
standWebSocket.sendTXT(num, st);
|
// standWebSocket.sendTXT(num, st);
|
||||||
size_t size = msg.length();
|
// size_t size = msg.length();
|
||||||
char dataArray[size];
|
// char dataArray[size];
|
||||||
msg.toCharArray(dataArray, size);
|
// msg.toCharArray(dataArray, size);
|
||||||
standWebSocket.sendBIN(num, (uint8_t*)dataArray, size);
|
// standWebSocket.sendBIN(num, (uint8_t*)dataArray, size);
|
||||||
String end = "/end" + String(name);
|
// String end = "/end" + String(name);
|
||||||
standWebSocket.sendTXT(num, end);
|
// standWebSocket.sendTXT(num, end);
|
||||||
}
|
//}
|
||||||
|
|
||||||
//особая функция отправки графиков в веб
|
//особая функция отправки графиков в веб
|
||||||
void publishChartToWs(String filename, int num, size_t frameSize, int maxCount, String id) {
|
void publishChartToWs(String filename, int num, size_t frameSize, int maxCount, String id) {
|
||||||
@@ -400,13 +405,12 @@ void publishChartToWs(String filename, int num, size_t frameSize, int maxCount,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6 4
|
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize) {
|
||||||
// layout|0120|{status:12}|...from file...
|
if (header.length() != 6) {
|
||||||
// layout|0000|...from file...
|
SerialPrint("E", "FS", F("wrong header size"));
|
||||||
// layout|0000|...from file...
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void sendBlobToWsStrHeader(const String& filename, const String& header, uint8_t client_id, size_t frameSize) {
|
|
||||||
// откроем файл
|
|
||||||
auto path = filepath(filename);
|
auto path = filepath(filename);
|
||||||
auto file = FileFS.open(path, "r");
|
auto file = FileFS.open(path, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -417,19 +421,26 @@ void sendBlobToWsStrHeader(const String& filename, const String& header, uint8_t
|
|||||||
size_t totalSize = file.size();
|
size_t totalSize = file.size();
|
||||||
SerialPrint("I", "FS", "Send file '" + String(filename) + "', file size: " + String(totalSize));
|
SerialPrint("I", "FS", "Send file '" + String(filename) + "', file size: " + String(totalSize));
|
||||||
|
|
||||||
// размер заголовка
|
char buf[32];
|
||||||
auto headerSize = header.length();
|
sprintf(buf, "%04d", json.length() + 12);
|
||||||
// выделим буфер размером с фрейм
|
String data = header + "|" + String(buf) + "|" + json;
|
||||||
|
|
||||||
|
size_t headerSize = data.length();
|
||||||
auto frameBuf = new uint8_t[frameSize];
|
auto frameBuf = new uint8_t[frameSize];
|
||||||
// заголовок у нас не меняется, запием его в начало буфера
|
size_t maxPayloadSize = frameSize - headerSize;
|
||||||
header.toCharArray((char*)frameBuf, frameSize);
|
uint8_t* payloadBuf = nullptr;
|
||||||
// указатель на начало полезной нагрузки
|
|
||||||
auto payloadBuf = &frameBuf[headerSize];
|
|
||||||
// и сколько осталось места для нее
|
|
||||||
auto maxPayloadSize = frameSize - headerSize;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (file.available()) {
|
while (file.available()) {
|
||||||
// прочитаем кусок в буфер
|
if (i == 0) {
|
||||||
|
data.toCharArray((char*)frameBuf, frameSize);
|
||||||
|
payloadBuf = &frameBuf[headerSize];
|
||||||
|
} else {
|
||||||
|
maxPayloadSize = frameSize;
|
||||||
|
headerSize = 0;
|
||||||
|
payloadBuf = &frameBuf[0];
|
||||||
|
}
|
||||||
|
|
||||||
size_t payloadSize = file.read(payloadBuf, maxPayloadSize);
|
size_t payloadSize = file.read(payloadBuf, maxPayloadSize);
|
||||||
if (payloadSize) {
|
if (payloadSize) {
|
||||||
size_t size = headerSize + payloadSize;
|
size_t size = headerSize + payloadSize;
|
||||||
@@ -448,13 +459,90 @@ void sendBlobToWsStrHeader(const String& filename, const String& header, uint8_t
|
|||||||
continuation = true;
|
continuation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialPrint("I", "FS", String(i) + ") sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
|
SerialPrint("I", "FS", String(i) + ") fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
|
||||||
standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation);
|
standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
payloadBuf = &frameBuf[0];
|
||||||
|
delete[] payloadBuf;
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendStringToWs(const String& header, String& payload, uint8_t client_id) {
|
||||||
|
if (header.length() != 6) {
|
||||||
|
SerialPrint("E", "FS", F("wrong header size"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String msg = header + "|0012|" + payload;
|
||||||
|
size_t totalSize = msg.length();
|
||||||
|
SerialPrint("I", "FS", "Send string '" + header + "', str size: " + String(totalSize));
|
||||||
|
|
||||||
|
char dataArray[totalSize];
|
||||||
|
msg.toCharArray(dataArray, totalSize + 1);
|
||||||
|
standWebSocket.sendBIN(client_id, (uint8_t*)dataArray, totalSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize) {
|
||||||
|
// if (header.length() != 6) {
|
||||||
|
// SerialPrint("E", "FS", F("wrong header size"));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// // откроем файл
|
||||||
|
// auto path = filepath(filename);
|
||||||
|
// auto file = FileFS.open(path, "r");
|
||||||
|
// if (!file) {
|
||||||
|
// SerialPrint("E", "FS", F("reed file error"));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// size_t totalSize = file.size();
|
||||||
|
// SerialPrint("I", "FS", "Send file '" + String(filename) + "', file size: " + String(totalSize));
|
||||||
|
//
|
||||||
|
// char buf[32];
|
||||||
|
// sprintf(buf, "%04d", json.length() + 12);
|
||||||
|
//
|
||||||
|
// String data = header + "|" + String(buf) + "|" + json;
|
||||||
|
//
|
||||||
|
// // размер заголовка
|
||||||
|
// auto headerSize = data.length();
|
||||||
|
// // выделим буфер размером с фрейм
|
||||||
|
// auto frameBuf = new uint8_t[frameSize];
|
||||||
|
// // заголовок у нас не меняется, запием его в начало буфера
|
||||||
|
// data.toCharArray((char*)frameBuf, frameSize);
|
||||||
|
// // указатель на начало полезной нагрузки
|
||||||
|
// auto payloadBuf = &frameBuf[headerSize];
|
||||||
|
// // и сколько осталось места для нее
|
||||||
|
// auto maxPayloadSize = frameSize - headerSize;
|
||||||
|
// int i = 0;
|
||||||
|
// while (file.available()) {
|
||||||
|
// // прочитаем кусок в буфер
|
||||||
|
// size_t payloadSize = file.read(payloadBuf, maxPayloadSize);
|
||||||
|
// if (payloadSize) {
|
||||||
|
// size_t size = headerSize + payloadSize;
|
||||||
|
//
|
||||||
|
// bool fin = false;
|
||||||
|
// if (size == frameSize) {
|
||||||
|
// fin = false;
|
||||||
|
// } else {
|
||||||
|
// fin = true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// bool continuation = false;
|
||||||
|
// if (i == 0) {
|
||||||
|
// continuation = false;
|
||||||
|
// } else {
|
||||||
|
// continuation = true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// SerialPrint("I", "FS", String(i) + ") sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
|
||||||
|
// standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation);
|
||||||
|
// }
|
||||||
|
// i++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// void sendMark(const char* filename, const char* mark, uint8_t num) {
|
// void sendMark(const char* filename, const char* mark, uint8_t num) {
|
||||||
// char outChar[strlen(filename) + strlen(mark) + 1];
|
// char outChar[strlen(filename) + strlen(mark) + 1];
|
||||||
// strcpy(outChar, mark);
|
// strcpy(outChar, mark);
|
||||||
|
|||||||
34
src/modules/virtual/Loging/Loging (1).cpp
Normal file
34
src/modules/virtual/Loging/Loging (1).cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "Global.h"
|
||||||
|
#include "classes/IoTItem.h"
|
||||||
|
|
||||||
|
class Loging : public IoTItem {
|
||||||
|
private:
|
||||||
|
String logval;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Loging(String parameters) : IoTItem(parameters) {
|
||||||
|
jsonRead(parameters, F("logid"), logval);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void setValue(IoTValue Value) {
|
||||||
|
// value = Value;
|
||||||
|
// regEvent((String)(int)value.valD, "Loging");
|
||||||
|
// }
|
||||||
|
|
||||||
|
void doByInterval() {
|
||||||
|
String value = getItemValue(logval);
|
||||||
|
if (value == "") {
|
||||||
|
SerialPrint("E", F("Logging"), F("no value set"));
|
||||||
|
} else {
|
||||||
|
regEvent(value, "Logging");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void* getAPI_Loging(String subtype, String param) {
|
||||||
|
if (subtype == F("Loging")) {
|
||||||
|
return new Loging(param);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user