mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
восстановление графиков
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
const String getThisDevice() {
|
||||
String thisDevice = "{}";
|
||||
// jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга
|
||||
jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга нужна для udp валидации
|
||||
jsonWriteStr_(thisDevice, F("ip"), jsonReadStr(settingsFlashJson, F("ip")));
|
||||
jsonWriteStr_(thisDevice, F("id"), jsonReadStr(settingsFlashJson, F("id")));
|
||||
jsonWriteStr_(thisDevice, F("name"), jsonReadStr(settingsFlashJson, F("name")));
|
||||
@@ -68,7 +68,7 @@ void asyncUdpInit() {
|
||||
}
|
||||
|
||||
bool udpPacketValidation(String& data) {
|
||||
if (data.indexOf("devicelist") != -1) {
|
||||
if (data.indexOf("devicelist_") != -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -19,8 +19,8 @@ void globalVarsSync() {
|
||||
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
||||
jsonWriteStr_(settingsFlashJson, "id", chipId);
|
||||
|
||||
// jsonWriteStr_(errorsHeapJson, "errors_", ""); //метка для парсинга
|
||||
// jsonWriteStr_(ssidListHeapJson, "ssids_", ""); //метка для парсинга
|
||||
// jsonWriteStr_(errorsHeapJson, "errors_", ""); //метка для парсинга удалить
|
||||
// jsonWriteStr_(ssidListHeapJson, "ssids_", ""); //метка для парсинга удалить
|
||||
}
|
||||
|
||||
String getParamsJson() {
|
||||
|
||||
@@ -62,7 +62,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
//отвечаем на запрос параметров
|
||||
if (headerStr == "/params|") {
|
||||
String params = "{}";
|
||||
// jsonWriteStr(params, "params_", ""); //метка для парсинга
|
||||
// jsonWriteStr(params, "params_", ""); //метка для парсинга удалить
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
if ((*it)->getSubtype() != "Loging") {
|
||||
if ((*it)->iAmLocal) jsonWriteStr(params, (*it)->getID(), (*it)->getValue());
|
||||
@@ -258,28 +258,13 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
|
||||
//публикация статус сообщений (недостаток в том что делаем бродкаст всем клиентам поднятым в свелте!!!)
|
||||
void publishStatusWs(const String& topic, const String& data) {
|
||||
// String path = mqttRootDevice + "/" + topic;
|
||||
// String json = "{}";
|
||||
// jsonWriteStr(json, "status", data);
|
||||
// jsonWriteStr(json, "topic", path);
|
||||
// standWebSocket.broadcastTXT(json);
|
||||
String path = mqttRootDevice + "/" + topic;
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", data);
|
||||
jsonWriteStr(json, "topic", path);
|
||||
sendStringToWs("status", json, -1);
|
||||
}
|
||||
|
||||
//публикация статус сообщений
|
||||
// void publishChartWs2(int num, String& data) {
|
||||
// bool ok = false;
|
||||
// if (num == -1) {
|
||||
// ok = standWebSocket.broadcastTXT(data);
|
||||
// } else {
|
||||
// ok = standWebSocket.sendTXT(num, data);
|
||||
// }
|
||||
// if (ok) {
|
||||
// SerialPrint(F("i"), F("WS"), F("sent sucsess"));
|
||||
// } else {
|
||||
// SerialPrint(F("E"), F("WS"), F("sent error"));
|
||||
// }
|
||||
//}
|
||||
|
||||
void publishChartWs(int num, String& path) {
|
||||
sendFileToWs(path, num, 1000);
|
||||
}
|
||||
@@ -407,8 +392,8 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
|
||||
return;
|
||||
}
|
||||
|
||||
size_t totalSize = file.size();
|
||||
// Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize));
|
||||
// size_t totalSize = file.size();
|
||||
// Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize));
|
||||
|
||||
char buf[32];
|
||||
sprintf(buf, "%04d", json.length() + 12);
|
||||
|
||||
@@ -176,13 +176,15 @@ class Loging : public IoTItem {
|
||||
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
||||
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
|
||||
noData = false;
|
||||
String json = getAdditionalJson();
|
||||
if (_publishType == TO_MQTT) {
|
||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||
} 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) {
|
||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||
publishChartToWs(path, _wsNum, 1000, calculateMaxCount(), id);
|
||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||
}
|
||||
SerialPrint("i", F("Loging"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
||||
} else {
|
||||
@@ -197,6 +199,26 @@ class Loging : public IoTItem {
|
||||
}
|
||||
}
|
||||
|
||||
String getAdditionalJson() {
|
||||
String topic = mqttRootDevice + "/" + id;
|
||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\"}";
|
||||
return json;
|
||||
}
|
||||
|
||||
void publishChartToWsSinglePoint(String value) {
|
||||
String topic = mqttRootDevice + "/" + id;
|
||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
||||
String pk = "/string/chart.json|" + json;
|
||||
// standWebSocket.broadcastTXT(pk);
|
||||
}
|
||||
|
||||
void clearValue() {
|
||||
String topic = mqttRootDevice + "/" + id;
|
||||
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
||||
String pk = "/string/chart.json|" + json;
|
||||
// standWebSocket.broadcastTXT(pk);
|
||||
}
|
||||
|
||||
void clearHistory() {
|
||||
String dir = "/lg/" + id;
|
||||
cleanDirectory(dir);
|
||||
@@ -224,20 +246,6 @@ class Loging : public IoTItem {
|
||||
}
|
||||
}
|
||||
|
||||
void clearValue() {
|
||||
String topic = mqttRootDevice + "/" + id;
|
||||
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
||||
String pk = "/string/chart.json|" + json;
|
||||
//standWebSocket.broadcastTXT(pk);
|
||||
}
|
||||
|
||||
void publishChartToWsSinglePoint(String value) {
|
||||
String topic = mqttRootDevice + "/" + id;
|
||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
||||
String pk = "/string/chart.json|" + json;
|
||||
//standWebSocket.broadcastTXT(pk);
|
||||
}
|
||||
|
||||
void setPublishDestination(int publishType, int wsNum = -1) {
|
||||
_publishType = publishType;
|
||||
_wsNum = wsNum;
|
||||
|
||||
Reference in New Issue
Block a user