diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index c87f925c..890173d5 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -51,6 +51,7 @@ class IoTItem { // хуки для системных событий virtual void onRegEvent(IoTItem* item); + virtual void onMqttRecive(char* topic, uint8_t* payload, size_t length); //методы для графиков virtual void publishValue(); diff --git a/include/classes/IoTScenario.h b/include/classes/IoTScenario.h index c1a6cf83..bee35bb0 100644 --- a/include/classes/IoTScenario.h +++ b/include/classes/IoTScenario.h @@ -51,7 +51,7 @@ class IoTScenario { int GetTokPrecedence(); /// Error* - Это небольшие вспомогательные функции для обработки ошибок. - ExprAST *Error(const char *Str); + ExprAST *Error(const String& Str); /// identifierexpr /// ::= identifier diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index e86131ce..77a89e6f 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -117,6 +117,11 @@ void mqttSubscribe() { } void mqttCallback(char* topic, uint8_t* payload, size_t length) { + // распространяем принятое сообщение через хуки + for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { + (*it)->onMqttRecive(topic, payload, length); + } + String topicStr = String(topic); // SerialPrint("i", "=>MQTT", topicStr); String payloadStr; @@ -188,7 +193,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) { // loadScenario(); // SerialPrint("i", F("=>MQTT"), F("Scenario received")); // } - //} + //} } boolean publish(const String& topic, const String& data) { diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 095e6c18..063ae3cb 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -175,6 +175,8 @@ void IoTItem::checkIntFromNet() { void IoTItem::onRegEvent(IoTItem* item) {} +void IoTItem::onMqttRecive(char* topic, uint8_t* payload, size_t length) {} + void IoTItem::publishValue() {} void IoTItem::clearValue() {} diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index 0d30e477..8173ffb9 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -296,7 +296,7 @@ class CallExprAST : public ExprAST { //if (!ItemIsLocal) Item = findIoTItem(Callee); // пробуем найти переменную если она не локальная (могла придти по сети в процессе) if (!Item) return nullptr; // ret = zeroIotVal; // если все же не пришла, то либо опечатка, либо уже стерлась - выходим - if (Cmd == "getIntFromNet") { + if (Cmd == F("getIntFromNet")) { ret.valD = Item->getIntFromNet(); ret.isDecimal = true; return &ret; @@ -467,43 +467,43 @@ class SysCallExprAST : public ExprAST { public: SysCallExprAST(const String &callee, std::vector &args) : Callee(callee), Args(args) { - if (Callee == "reboot") + if (Callee == F("reboot")) operation = sysop_reboot; - else if (Callee == "digitalRead") + else if (Callee == F("digitalRead")) operation = sysop_digitalRead; - else if (Callee == "analogRead") + else if (Callee == F("analogRead")) operation = sysop_analogRead; - else if (Callee == "digitalWrite") + else if (Callee == F("digitalWrite")) operation = sysop_digitalWrite; - else if (Callee == "digitalInvert") + else if (Callee == F("digitalInvert")) operation = sysop_digitalInvert; - else if (Callee == "deepSleep") + else if (Callee == F("deepSleep")) operation = sysop_deepSleep; - else if (Callee == "getTime") + else if (Callee == F("getTime")) operation = sysop_getTime; - else if (Callee == "getHours") + else if (Callee == F("getHours")) operation = sysop_getHours; - else if (Callee == "getMinutes") + else if (Callee == F("getMinutes")) operation = sysop_getMinutes; - else if (Callee == "getSeconds") + else if (Callee == F("getSeconds")) operation = sysop_getSeconds; - else if (Callee == "getMonth") + else if (Callee == F("getMonth")) operation = sysop_getMonth; - else if (Callee == "getDay") + else if (Callee == F("getDay")) operation = sysop_getDay; - else if (Callee == "getRSSI") + else if (Callee == F("getRSSI")) operation = sysop_getRSSI; - else if (Callee == "getIP") + else if (Callee == F("getIP")) operation = sysop_getIP; - else if (Callee == "mqttPub") + else if (Callee == F("mqttPub")) operation = sysop_mqttPub; - else if (Callee == "gethhmm") + else if (Callee == F("gethhmm")) operation = sysop_gethhmm; - else if (Callee == "gethhmmss") + else if (Callee == F("gethhmmss")) operation = sysop_gethhmmss; - else if (Callee == "getTime") + else if (Callee == F("getTime")) operation = sysop_getTime; - else if (Callee == "getUptime") + else if (Callee == F("getUptime")) operation = sysop_getUptime; else operation = sysop_notfound; @@ -775,7 +775,6 @@ int IoTScenario::gettok() { /// токен, просматриваемый парсером. getNextToken получает следующий токен от /// лексического анализатора и обновляет CurTok. int IoTScenario::getNextToken() { - scenario_yield(); return CurTok = gettok(); } @@ -791,8 +790,8 @@ int IoTScenario::GetTokPrecedence() { } /// Error* - Это небольшие вспомогательные функции для обработки ошибок. -ExprAST *IoTScenario::Error(const char *Str) { - Serial.printf("Scenario error in line %d: %s\n", curLine, Str); +ExprAST *IoTScenario::Error(const String& Str) { + Serial.printf("Scenario error in line %d: %s\n", curLine, Str.c_str()); isIotScenException = true; return nullptr; } @@ -835,7 +834,7 @@ ExprAST *IoTScenario::ParseIdentifierExpr(String *IDNames, bool callFromConditio if (CurTok == ')') break; if (CurTok != ',') { - return Error("Expected ')' or ',' in argument list"); + return Error(F("Expected ')' or ',' in argument list")); } getNextToken(); } @@ -892,7 +891,7 @@ ExprAST *IoTScenario::ParseBracketsExpr(String *IDNames, bool callFromCondition) // int ttok = getNextToken(); if (CurTok == tok_eof) { - return Error("Expected '}'"); + return Error(F("Expected '}'")); } } @@ -947,7 +946,7 @@ ExprAST *IoTScenario::ParsePrimary(String *IDNames, bool callFromCondition) { switch (CurTok) { default: Serial.println(CurTok); - return Error("unknown token when expecting an expression"); + return Error(F("unknown token when expecting an expression")); case tok_identifier: { if (callFromCondition && IDNames) { String tmpstr = *IDNames; @@ -1019,13 +1018,13 @@ void IoTScenario::loadScenario(String fileName) { // подготавливае if (file) file.close(); file = FileFS.open(fileName.c_str(), "r"); if (!file) { - Error("Open file scenario error"); + Error(F("Open file scenario error")); return; } } else if (mode == 1) { file = FileFS.open(fileName.c_str(), "r"); if (!file) { - Error("Open file scenario error"); + Error(F("Open file scenario error")); return; } strFromFile = file.readString(); diff --git a/src/modules/virtual/Variable/modinfo.json b/src/modules/virtual/Variable/modinfo.json index 85f957b4..9b01d4d8 100644 --- a/src/modules/virtual/Variable/modinfo.json +++ b/src/modules/virtual/Variable/modinfo.json @@ -56,6 +56,23 @@ "descr": "Введите текст", "int": "0", "val": "текст" + }, + { + "global": 0, + "name": "Вывод значения", + "type": "Reading", + "subtype": "Variable", + "id": "vout", + "needSave": 0, + "widget": "anydataDef", + "page": "Вывод", + "descr": "Значение", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 } ], "about": { diff --git a/src/utils/SerialPrint.cpp b/src/utils/SerialPrint.cpp index a1e8fde2..8ed907e2 100644 --- a/src/utils/SerialPrint.cpp +++ b/src/utils/SerialPrint.cpp @@ -13,7 +13,7 @@ void SerialPrint(const String& errorLevel, const String& module, const String& m if (isNetworkActive()) { if (jsonReadInt(settingsFlashJson, F("log")) != 0) { - sendStringToWs("corelg", tosend, -1); + sendStringToWs(F("corelg"), tosend, -1); } } @@ -21,7 +21,7 @@ void SerialPrint(const String& errorLevel, const String& module, const String& m cleanString(tosend); // создаем событие об ошибке для возможной реакции в сценарии if (itemId != "") { - createItemFromNet(itemId + "_onError", tosend, -4); + createItemFromNet(itemId + F("_onError"), tosend, -4); } else { // createItemFromNet("onError", tosend, -4); }