mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
рабочая версия
This commit is contained in:
@@ -13,16 +13,9 @@ extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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 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 sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize);
|
||||||
void sendStringToWs(const String& header, String& payload, int client_id);
|
void sendStringToWs(const String& header, String& payload, int client_id);
|
||||||
|
|
||||||
// void sendMark(const char* filename, const char* mark, uint8_t num);
|
|
||||||
// void sendFileToWs3(const String& filename, uint8_t num);
|
|
||||||
// void sendFileToWs4(const String& filename, uint8_t num);
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const String getThisDevice() {
|
const String getThisDevice() {
|
||||||
String thisDevice = "{}";
|
String thisDevice = "{}";
|
||||||
jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга нужна для udp валидации
|
jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга нужна для udp валидации может быть рабочей группой в последствии
|
||||||
jsonWriteStr_(thisDevice, F("ip"), jsonReadStr(settingsFlashJson, F("ip")));
|
jsonWriteStr_(thisDevice, F("ip"), jsonReadStr(settingsFlashJson, F("ip")));
|
||||||
jsonWriteStr_(thisDevice, F("id"), jsonReadStr(settingsFlashJson, F("id")));
|
jsonWriteStr_(thisDevice, F("id"), jsonReadStr(settingsFlashJson, F("id")));
|
||||||
jsonWriteStr_(thisDevice, F("name"), jsonReadStr(settingsFlashJson, F("name")));
|
jsonWriteStr_(thisDevice, F("name"), jsonReadStr(settingsFlashJson, F("name")));
|
||||||
|
|||||||
207
src/WsServer.cpp
207
src/WsServer.cpp
@@ -266,7 +266,7 @@ void publishStatusWs(const String& topic, const String& data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void publishChartWs(int num, String& path) {
|
void publishChartWs(int num, String& path) {
|
||||||
sendFileToWs(path, num, 1000);
|
// sendFileToWs(path, num, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//данные которые мы отправляем в сокеты переодически
|
//данные которые мы отправляем в сокеты переодически
|
||||||
@@ -292,93 +292,6 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//посылка данных из файла в бинарном виде
|
|
||||||
void sendFileToWs(String filename, int num, size_t frameSize) {
|
|
||||||
// String st = "/st" + String(filename);
|
|
||||||
// if (num == -1) {
|
|
||||||
// standWebSocket.broadcastTXT(st);
|
|
||||||
// } else {
|
|
||||||
// standWebSocket.sendTXT(num, st);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// String path = filepath(filename);
|
|
||||||
// auto file = FileFS.open(path, "r");
|
|
||||||
// if (!file) {
|
|
||||||
// SerialPrint(F("E"), F("FS"), F("reed file error"));
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
// size_t fileSize = file.size();
|
|
||||||
// SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize));
|
|
||||||
// uint8_t payload[frameSize];
|
|
||||||
// int countRead = file.read(payload, sizeof(payload));
|
|
||||||
// while (countRead > 0) {
|
|
||||||
// if (num == -1) {
|
|
||||||
// standWebSocket.broadcastBIN(payload, countRead);
|
|
||||||
// } else {
|
|
||||||
// standWebSocket.sendBIN(num, payload, countRead);
|
|
||||||
// }
|
|
||||||
// countRead = file.read(payload, sizeof(payload));
|
|
||||||
//}
|
|
||||||
// file.close();
|
|
||||||
// String end = "/end" + String(filename);
|
|
||||||
// if (num == -1) {
|
|
||||||
// standWebSocket.broadcastTXT(end);
|
|
||||||
//} else {
|
|
||||||
// standWebSocket.sendTXT(num, end);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
//посылка данных из string
|
|
||||||
// void sendStringToWs(const String& msg, uint8_t num, String name) {
|
|
||||||
// String st = "/st" + String(name);
|
|
||||||
// standWebSocket.sendTXT(num, st);
|
|
||||||
// size_t size = msg.length();
|
|
||||||
// char dataArray[size];
|
|
||||||
// msg.toCharArray(dataArray, size);
|
|
||||||
// standWebSocket.sendBIN(num, (uint8_t*)dataArray, size);
|
|
||||||
// String end = "/end" + String(name);
|
|
||||||
// standWebSocket.sendTXT(num, end);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//особая функция отправки графиков в веб
|
|
||||||
void publishChartToWs(String filename, int num, size_t frameSize, int maxCount, String id) {
|
|
||||||
// String json;
|
|
||||||
// jsonWriteStr(json, "topic", mqttRootDevice + "/" + id);
|
|
||||||
// jsonWriteInt(json, "maxCount", maxCount);
|
|
||||||
//
|
|
||||||
// String st = "/st/chart.json|" + json;
|
|
||||||
// if (num == -1) {
|
|
||||||
// standWebSocket.broadcastTXT(st);
|
|
||||||
//} else {
|
|
||||||
// standWebSocket.sendTXT(num, st);
|
|
||||||
//}
|
|
||||||
// String path = filepath(filename);
|
|
||||||
// auto file = FileFS.open(path, "r");
|
|
||||||
// if (!file) {
|
|
||||||
// SerialPrint(F("E"), F("FS"), F("reed file error"));
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
// size_t fileSize = file.size();
|
|
||||||
// SerialPrint(F("i"), F("FS"), "Send file '" + String(filename) + "', file size: " + String(fileSize));
|
|
||||||
// uint8_t payload[frameSize];
|
|
||||||
// int countRead = file.read(payload, sizeof(payload));
|
|
||||||
// while (countRead > 0) {
|
|
||||||
// if (num == -1) {
|
|
||||||
// standWebSocket.broadcastBIN(payload, countRead);
|
|
||||||
// } else {
|
|
||||||
// standWebSocket.sendBIN(num, payload, countRead);
|
|
||||||
// }
|
|
||||||
// countRead = file.read(payload, sizeof(payload));
|
|
||||||
//}
|
|
||||||
// file.close();
|
|
||||||
// String end = "/end/chart.json|" + json;
|
|
||||||
// if (num == -1) {
|
|
||||||
// standWebSocket.broadcastTXT(end);
|
|
||||||
//} else {
|
|
||||||
// standWebSocket.sendTXT(num, end);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize) {
|
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, uint8_t client_id, size_t frameSize) {
|
||||||
if (header.length() != 6) {
|
if (header.length() != 6) {
|
||||||
SerialPrint("E", "FS", F("wrong header size"));
|
SerialPrint("E", "FS", F("wrong header size"));
|
||||||
@@ -434,8 +347,12 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Serial.println(String(i) + ") fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
|
// Serial.println(String(i) + ") fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
|
||||||
|
if (client_id == -1) {
|
||||||
|
standWebSocket.broadcastBIN(frameBuf, size, fin, continuation);
|
||||||
|
} else {
|
||||||
standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation);
|
standWebSocket.sendBIN(client_id, frameBuf, size, fin, continuation);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
payloadBuf = &frameBuf[0];
|
payloadBuf = &frameBuf[0];
|
||||||
@@ -461,117 +378,3 @@ void sendStringToWs(const String& header, String& payload, int client_id) {
|
|||||||
standWebSocket.sendBIN(client_id, (uint8_t*)dataArray, totalSize);
|
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) {
|
|
||||||
// char outChar[strlen(filename) + strlen(mark) + 1];
|
|
||||||
// strcpy(outChar, mark);
|
|
||||||
// strcat(outChar, filename);
|
|
||||||
// size_t size = strlen(outChar);
|
|
||||||
// uint8_t outUint[size];
|
|
||||||
// for (size_t i = 0; i < size; i++) {
|
|
||||||
// outUint[i] = uint8_t(outChar[i]);
|
|
||||||
// }
|
|
||||||
// standWebSocket.sendBIN(num, outUint, sizeof(outUint));
|
|
||||||
// }
|
|
||||||
|
|
||||||
//посылка данных из файла в string
|
|
||||||
// void sendFileToWs3(const String& filename, uint8_t num) {
|
|
||||||
// standWebSocket.sendTXT(num, "/st" + filename);
|
|
||||||
// size_t ws_buffer = 512;
|
|
||||||
// String path = filepath(filename);
|
|
||||||
// auto file = FileFS.open(path, "r");
|
|
||||||
// if (!file) {
|
|
||||||
// SerialPrint(F("E"), F("FS"), F("reed file error"));
|
|
||||||
// }
|
|
||||||
// size_t fileSize = file.size();
|
|
||||||
// SerialPrint(F("i"), F("WS"), "Send file '" + filename + "', file size: " + String(fileSize));
|
|
||||||
// String ret;
|
|
||||||
// char temp[ws_buffer + 1];
|
|
||||||
// int countRead = file.readBytes(temp, sizeof(temp) - 1);
|
|
||||||
// while (countRead > 0) {
|
|
||||||
// temp[countRead] = 0;
|
|
||||||
// ret = temp;
|
|
||||||
// standWebSocket.sendTXT(num, ret);
|
|
||||||
// countRead = file.readBytes(temp, sizeof(temp) - 1);
|
|
||||||
// }
|
|
||||||
// standWebSocket.sendTXT(num, "/end" + filename);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//посылка данных из файла в char
|
|
||||||
// void sendFileToWs4(const String& filename, uint8_t num) {
|
|
||||||
// standWebSocket.sendTXT(num, "/st" + filename);
|
|
||||||
// size_t ws_buffer = 512;
|
|
||||||
// String path = filepath(filename);
|
|
||||||
// auto file = FileFS.open(path, "r");
|
|
||||||
// if (!file) {
|
|
||||||
// SerialPrint(F("E"), F("FS"), F("reed file error"));
|
|
||||||
// }
|
|
||||||
// size_t fileSize = file.size();
|
|
||||||
// SerialPrint(F("i"), F("WS"), "Send file '" + filename + "', file size: " + String(fileSize));
|
|
||||||
// char temp[ws_buffer + 1];
|
|
||||||
// int countRead = file.readBytes(temp, sizeof(temp) - 1);
|
|
||||||
// while (countRead > 0) {
|
|
||||||
// temp[countRead] = 0;
|
|
||||||
// standWebSocket.sendTXT(num, temp, countRead);
|
|
||||||
// countRead = file.readBytes(temp, sizeof(temp) - 1);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|||||||
@@ -181,10 +181,9 @@ class Loging : public IoTItem {
|
|||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
} else if (_publishType == TO_WS) {
|
} else if (_publishType == TO_WS) {
|
||||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
|
|
||||||
} else if (_publishType == TO_MQTT_WS) {
|
} else if (_publishType == TO_MQTT_WS) {
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
|
||||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
}
|
}
|
||||||
SerialPrint("i", F("Loging"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
SerialPrint("i", F("Loging"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
||||||
} else {
|
} else {
|
||||||
@@ -208,15 +207,13 @@ class Loging : public IoTItem {
|
|||||||
void publishChartToWsSinglePoint(String value) {
|
void publishChartToWsSinglePoint(String value) {
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
||||||
String pk = "/string/chart.json|" + json;
|
sendStringToWs("chartb", json, -1);
|
||||||
// standWebSocket.broadcastTXT(pk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearValue() {
|
void clearValue() {
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
||||||
String pk = "/string/chart.json|" + json;
|
sendStringToWs("chartb", json, -1);
|
||||||
// standWebSocket.broadcastTXT(pk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearHistory() {
|
void clearHistory() {
|
||||||
@@ -246,7 +243,7 @@ class Loging : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPublishDestination(int publishType, int wsNum = -1) {
|
void setPublishDestination(int publishType, int wsNum) {
|
||||||
_publishType = publishType;
|
_publishType = publishType;
|
||||||
_wsNum = wsNum;
|
_wsNum = wsNum;
|
||||||
}
|
}
|
||||||
@@ -321,8 +318,7 @@ class Date : public IoTItem {
|
|||||||
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||||
if ((*it)->getSubtype() == "Loging") {
|
if ((*it)->getSubtype() == "Loging") {
|
||||||
if ((*it)->getID() == selectToMarker(id, "-")) {
|
if ((*it)->getID() == selectToMarker(id, "-")) {
|
||||||
(*it)->setPublishDestination(TO_MQTT_WS);
|
(*it)->setPublishDestination(TO_MQTT_WS, -1);
|
||||||
(*it)->clearValue();
|
|
||||||
(*it)->publishValue();
|
(*it)->publishValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,14 +168,14 @@ class LogingDaily : public IoTItem {
|
|||||||
path = "/lgd/" + id + path;
|
path = "/lgd/" + id + path;
|
||||||
|
|
||||||
f++;
|
f++;
|
||||||
|
String json = getAdditionalJson();
|
||||||
if (_publishType == TO_MQTT) {
|
if (_publishType == TO_MQTT) {
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
} else if (_publishType == TO_WS) {
|
} else if (_publishType == TO_WS) {
|
||||||
publishChartToWs(path, _wsNum, 1000, calculateMaxCount(), id);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
} else if (_publishType == TO_MQTT_WS) {
|
} else if (_publishType == TO_MQTT_WS) {
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
publishChartToWs(path, _wsNum, 1000, calculateMaxCount(), id);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
}
|
}
|
||||||
SerialPrint("i", F("LogingDaily"), String(f) + ") " + path + ", sent");
|
SerialPrint("i", F("LogingDaily"), String(f) + ") " + path + ", sent");
|
||||||
|
|
||||||
@@ -183,17 +183,23 @@ class LogingDaily : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getAdditionalJson() {
|
||||||
|
String topic = mqttRootDevice + "/" + id;
|
||||||
|
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\"}";
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
void clearHistory() {
|
void clearHistory() {
|
||||||
String dir = "/lgd/" + id;
|
String dir = "/lgd/" + id;
|
||||||
cleanDirectory(dir);
|
cleanDirectory(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishChartToWsSinglePoint(String value) {
|
// void publishChartToWsSinglePoint(String value) {
|
||||||
String topic = mqttRootDevice + "/" + id;
|
// String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
// String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
||||||
String pk = "/string/chart.json|" + json;
|
// String pk = "/string/chart.json|" + json;
|
||||||
// standWebSocket.broadcastTXT(pk);
|
// standWebSocket.broadcastTXT(pk);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void setPublishDestination(int publishType, int wsNum = -1) {
|
void setPublishDestination(int publishType, int wsNum = -1) {
|
||||||
_publishType = publishType;
|
_publishType = publishType;
|
||||||
|
|||||||
Reference in New Issue
Block a user