mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-04-02 05:19:27 +03:00
графики с датой, рабочая версия
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
|
||||||
<title>IoT Manager 4.2.5</title>
|
<title>IoT Manager 4.2.6</title>
|
||||||
|
|
||||||
<link rel="icon" type="image/png" href="/favicon.ico" />
|
<link rel="icon" type="image/png" href="/favicon.ico" />
|
||||||
<link rel="stylesheet" href="/build/bundle.css" />
|
<link rel="stylesheet" href="/build/bundle.css" />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
|
|||||||
|
|
||||||
void sendFileToWs(const char* filename, uint8_t num, size_t frameSize);
|
void sendFileToWs(const char* filename, uint8_t num, size_t frameSize);
|
||||||
void publishStatusWs(const String& topic, const String& data);
|
void publishStatusWs(const String& topic, const String& data);
|
||||||
void publishChartWs(String& json);
|
void publishChartWs(int num, String& json);
|
||||||
void periodicWsSend();
|
void periodicWsSend();
|
||||||
void sendStringToWs(const String& msg, uint8_t num, String name);
|
void sendStringToWs(const String& msg, uint8_t num, String name);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ class IoTItem {
|
|||||||
virtual void regEvent(float value, String consoleInfo);
|
virtual void regEvent(float value, String consoleInfo);
|
||||||
|
|
||||||
String getSubtype();
|
String getSubtype();
|
||||||
virtual void sendChart(int type);
|
virtual void sendChart();
|
||||||
|
virtual void setPublishType(int type, int num);
|
||||||
virtual void cleanData();
|
virtual void cleanData();
|
||||||
|
|
||||||
String getID();
|
String getID();
|
||||||
|
|||||||
@@ -137,7 +137,8 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
//отправка данных графиков
|
//отправка данных графиков
|
||||||
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") {
|
||||||
(*it)->sendChart(1);
|
(*it)->setPublishType(1, -1);
|
||||||
|
(*it)->sendChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,10 +59,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
sendFileToWs("/layout.json", num, 1024);
|
sendFileToWs("/layout.json", num, 1024);
|
||||||
String json = getParamsJson();
|
String json = getParamsJson();
|
||||||
standWebSocket.sendTXT(num, json);
|
standWebSocket.sendTXT(num, json);
|
||||||
//отправка данных графиков (нехватает передачи номера сокетов)
|
//отправка данных графиков только в выбранный сокет
|
||||||
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") {
|
||||||
(*it)->sendChart(2);
|
(*it)->setPublishType(2, num);
|
||||||
|
(*it)->sendChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +241,7 @@ 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 = "{}";
|
||||||
@@ -249,9 +250,15 @@ void publishStatusWs(const String& topic, const String& data) {
|
|||||||
standWebSocket.broadcastTXT(json);
|
standWebSocket.broadcastTXT(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
//публикация статус сообщений уже готовых
|
//публикация статус сообщений
|
||||||
void publishChartWs(String& data) {
|
void publishChartWs(int num, String& data) {
|
||||||
standWebSocket.broadcastTXT(data);
|
if (num == -1) {
|
||||||
|
Serial.println("broadcastTXT");
|
||||||
|
standWebSocket.broadcastTXT(data);
|
||||||
|
} else {
|
||||||
|
Serial.println("sendTXT");
|
||||||
|
standWebSocket.sendTXT(num, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//данные которые мы отправляем в сокеты переодически
|
//данные которые мы отправляем в сокеты переодически
|
||||||
|
|||||||
@@ -128,7 +128,9 @@ String IoTItem::getSubtype() {
|
|||||||
return _subtype;
|
return _subtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoTItem::sendChart(int type) {}
|
void IoTItem::sendChart() {}
|
||||||
|
|
||||||
|
void IoTItem::setPublishType(int publishType, int wsNum){};
|
||||||
|
|
||||||
void IoTItem::cleanData() {}
|
void IoTItem::cleanData() {}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ class Loging : public IoTItem {
|
|||||||
String id;
|
String id;
|
||||||
String filesList = "";
|
String filesList = "";
|
||||||
|
|
||||||
|
int _publishType = -2;
|
||||||
|
int _wsNum = -1;
|
||||||
|
|
||||||
int points;
|
int points;
|
||||||
int keepdays;
|
int keepdays;
|
||||||
|
|
||||||
@@ -137,7 +140,7 @@ class Loging : public IoTItem {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendChart(int type) {
|
void sendChart() {
|
||||||
getFilesList();
|
getFilesList();
|
||||||
int f = 0;
|
int f = 0;
|
||||||
|
|
||||||
@@ -160,7 +163,7 @@ 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;
|
||||||
createJson(buf, i, type);
|
createJson(buf, i);
|
||||||
SerialPrint("i", F("Loging"), String(f) + ")" + buf + ", " + String(i) + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
SerialPrint("i", F("Loging"), String(f) + ")" + buf + ", " + String(i) + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
||||||
} else {
|
} else {
|
||||||
SerialPrint("i", F("Loging"), String(f) + ")" + buf + ", " + String(i) + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
SerialPrint("i", F("Loging"), String(f) + ")" + buf + ", " + String(i) + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
||||||
@@ -173,7 +176,7 @@ class Loging : public IoTItem {
|
|||||||
if (noData) {
|
if (noData) {
|
||||||
SerialPrint("i", F("Loging"), "clear chart");
|
SerialPrint("i", F("Loging"), "clear chart");
|
||||||
String cleanJson = createEmtyJson();
|
String cleanJson = createEmtyJson();
|
||||||
publishJson(cleanJson, type);
|
publishJson(cleanJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +194,7 @@ class Loging : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createJson(String file, int &i, int type) {
|
void createJson(String file, int &i) {
|
||||||
File configFile = FileFS.open(file, "r");
|
File configFile = FileFS.open(file, "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
SerialPrint("E", F("Loging"), "'" + id + "' open file error");
|
SerialPrint("E", F("Loging"), "'" + id + "' open file error");
|
||||||
@@ -223,17 +226,26 @@ class Loging : public IoTItem {
|
|||||||
oneSingleJson = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[" + oneSingleJson + "]}";
|
oneSingleJson = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[" + oneSingleJson + "]}";
|
||||||
oneSingleJson.replace("},]}", "}]}");
|
oneSingleJson.replace("},]}", "}]}");
|
||||||
|
|
||||||
publishJson(oneSingleJson, type);
|
publishJson(oneSingleJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishJson(String &oneSingleJson, int type) {
|
// publishType 1 - в mqtt, 2 - в ws, 3 - mqtt и ws
|
||||||
if (type == 1) {
|
// wsNum = -1 => broadcast
|
||||||
|
void setPublishType(int publishType, int wsNum) {
|
||||||
|
_publishType = publishType;
|
||||||
|
_wsNum = wsNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void publishJson(String &oneSingleJson) {
|
||||||
|
if (_publishType == 1) {
|
||||||
publishChartMqtt(id, oneSingleJson);
|
publishChartMqtt(id, oneSingleJson);
|
||||||
} else if (type == 2) {
|
} else if (_publishType == 2) {
|
||||||
publishChartWs(oneSingleJson);
|
publishChartWs(_wsNum, oneSingleJson);
|
||||||
} else if (type == 3) {
|
} else if (_publishType == 3) {
|
||||||
publishChartMqtt(id, oneSingleJson);
|
publishChartMqtt(id, oneSingleJson);
|
||||||
publishChartWs(oneSingleJson);
|
publishChartWs(_wsNum, oneSingleJson);
|
||||||
|
} else {
|
||||||
|
SerialPrint("E", F("Loging"), "wrong publishType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +268,7 @@ class Loging : public IoTItem {
|
|||||||
generateEvent(_id, value);
|
generateEvent(_id, value);
|
||||||
publishStatusMqtt(_id, value);
|
publishStatusMqtt(_id, value);
|
||||||
String json = createSingleJson(_id, value);
|
String json = createSingleJson(_id, value);
|
||||||
publishChartWs(json);
|
publishChartWs(-1, json);
|
||||||
SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +320,8 @@ class Date : public IoTItem {
|
|||||||
if ((*it)->getSubtype() == "Loging") {
|
if ((*it)->getSubtype() == "Loging") {
|
||||||
//отправляем только свои данные
|
//отправляем только свои данные
|
||||||
if ((*it)->getID() == selectToMarker(id, "-")) {
|
if ((*it)->getID() == selectToMarker(id, "-")) {
|
||||||
(*it)->sendChart(3);
|
(*it)->setPublishType(3, -1);
|
||||||
|
(*it)->sendChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user