mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
переименования и прочее
This commit is contained in:
@@ -18,17 +18,13 @@ void mqttSubscribe();
|
|||||||
boolean publish(const String& topic, const String& data);
|
boolean publish(const String& topic, const String& data);
|
||||||
boolean publishData(const String& topic, const String& data);
|
boolean publishData(const String& topic, const String& data);
|
||||||
boolean publishChartMqtt(const String& topic, const String& data);
|
boolean publishChartMqtt(const String& topic, const String& data);
|
||||||
boolean publishControl(String id, String topic, String state);
|
|
||||||
boolean publishJsonMqtt(const String& topic, const String& json);
|
boolean publishJsonMqtt(const String& topic, const String& json);
|
||||||
boolean publishStatusMqtt(const String& topic, const String& data);
|
boolean publishStatusMqtt(const String& topic, const String& data);
|
||||||
boolean publishEvent(const String& topic, const String& data);
|
boolean publishEvent(const String& topic, const String& data);
|
||||||
boolean publishInfo(const String& topic, const String& data);
|
|
||||||
boolean publishAnyJsonKeyMqtt(const String& topic, const String& key, const String& data);
|
|
||||||
bool publishChartFileToMqtt(String path, String id, int maxCount);
|
bool publishChartFileToMqtt(String path, String id, int maxCount);
|
||||||
|
|
||||||
void publishWidgets();
|
void publishWidgets();
|
||||||
void publishMainWidgetsValues();
|
|
||||||
void publishSubWidgetsValues();
|
|
||||||
|
|
||||||
void mqttCallback(char* topic, uint8_t* payload, size_t length);
|
void mqttCallback(char* topic, uint8_t* payload, size_t length);
|
||||||
void handleMqttStatus(bool send);
|
void handleMqttStatus(bool send);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ extern void hexdump(const void* mem, uint32_t len, uint8_t cols);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void publishStatusWs(const String& topic, const String& data);
|
void publishStatusWs(const String& topic, const String& data);
|
||||||
void publishChartWs(int num, String& path);
|
void publishJsonWs(const String& topic, String& json);
|
||||||
void periodicWsSend();
|
void periodicWsSend();
|
||||||
|
|
||||||
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, int client_id, size_t frameSize);
|
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, int client_id, size_t frameSize);
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class IoTItem {
|
|||||||
bool isGlobal();
|
bool isGlobal();
|
||||||
|
|
||||||
void sendSubWidgetsValues(String& id, String& json);
|
void sendSubWidgetsValues(String& id, String& json);
|
||||||
virtual void onMqttWsAppConnectEvent();
|
|
||||||
|
|
||||||
void setInterval(long interval);
|
void setInterval(long interval);
|
||||||
void setIntFromNet(int interval);
|
void setIntFromNet(int interval);
|
||||||
@@ -52,11 +51,12 @@ class IoTItem {
|
|||||||
String getRoundValue();
|
String getRoundValue();
|
||||||
void getNetEvent(String& event);
|
void getNetEvent(String& event);
|
||||||
|
|
||||||
// хуки для системных событий
|
// хуки для системных событий (должны начинаться с "on")
|
||||||
virtual void onRegEvent(IoTItem* item);
|
virtual void onRegEvent(IoTItem* item);
|
||||||
virtual void onMqttRecive(String& topic, String& msg);
|
virtual void onMqttRecive(String& topic, String& msg);
|
||||||
|
virtual void onMqttWsAppConnectEvent();
|
||||||
|
|
||||||
//методы для графиков
|
//методы для графиков (будет упрощено)
|
||||||
virtual void publishValue();
|
virtual void publishValue();
|
||||||
virtual void clearValue();
|
virtual void clearValue();
|
||||||
virtual void setPublishDestination(int type, int wsNum = -1);
|
virtual void setPublishDestination(int type, int wsNum = -1);
|
||||||
|
|||||||
@@ -125,19 +125,26 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
payloadStr += (char)payload[i];
|
payloadStr += (char)payload[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// распространяем принятое сообщение через хуки
|
// генерация события прихода mqtt сообщения в модуле
|
||||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||||
(*it)->onMqttRecive(topicStr, payloadStr);
|
(*it)->onMqttRecive(topicStr, payloadStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payloadStr.startsWith("HELLO")) {
|
if (payloadStr.startsWith("HELLO")) {
|
||||||
SerialPrint("i", F("MQTT"), F("Full update"));
|
SerialPrint("i", F("MQTT"), F("Full update"));
|
||||||
publishWidgets();
|
|
||||||
publishMainWidgetsValues();
|
|
||||||
publishSubWidgetsValues();
|
|
||||||
|
|
||||||
//обращение к логированию из ядра
|
//публикация всех виджетов
|
||||||
//отправка данных графиков
|
publishWidgets();
|
||||||
|
|
||||||
|
//публикация всех статус сообщений при подключении приложения и генерация события подключения приложения в модулях
|
||||||
|
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||||
|
if ((*it)->iAmLocal) {
|
||||||
|
publishStatusMqtt((*it)->getID(), (*it)->getValue());
|
||||||
|
(*it)->onMqttWsAppConnectEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//отправка данных графиков - данный код будет оптимизирован после завершения написания приложения с новыми графиками
|
||||||
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" || "LogingDaily") {
|
if ((*it)->getSubtype() == "Loging" || "LogingDaily") {
|
||||||
(*it)->setPublishDestination(TO_MQTT);
|
(*it)->setPublishDestination(TO_MQTT);
|
||||||
@@ -183,14 +190,6 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
generateOrder(id, payloadStr);
|
generateOrder(id, payloadStr);
|
||||||
SerialPrint("i", F("=>MQTT"), "Received direct order " + id + " " + payloadStr);
|
SerialPrint("i", F("=>MQTT"), "Received direct order " + id + " " + payloadStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// else if (topicStr.indexOf("info") != -1) {
|
|
||||||
// if (topicStr.indexOf("scen") != -1) {
|
|
||||||
// writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
|
||||||
// loadScenario();
|
|
||||||
// SerialPrint("i", F("=>MQTT"), F("Scenario received"));
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean publish(const String& topic, const String& data) {
|
boolean publish(const String& topic, const String& data) {
|
||||||
@@ -219,16 +218,6 @@ boolean publishChartMqtt(const String& topic, const String& data) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean publishControl(String id, String topic, String state) {
|
|
||||||
String path = mqttPrefix + "/" + id + "/" + topic + "/control";
|
|
||||||
return mqtt.publish(path.c_str(), state.c_str(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean publishJsonMqtt(const String& topic, const String& json) {
|
|
||||||
String path = mqttRootDevice + "/" + topic + "/status";
|
|
||||||
return mqtt.publish(path.c_str(), json.c_str(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean publishStatusMqtt(const String& topic, const String& data) {
|
boolean publishStatusMqtt(const String& topic, const String& data) {
|
||||||
String path = mqttRootDevice + "/" + topic + "/status";
|
String path = mqttRootDevice + "/" + topic + "/status";
|
||||||
String json = "{}";
|
String json = "{}";
|
||||||
@@ -236,10 +225,8 @@ boolean publishStatusMqtt(const String& topic, const String& data) {
|
|||||||
return mqtt.publish(path.c_str(), json.c_str(), false);
|
return mqtt.publish(path.c_str(), json.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean publishAnyJsonKeyMqtt(const String& topic, const String& key, const String& data) {
|
boolean publishJsonMqtt(const String& topic, const String& json) {
|
||||||
String path = mqttRootDevice + "/" + topic + "/status";
|
String path = mqttRootDevice + "/" + topic + "/status";
|
||||||
String json = "{}";
|
|
||||||
jsonWriteStr(json, key, data);
|
|
||||||
return mqtt.publish(path.c_str(), json.c_str(), false);
|
return mqtt.publish(path.c_str(), json.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,11 +235,6 @@ boolean publishEvent(const String& topic, const String& data) {
|
|||||||
return mqtt.publish(path.c_str(), data.c_str(), false);
|
return mqtt.publish(path.c_str(), data.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean publishInfo(const String& topic, const String& data) {
|
|
||||||
String path = mqttRootDevice + "/" + topic + "/info";
|
|
||||||
return mqtt.publish(path.c_str(), data.c_str(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void publishWidgets() {
|
void publishWidgets() {
|
||||||
auto file = seekFile("layout.json");
|
auto file = seekFile("layout.json");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -273,38 +255,6 @@ void publishWidgets() {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//устаревшая версия к удалению
|
|
||||||
// void publishMainWidgetsValues() {
|
|
||||||
// String json = getParamsJson();
|
|
||||||
// SerialPrint("i", F("DATA"), json);
|
|
||||||
// json.replace("{", "");
|
|
||||||
// json.replace("}", "");
|
|
||||||
// json.replace("\"", "");
|
|
||||||
// json += ",";
|
|
||||||
// while (json.length() != 0) {
|
|
||||||
// String tmp = selectToMarker(json, ",");
|
|
||||||
// String topic = selectToMarker(tmp, ":");
|
|
||||||
// String state = deleteBeforeDelimiter(tmp, ":");
|
|
||||||
// if (topic != "" && state != "") {
|
|
||||||
// publishStatusMqtt(topic, state);
|
|
||||||
// }
|
|
||||||
// json = deleteBeforeDelimiter(json, ",");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//оптимизированная версия
|
|
||||||
void publishMainWidgetsValues() {
|
|
||||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
|
||||||
if ((*it)->iAmLocal) publishStatusMqtt((*it)->getID(), (*it)->getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void publishSubWidgetsValues() {
|
|
||||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
|
||||||
if ((*it)->iAmLocal) (*it)->onMqttWsAppConnectEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool publishChartFileToMqtt(String path, String id, int maxCount) {
|
bool publishChartFileToMqtt(String path, String id, int maxCount) {
|
||||||
File configFile = FileFS.open(path, FILE_READ);
|
File configFile = FileFS.open(path, FILE_READ);
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
@@ -325,7 +275,6 @@ void handleMqttStatus(bool send) {
|
|||||||
String stateStr = getStateStr(mqtt.state());
|
String stateStr = getStateStr(mqtt.state());
|
||||||
// Serial.println(stateStr);
|
// Serial.println(stateStr);
|
||||||
jsonWriteStr_(errorsHeapJson, F("mqtt"), stateStr);
|
jsonWriteStr_(errorsHeapJson, F("mqtt"), stateStr);
|
||||||
|
|
||||||
if (!send) sendStringToWs("errors", errorsHeapJson, -1);
|
if (!send) sendStringToWs("errors", errorsHeapJson, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,8 +285,6 @@ void handleMqttStatus(bool send, int state) {
|
|||||||
if (!send) sendStringToWs("errors", errorsHeapJson, -1);
|
if (!send) sendStringToWs("errors", errorsHeapJson, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log-20384820.txt
|
|
||||||
|
|
||||||
const String getStateStr(int e) {
|
const String getStateStr(int e) {
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case -4: //Нет ответа от сервера
|
case -4: //Нет ответа от сервера
|
||||||
|
|||||||
@@ -54,21 +54,25 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
// Страница веб интерфейса dashboard
|
// Страница веб интерфейса dashboard
|
||||||
//----------------------------------------------------------------------//
|
//----------------------------------------------------------------------//
|
||||||
|
|
||||||
//отвечаем данными на запрос страницы
|
//публикация всех виджетов
|
||||||
if (headerStr == "/|") {
|
if (headerStr == "/|") {
|
||||||
sendFileToWsByFrames("/layout.json", "layout", "", num, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames("/layout.json", "layout", "", num, WEB_SOCKETS_FRAME_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//отвечаем на запрос параметров
|
|
||||||
if (headerStr == "/params|") {
|
if (headerStr == "/params|") {
|
||||||
|
//публикация всех статус сообщений при подключении svelte приложения
|
||||||
String params = "{}";
|
String 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendStringToWs("params", params, num);
|
sendStringToWs("params", params, num);
|
||||||
|
|
||||||
|
//генерация события подключения в модулях
|
||||||
|
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||||
|
if ((*it)->iAmLocal) (*it)->onMqttWsAppConnectEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//отвечаем на запрос графиков
|
//отвечаем на запрос графиков
|
||||||
@@ -261,7 +265,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//публикация статус сообщений (недостаток в том что делаем бродкаст всем клиентам поднятым в свелте!!!)
|
//публикация статус сообщений в ws (недостаток в том что делаем бродкаст всем клиентам поднятым в свелте!!!)
|
||||||
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 = "{}";
|
||||||
@@ -270,8 +274,12 @@ void publishStatusWs(const String& topic, const String& data) {
|
|||||||
sendStringToWs("status", json, -1);
|
sendStringToWs("status", json, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishChartWs(int num, String& path) {
|
//публикация дополнительных json сообщений в ws
|
||||||
// sendFileToWs(path, num, 1000);
|
void publishJsonWs(const String& topic, String& json) {
|
||||||
|
String path = mqttRootDevice + "/" + topic;
|
||||||
|
jsonWriteStr(json, "topic", path);
|
||||||
|
// TO DO отправка полей в веб
|
||||||
|
// sendStringToWs("status", json, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//данные которые мы отправляем в сокеты переодически
|
//данные которые мы отправляем в сокеты переодически
|
||||||
@@ -375,7 +383,6 @@ void sendStringToWs(const String& header, String& payload, int client_id) {
|
|||||||
|
|
||||||
String msg = header + "|0012|" + payload;
|
String msg = header + "|0012|" + payload;
|
||||||
size_t totalSize = msg.length();
|
size_t totalSize = msg.length();
|
||||||
// Serial.println("Send string '" + header + "', str size: " + String(totalSize));
|
|
||||||
|
|
||||||
char dataArray[totalSize];
|
char dataArray[totalSize];
|
||||||
msg.toCharArray(dataArray, totalSize + 1);
|
msg.toCharArray(dataArray, totalSize + 1);
|
||||||
|
|||||||
@@ -79,15 +79,13 @@ void IoTItem::setValue(const IoTValue& Value, bool genEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//метод отправки из модуля дополнительных json полей виджета в приложение и веб интерфейс, необходимый для изменения виджетов "на лету" из модуля
|
//метод отправки из модуля дополнительных json полей виджета в приложение и веб интерфейс,
|
||||||
|
//необходимый для изменения виджетов "на лету" из модуля
|
||||||
void IoTItem::sendSubWidgetsValues(String& id, String& json) {
|
void IoTItem::sendSubWidgetsValues(String& id, String& json) {
|
||||||
publishJsonMqtt(id, json);
|
publishJsonMqtt(id, json);
|
||||||
// to do publishJsonWs
|
publishJsonWs(id, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
//событие когда пользователь подключается приложением или веб интерфейсом к усройству
|
|
||||||
void IoTItem::onMqttWsAppConnectEvent() {}
|
|
||||||
|
|
||||||
//когда событие случилось
|
//когда событие случилось
|
||||||
void IoTItem::regEvent(const String& value, const String& consoleInfo, bool error, bool genEvent) {
|
void IoTItem::regEvent(const String& value, const String& consoleInfo, bool error, bool genEvent) {
|
||||||
if (_needSave) {
|
if (_needSave) {
|
||||||
@@ -115,7 +113,6 @@ void IoTItem::regEvent(const String& value, const String& consoleInfo, bool erro
|
|||||||
publishEvent(_id, json);
|
publishEvent(_id, json);
|
||||||
SerialPrint("i", F("<=MQTT"), "Broadcast event: " + json);
|
SerialPrint("i", F("<=MQTT"), "Broadcast event: " + json);
|
||||||
}
|
}
|
||||||
//========================================================================
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,18 +174,16 @@ void IoTItem::checkIntFromNet() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// хуки для системных событий (должны начинаться с "on")
|
||||||
void IoTItem::onRegEvent(IoTItem* item) {}
|
void IoTItem::onRegEvent(IoTItem* item) {}
|
||||||
|
|
||||||
void IoTItem::onMqttRecive(String& topic, String& msg) {}
|
void IoTItem::onMqttRecive(String& topic, String& msg) {}
|
||||||
|
void IoTItem::onMqttWsAppConnectEvent() {}
|
||||||
|
|
||||||
|
//методы для графиков (будет упрощено)
|
||||||
void IoTItem::publishValue() {}
|
void IoTItem::publishValue() {}
|
||||||
|
|
||||||
void IoTItem::clearValue() {}
|
void IoTItem::clearValue() {}
|
||||||
|
|
||||||
void IoTItem::setPublishDestination(int publishType, int wsNum){};
|
void IoTItem::setPublishDestination(int publishType, int wsNum){};
|
||||||
|
|
||||||
void IoTItem::clearHistory() {}
|
void IoTItem::clearHistory() {}
|
||||||
|
|
||||||
void IoTItem::setTodayDate() {}
|
void IoTItem::setTodayDate() {}
|
||||||
|
|
||||||
String IoTItem::getID() {
|
String IoTItem::getID() {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ class Loging : public IoTItem {
|
|||||||
//запускаем процедуру удаления старых файлов если память переполняется
|
//запускаем процедуру удаления старых файлов если память переполняется
|
||||||
deleteLastFile();
|
deleteLastFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDoByInterval(String valse) {
|
void SetDoByInterval(String valse) {
|
||||||
String value = valse;
|
String value = valse;
|
||||||
//если значение логгирования пустое
|
//если значение логгирования пустое
|
||||||
|
|||||||
Reference in New Issue
Block a user