mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-04-01 04:49:13 +03:00
отправка данных графиков в веб интерфейс
This commit is contained in:
@@ -25,7 +25,7 @@ void globalVarsSync() {
|
||||
|
||||
String getParamsJson() {
|
||||
String json;
|
||||
serializeJson(*getLocalItemsAsJSON(), json); // Ilya, data: "1.00" (analog sensor, round set to 1, should be "1.0")
|
||||
serializeJson(*getLocalItemsAsJSON(), json);
|
||||
jsonWriteStr_(json, "params", "");
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -134,9 +134,10 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
publishWidgets();
|
||||
publishState();
|
||||
|
||||
//отправка данных графиков
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
if ((*it)->getSubtype() == "Loging") {
|
||||
(*it)->sendChart();
|
||||
(*it)->sendChart(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
}
|
||||
|
||||
// Страница веб интерфейса dashboard===================================================================
|
||||
// отправляем только файл layout.json //
|
||||
if (headerStr == "/|") {
|
||||
sendFileToWs("/layout.json", num, 1024);
|
||||
String json = getParamsJson();
|
||||
standWebSocket.sendTXT(num, json);
|
||||
sendFileToWs("/layout.json", num, 1024);
|
||||
//отправка данных графиков
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
if ((*it)->getSubtype() == "Loging") {
|
||||
(*it)->sendChart(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Страница веб интерфейса configutation================================================================
|
||||
//========отправка=========================================================//
|
||||
@@ -150,8 +155,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
}
|
||||
//команда очистки всех логов esp//
|
||||
if (headerStr == "/clean|") {
|
||||
cleanDirectory("lg");
|
||||
cleanDirectory("db");
|
||||
cleanLogs();
|
||||
}
|
||||
|
||||
//Прием сообщений cotrol ==============================================================================
|
||||
@@ -203,13 +207,20 @@ 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; //+ "/status";
|
||||
String path = mqttRootDevice + "/" + topic;
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", data);
|
||||
jsonWriteStr(json, "topic", path);
|
||||
standWebSocket.broadcastTXT(json);
|
||||
}
|
||||
|
||||
//публикация статус сообщений уже готовых
|
||||
void publishStatusWsJson(const String& topic, String& json) {
|
||||
String path = mqttRootDevice + "/" + topic;
|
||||
jsonWriteStr(json, "topic", path);
|
||||
standWebSocket.broadcastTXT(json);
|
||||
}
|
||||
|
||||
//данные которые мы отправляем в сокеты переодически
|
||||
void periodicWsSend() {
|
||||
standWebSocket.broadcastTXT(devListHeapJson);
|
||||
|
||||
@@ -128,7 +128,7 @@ String IoTItem::getSubtype() {
|
||||
return _subtype;
|
||||
}
|
||||
|
||||
void IoTItem::sendChart() {}
|
||||
void IoTItem::sendChart(bool mqtt) {}
|
||||
|
||||
String IoTItem::getID() {
|
||||
return _id;
|
||||
|
||||
@@ -17,7 +17,7 @@ class Loging : public IoTItem {
|
||||
jsonRead(parameters, F("logid"), logid);
|
||||
jsonRead(parameters, F("id"), id);
|
||||
jsonRead(parameters, F("points"), points);
|
||||
if (points >= 300) {
|
||||
if (points > 300) {
|
||||
points = 300;
|
||||
SerialPrint("E", F("Loging"), "'" + id + "' user set more points than allowed, value reset to 300");
|
||||
}
|
||||
@@ -91,7 +91,7 @@ class Loging : public IoTItem {
|
||||
SerialPrint("i", F("Loging"), "'" + id + "' loging in file http://" + WiFi.localIP().toString() + path);
|
||||
}
|
||||
|
||||
void sendChart() {
|
||||
void sendChart(bool mqtt) {
|
||||
SerialPrint("i", F("Loging"), "'" + id + "'----------------------------");
|
||||
String reqUnixTimeStr = "27.08.2022"; //нужно получить эту дату из окна ввода под графиком.
|
||||
unsigned long reqUnixTime = strDateToUnix(reqUnixTimeStr);
|
||||
@@ -124,7 +124,7 @@ class Loging : public IoTItem {
|
||||
// if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) {
|
||||
SerialPrint("i", F("Loging"), "'" + id + "' matching file found '" + fname + "'");
|
||||
//выгрузка по частям, по одному файлу
|
||||
publishJsonPartly("/lg/" + fname, calculateMaxCount(), i);
|
||||
publishJsonPartly("/lg/" + fname, calculateMaxCount(), i, mqtt);
|
||||
//}
|
||||
//удаление старых файлов
|
||||
if ((fileUnixTime + (points * interval)) < (unixTime - (keepdays * 86400))) {
|
||||
@@ -144,7 +144,7 @@ class Loging : public IoTItem {
|
||||
SerialPrint("i", F("Loging"), "'" + id + "'--------------'" + String(i) + "'--------------");
|
||||
}
|
||||
|
||||
void publishJsonPartly(String file, int maxCount, int &i) {
|
||||
void publishJsonPartly(String file, int maxCount, int &i, bool mqtt) {
|
||||
File configFile = FileFS.open(file, "r");
|
||||
if (!configFile) {
|
||||
SerialPrint("E", F("Loging"), "'" + id + "' open file error");
|
||||
@@ -171,14 +171,17 @@ class Loging : public IoTItem {
|
||||
} while (psn < sz);
|
||||
|
||||
configFile.close();
|
||||
publishJson(dividedJson, maxCount);
|
||||
|
||||
publishJson(dividedJson, maxCount, mqtt);
|
||||
}
|
||||
|
||||
void publishJson(String & oneSingleJson, int &maxCount) {
|
||||
void publishJson(String & oneSingleJson, int &maxCount, bool mqtt) {
|
||||
oneSingleJson = "{\"maxCount\":" + String(maxCount) + ",\"status\":[" + oneSingleJson + "]}";
|
||||
oneSingleJson.replace("},]}", "}]}");
|
||||
if (!publishChart(id, oneSingleJson)) {
|
||||
SerialPrint("E", F("Loging"), "'" + id + "' mqtt publish error");
|
||||
if (mqtt) {
|
||||
publishChart(id, oneSingleJson);
|
||||
} else {
|
||||
publishStatusWsJson(id, oneSingleJson);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ void cleanDirectory(String path) {
|
||||
while (dir.next()) {
|
||||
String fname = dir.fileName();
|
||||
removeFile(path + "/" + fname);
|
||||
SerialPrint("I", "Files", path + "/" + fname + " => deleted");
|
||||
SerialPrint("i", "Files", path + "/" + fname + " => deleted");
|
||||
}
|
||||
onFlashWrite();
|
||||
#endif
|
||||
@@ -205,12 +205,16 @@ void cleanDirectory(String path) {
|
||||
path = "/" + path;
|
||||
File root = FileFS.open(path);
|
||||
path = String();
|
||||
if (!root) {
|
||||
SerialPrint("E", "Files", "nothing to delete");
|
||||
return;
|
||||
}
|
||||
if (root.isDirectory()) {
|
||||
File file = root.openNextFile();
|
||||
while (file) {
|
||||
String fname = file.name();
|
||||
removeFile(fname);
|
||||
SerialPrint("I", "Files", fname + " => deleted");
|
||||
SerialPrint("i", "Files", fname + " => deleted");
|
||||
file = root.openNextFile();
|
||||
}
|
||||
}
|
||||
@@ -227,6 +231,11 @@ String readDataDB(String id) {
|
||||
return readFile(path, 2000);
|
||||
}
|
||||
|
||||
void cleanLogs() {
|
||||
cleanDirectory("lg");
|
||||
cleanDirectory("db");
|
||||
}
|
||||
|
||||
//счетчик количества записей на флешь за сеанс
|
||||
void onFlashWrite() {
|
||||
flashWriteNumber++;
|
||||
|
||||
Reference in New Issue
Block a user