mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
восстановление графиков
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const String getThisDevice() {
|
const String getThisDevice() {
|
||||||
String thisDevice = "{}";
|
String thisDevice = "{}";
|
||||||
// jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга
|
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")));
|
||||||
@@ -68,7 +68,7 @@ void asyncUdpInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool udpPacketValidation(String& data) {
|
bool udpPacketValidation(String& data) {
|
||||||
if (data.indexOf("devicelist") != -1) {
|
if (data.indexOf("devicelist_") != -1) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ void globalVarsSync() {
|
|||||||
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
||||||
jsonWriteStr_(settingsFlashJson, "id", chipId);
|
jsonWriteStr_(settingsFlashJson, "id", chipId);
|
||||||
|
|
||||||
// jsonWriteStr_(errorsHeapJson, "errors_", ""); //метка для парсинга
|
// jsonWriteStr_(errorsHeapJson, "errors_", ""); //метка для парсинга удалить
|
||||||
// jsonWriteStr_(ssidListHeapJson, "ssids_", ""); //метка для парсинга
|
// jsonWriteStr_(ssidListHeapJson, "ssids_", ""); //метка для парсинга удалить
|
||||||
}
|
}
|
||||||
|
|
||||||
String getParamsJson() {
|
String getParamsJson() {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
//отвечаем на запрос параметров
|
//отвечаем на запрос параметров
|
||||||
if (headerStr == "/params|") {
|
if (headerStr == "/params|") {
|
||||||
String params = "{}";
|
String params = "{}";
|
||||||
// jsonWriteStr(params, "params_", ""); //метка для парсинга
|
// jsonWriteStr(params, "params_", ""); //метка для парсинга удалить
|
||||||
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)->iAmLocal) jsonWriteStr(params, (*it)->getID(), (*it)->getValue());
|
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) {
|
void publishStatusWs(const String& topic, const String& data) {
|
||||||
// String path = mqttRootDevice + "/" + topic;
|
String path = mqttRootDevice + "/" + topic;
|
||||||
// String json = "{}";
|
String json = "{}";
|
||||||
// jsonWriteStr(json, "status", data);
|
jsonWriteStr(json, "status", data);
|
||||||
// jsonWriteStr(json, "topic", path);
|
jsonWriteStr(json, "topic", path);
|
||||||
// standWebSocket.broadcastTXT(json);
|
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) {
|
void publishChartWs(int num, String& path) {
|
||||||
sendFileToWs(path, num, 1000);
|
sendFileToWs(path, num, 1000);
|
||||||
}
|
}
|
||||||
@@ -407,8 +392,8 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t totalSize = file.size();
|
// size_t totalSize = file.size();
|
||||||
// Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize));
|
// Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize));
|
||||||
|
|
||||||
char buf[32];
|
char buf[32];
|
||||||
sprintf(buf, "%04d", json.length() + 12);
|
sprintf(buf, "%04d", json.length() + 12);
|
||||||
|
|||||||
@@ -176,13 +176,15 @@ class Loging : public IoTItem {
|
|||||||
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
||||||
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
|
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
|
||||||
noData = false;
|
noData = false;
|
||||||
|
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("Loging"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
SerialPrint("i", F("Loging"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
||||||
} else {
|
} 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() {
|
void clearHistory() {
|
||||||
String dir = "/lg/" + id;
|
String dir = "/lg/" + id;
|
||||||
cleanDirectory(dir);
|
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) {
|
void setPublishDestination(int publishType, int wsNum = -1) {
|
||||||
_publishType = publishType;
|
_publishType = publishType;
|
||||||
_wsNum = wsNum;
|
_wsNum = wsNum;
|
||||||
|
|||||||
Reference in New Issue
Block a user