From d4c2eeb752747b33a48c69a14f831eea71db7fe3 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 28 Nov 2022 07:46:15 +0300 Subject: [PATCH 01/13] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D1=83=20Mcp23008?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/Mcp23008/Mcp23008.cpp | 85 ++++++++++++++++++++++++++ src/modules/exec/Mcp23008/modinfo.json | 67 ++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/modules/exec/Mcp23008/Mcp23008.cpp create mode 100644 src/modules/exec/Mcp23008/modinfo.json diff --git a/src/modules/exec/Mcp23008/Mcp23008.cpp b/src/modules/exec/Mcp23008/Mcp23008.cpp new file mode 100644 index 00000000..fef91121 --- /dev/null +++ b/src/modules/exec/Mcp23008/Mcp23008.cpp @@ -0,0 +1,85 @@ +#include "Global.h" +#include "classes/IoTItem.h" +#include "classes/IoTGpio.h" +#include + +class Mcp23008Driver : public IoTGpio { + private: + Adafruit_MCP23X08 _mcp; + + public: + Mcp23008Driver(int index, String addr) : IoTGpio(index) { + if (!_mcp.begin_I2C(hexStringToUint8(addr))) { + Serial.println("MCP23X08 Init Error."); + } + } + + void pinMode(uint8_t pin, uint8_t mode) { + _mcp.pinMode(pin, mode); + } + + void digitalWrite(uint8_t pin, uint8_t val) { + _mcp.digitalWrite(pin, val); + } + + int digitalRead(uint8_t pin) { + return _mcp.digitalRead(pin); + } + + void digitalInvert(uint8_t pin) { + _mcp.digitalWrite(pin, 1 - _mcp.digitalRead(pin)); + } + + ~Mcp23008Driver() {}; +}; + + +class Mcp23008 : public IoTItem { + private: + Mcp23008Driver* _driver; + String _addr; + + public: + Mcp23008(String parameters) : IoTItem(parameters) { + _driver = nullptr; + + jsonRead(parameters, "addr", _addr); + if (_addr == "") { + scanI2C(); + return; + } + + int index; + jsonRead(parameters, "index", index); + if (index > 4) { + Serial.println("MCP23X08 wrong index. Must be 0 - 4"); + return; + } + + _driver = new Mcp23008Driver(index, _addr); + } + + void doByInterval() { + if (_addr == "") { + scanI2C(); + return; + } + } + + //возвращает ссылку на экземпляр класса Mcp23008Driver + IoTGpio* getGpioDriver() { + return _driver; + } + + ~Mcp23008() { + delete _driver; + }; +}; + +void* getAPI_Mcp23008(String subtype, String param) { + if (subtype == F("Mcp23008")) { + return new Mcp23008(param); + } else { + return nullptr; + } +} diff --git a/src/modules/exec/Mcp23008/modinfo.json b/src/modules/exec/Mcp23008/modinfo.json new file mode 100644 index 00000000..6181b062 --- /dev/null +++ b/src/modules/exec/Mcp23008/modinfo.json @@ -0,0 +1,67 @@ +{ + "menuSection": "Исполнительные устройства", + + "configItem": [{ + "global": 0, + "name": "Расширитель портов Mcp23008", + "type": "Reading", + "subtype": "Mcp23008", + "id": "Mcp", + "widget": "", + "page": "", + "descr": "", + + "int": "0", + "addr": "0x20", + "index": 1 + }], + + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "specialThanks": "", + "moduleName": "Mcp23008", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Расширитель портов Mcp23008", + "moduleDesc": "Добавляет в систему дополнительные GPIO для элементов, которые поддерживают такую функцию.", + "propInfo": { + "int": "Не используется", + "addr": "Адрес устройства на шине, обычно 0x20", + "index": "Значения от 1 до 4, где при выборе 1 будет нумерация pin 100-115, при выборе 2 200-215 и т.д." + } + }, + + "defActive": false, + + "usedLibs": { + "esp32_4mb": [ + "adafruit/Adafruit Mcp23017 Arduino Library@^2.1.0", + "adafruit/Adafruit BusIO @ ^1.13.2" + ], + "esp8266_4mb": [ + "adafruit/Adafruit Mcp23017 Arduino Library@^2.1.0", + "adafruit/Adafruit BusIO @ ^1.13.2" + ], + "esp8266_1mb": [ + "adafruit/Adafruit Mcp23017 Arduino Library@^2.1.0", + "adafruit/Adafruit BusIO @ ^1.13.2" + ], + "esp8266_1mb_ota": [ + "adafruit/Adafruit Mcp23017 Arduino Library@^2.1.0", + "adafruit/Adafruit BusIO @ ^1.13.2" + ], + "esp8285_1mb": [ + "adafruit/Adafruit Mcp23017 Arduino Library@^2.1.0", + "adafruit/Adafruit BusIO @ ^1.13.2" + ], + "esp8285_1mb_ota": [ + "adafruit/Adafruit Mcp23017 Arduino Library@^2.1.0", + "adafruit/Adafruit BusIO @ ^1.13.2" + ] + } +} \ No newline at end of file From 4d1ef99939607c08773699fa6c45b0530f2e6615 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 2 Dec 2022 13:56:31 +0300 Subject: [PATCH 02/13] =?UTF-8?q?=D0=9E=D0=BA=D1=80=D1=83=D0=B3=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B2=20=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTItem.cpp | 3 ++- src/classes/IoTScenario.cpp | 19 +++++++++++-------- src/modules/sensors/UART/Uart.cpp | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index e8afe357..f75b86fc 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -122,7 +122,8 @@ String IoTItem::getRoundValue() { char buf[15]; sprintf(buf, ("%1." + (String)_round + "f").c_str(), value.valD); - return (String)buf; + value.valS = (String)buf; + return value.valS; } else { return (String)value.valD; } diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index 8173ffb9..1643751c 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -112,6 +112,7 @@ class VariableExprAST : public ExprAST { // if (Item->value.isDecimal) // Serial.printf("Call from VariableExprAST: %s = %f\n", Name.c_str(), Item->value.valD); // else Serial.printf("Call from VariableExprAST: %s = %s\n", Name.c_str(), Item->value.valS.c_str()); + Item->getRoundValue(); return &(Item->value); } @@ -222,15 +223,17 @@ class BinaryExprAST : public ExprAST { } if (!lhs->isDecimal || !rhs->isDecimal) { - if (lhs->isDecimal) - lhsStr = (String)lhs->valD; - else - lhsStr = lhs->valS; + // if (lhs->isDecimal) + // lhsStr = (String)lhs->valD; + // else + // lhsStr = lhs->valS; - if (rhs->isDecimal) - rhsStr = (String)rhs->valD; - else - rhsStr = rhs->valS; + // if (rhs->isDecimal) + // rhsStr = (String)rhs->valD; + // else + // rhsStr = rhs->valS; + lhsStr = lhs->valS; + rhsStr = rhs->valS; switch (Op) { case tok_equal: diff --git a/src/modules/sensors/UART/Uart.cpp b/src/modules/sensors/UART/Uart.cpp index a6d5040e..c75b7db1 100644 --- a/src/modules/sensors/UART/Uart.cpp +++ b/src/modules/sensors/UART/Uart.cpp @@ -169,13 +169,15 @@ class UART : public IoTItem { IoTValue execute(String command, std::vector ¶m) { if (command == "println") { if (param.size() == 1) { - if (param[0].isDecimal) uartPrintln((String)param[0].valD); - else uartPrintln(param[0].valS); + //if (param[0].isDecimal) uartPrintln((String)param[0].valD); + //else uartPrintln(param[0].valS); + uartPrintln(param[0].valS); } } else if (command == "print") { if (param.size() == 1) { - if (param[0].isDecimal) uartPrint((String)param[0].valD); - else uartPrint(param[0].valS); + //if (param[0].isDecimal) uartPrint((String)param[0].valD); + //else uartPrint(param[0].valS); + uartPrintln(param[0].valS); } } else if (command == "printHex") { if (param.size() == 1) { @@ -184,10 +186,11 @@ class UART : public IoTItem { } else if (command == "printFFF") { if (param.size() == 2) { String strToUart = ""; - if (param[0].isDecimal) - strToUart = param[0].valD; - else - strToUart = param[0].valS; + // if (param[0].isDecimal) + // strToUart = param[0].valD; + // else + // strToUart = param[0].valS; + strToUart = param[0].valS; if (param[1].valD) uartPrintFFF("\"" + strToUart + "\""); From 8d6ab1ee8a3e6a6faef7768b581a1c5c4e1bd258 Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 22 Dec 2022 11:01:44 +0300 Subject: [PATCH 03/13] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20IP=20?= =?UTF-8?q?=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=B0=20=D0=B2=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=20=D0=BF=D1=80=D0=B8=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=83=D1=81=D0=B0=20WIFI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MqttClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 75dec971..a74c66ca 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -6,7 +6,7 @@ void mqttInit() { WIFI_MQTT_CONNECTION_CHECK, MQTT_RECONNECT_INTERVAL, [&](void*) { if (WiFi.status() == WL_CONNECTED) { - SerialPrint("i", F("WIFI"), F("OK")); + SerialPrint("i", F("WIFI"), "OK: " + jsonReadStr(settingsFlashJson, F("ip"))); wifiUptimeCalc(); if (mqtt.connected()) { SerialPrint("i", F("MQTT"), "OK"); From 9871963cbb38744038445ea63a3518531c7e56fa Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 22 Dec 2022 15:00:25 +0300 Subject: [PATCH 04/13] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D0=BC=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=BD=D0=B0=D1=80=D0=BD=D1=8B=D1=85=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B8=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20=D0=B2=20=D1=81?= =?UTF-8?q?=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B8=20=D0=BA=D0=BE=D0=B3?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=B8=D0=B7=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=B2=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D1=87=D0=B8=D1=81=D0=BB=D0=BE=20=D0=B8=D0=BB=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0=20=D0=94=D0=BE?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC?= =?UTF-8?q?=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D0=B2=D1=8B?= =?UTF-8?q?=D1=80=D0=B5=D0=B7=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D0=B8=D0=B7=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D1=81=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=20-=20(=D0=BC=D0=B8=D0=BD=D1=83=D1=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTItem.cpp | 6 ++- src/classes/IoTScenario.cpp | 81 ++++++++++++++----------------------- 2 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 34d4b21b..702e96aa 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -63,6 +63,7 @@ void IoTItem::setValue(const String& valStr, bool genEvent) { if (value.isDecimal) { value.valD = valStr.toFloat(); + getRoundValue(); } else { value.valS = valStr; } @@ -117,6 +118,8 @@ void IoTItem::regEvent(const String& value, const String& consoleInfo, bool erro } String IoTItem::getRoundValue() { + if (!value.isDecimal) return value.valS; + if (_round >= 0 && _round <= 6) { int sot = _round ? pow(10, (int)_round) : 1; value.valD = round(value.valD * sot) / sot; @@ -126,7 +129,8 @@ String IoTItem::getRoundValue() { value.valS = (String)buf; return value.valS; } else { - return (String)value.valD; + value.valS = (String)value.valD; + return value.valS; } } diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index 1643751c..bd6eaf26 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -126,7 +126,7 @@ class BinaryExprAST : public ExprAST { signed char Op; ExprAST *LHS, *RHS; IoTValue val; - String lhsStr, rhsStr; + //String lhsStr, rhsStr; public: BinaryExprAST(signed char op, ExprAST *lhs, ExprAST *rhs) @@ -140,21 +140,6 @@ class BinaryExprAST : public ExprAST { IoTValue *exec() { if (isIotScenException) return nullptr; - // String printStr = ""; - - // if (Op == tok_equal) - // printStr = "=="; - // else if (Op == tok_notequal) - // printStr = "!="; - // else if (Op == tok_lesseq) - // printStr = "<="; - // else if (Op == tok_greateq) - // printStr = ">="; - // else - // printStr = printStr + (char)Op; - - // Serial.printf("Call from BinaryExprAST: %s\n", printStr.c_str()); - if (RHS == nullptr || LHS == nullptr) return nullptr; IoTValue *rhs = RHS->exec(); // получаем значение правого операнда для возможного использования в операции присваивания @@ -171,8 +156,12 @@ class BinaryExprAST : public ExprAST { IoTValue *lhs = LHS->exec(); // если присваивания не произошло, значит операция иная и необходимо значение левого операнда if (lhs == nullptr) return nullptr; - - if (lhs->isDecimal && rhs->isDecimal) { + // все бинарные операции кроме +, - и == обязаны работать с числами + if (Op != '+' && Op != '-' && Op != tok_equal) { + // поэтому преобразовываем строки в булевые интерпретации + if (!lhs->isDecimal) lhs->valD = lhs->valS != ""; // пустая строка = false + if (!rhs->isDecimal) rhs->valD = rhs->valS != ""; // пустая строка = false + switch (Op) { case '>': val.valD = lhs->valD > rhs->valD; @@ -186,19 +175,10 @@ class BinaryExprAST : public ExprAST { case tok_greateq: val.valD = lhs->valD >= rhs->valD; break; - case tok_equal: - val.valD = lhs->valD == rhs->valD; - break; case tok_notequal: val.valD = lhs->valD != rhs->valD; break; - case '+': - val.valD = lhs->valD + rhs->valD; - break; - case '-': - val.valD = lhs->valD - rhs->valD; - break; case '*': val.valD = lhs->valD * rhs->valD; break; @@ -219,39 +199,40 @@ class BinaryExprAST : public ExprAST { default: break; } - return &val; - } - - if (!lhs->isDecimal || !rhs->isDecimal) { - // if (lhs->isDecimal) - // lhsStr = (String)lhs->valD; - // else - // lhsStr = lhs->valS; - - // if (rhs->isDecimal) - // rhsStr = (String)rhs->valD; - // else - // rhsStr = rhs->valS; - lhsStr = lhs->valS; - rhsStr = rhs->valS; - + } else { // иначе имеем дело с операциями + или - или ==, которые могут работать с разными типами данных switch (Op) { case tok_equal: - val.valD = compStr(lhsStr, rhsStr); + if (lhs->isDecimal && rhs->isDecimal) + val.valD = lhs->valD == rhs->valD; + else + val.valD = compStr(lhs->valS, rhs->valS); break; case '+': - val.valS = lhsStr + rhsStr; - val.valD = 1; - val.isDecimal = false; + if (lhs->isDecimal && rhs->isDecimal) + val.valD = lhs->valD + rhs->valD; + else { + val.valS = lhs->valS + rhs->valS; + val.valD = 1; + val.isDecimal = false; + } + break; + + case '-': + if (lhs->isDecimal && rhs->isDecimal) + val.valD = lhs->valD - rhs->valD; + else { + val.valS = lhs->valS; + val.valS.replace(rhs->valS, ""); + val.valD = 1; + val.isDecimal = false; + } break; default: break; } - return &val; - } - + } return &val; } From 5a9ee8ac6eeca2e0be71b69b6417e4e80071058a Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 22 Dec 2022 22:13:35 +0300 Subject: [PATCH 05/13] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=B5=D1=82=D1=8C=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B8=D0=B7=D0=BD=D0=B0=D0=BA=D1=83?= =?UTF-8?q?=20global=20=D1=83=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=20mqttin=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=D0=B5=D0=BC=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 702e96aa..c39ee125 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -106,7 +106,7 @@ void IoTItem::regEvent(const String& value, const String& consoleInfo, bool erro } // отправка события другим устройствам в сети если не было ошибки - if (jsonReadBool(settingsFlashJson, "mqttin") && _global && !error) { + if (_global && !error) { String json = "{}"; jsonWriteStr_(json, "id", _id); jsonWriteStr_(json, "val", value); From b2d4d211c7ebed7a7eed0d12287e3eaf03c6f837 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 23 Dec 2022 20:35:07 +0300 Subject: [PATCH 06/13] =?UTF-8?q?=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC,=20=D1=87=D1=82=D0=BE=20=D0=B2=20=D1=82=D0=B0?= =?UTF-8?q?=D0=B9=D0=BC=D0=B5=D1=80=D0=B5=20=D0=BF=D1=80=D0=B8=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B7=D0=BE=D0=B2=D0=B5=20int=20=D0=B8=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D1=83=D1=8E=D1=82=D1=81=D1=8F=20=D0=BC=D0=B8?= =?UTF-8?q?=D0=BB=D0=BB=D0=B8=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/virtual/Timer/modinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/virtual/Timer/modinfo.json b/src/modules/virtual/Timer/modinfo.json index 7f097b29..e817b398 100644 --- a/src/modules/virtual/Timer/modinfo.json +++ b/src/modules/virtual/Timer/modinfo.json @@ -32,7 +32,7 @@ "title": "Таймер обратного отсчета", "moduleDesc": "Добавляет инструмент таймеров обратного отсчета для организации периодичных операций или логических конструкций. Часто используется как вспомогательный элемент для автоматизации.", "propInfo": { - "int": "Задает размер в секундах одного шага(тика) таймера.", + "int": "Задает размер в миллисекундах (1000 = 1сек) одного шага(тика) таймера.", "countDown": "Начальное значение таймера, с которого начинается обратный отсчет. countDown=0 - бесконечный счет (имеет смысл при ticker=1, иначе таймер будет выключен), countDown=-1 - отключает таймер совсем (используется для запуска системы с выключенным таймером)", "ticker": "Генерировать(1) или нет(0) события при каждом тике таймера.", "repeat": "Сбрасывать(1) или нет(0) таймер в начальное состояние при достижении нуля.", From 33bc338449d8ba6e387f1eec7359c78fb70c6e7d Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 23 Dec 2022 20:36:16 +0300 Subject: [PATCH 07/13] =?UTF-8?q?=D0=9B=D0=BE=D0=BA=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=20PZEMSensor=20=D0=B2=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src => src/modules/sensors/Pzem004t}/PZEMSensor.cpp | 0 .../include => src/modules/sensors/Pzem004t}/PZEMSensor.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {lib/PZEMSensor/src => src/modules/sensors/Pzem004t}/PZEMSensor.cpp (100%) rename {lib/PZEMSensor/include => src/modules/sensors/Pzem004t}/PZEMSensor.h (100%) diff --git a/lib/PZEMSensor/src/PZEMSensor.cpp b/src/modules/sensors/Pzem004t/PZEMSensor.cpp similarity index 100% rename from lib/PZEMSensor/src/PZEMSensor.cpp rename to src/modules/sensors/Pzem004t/PZEMSensor.cpp diff --git a/lib/PZEMSensor/include/PZEMSensor.h b/src/modules/sensors/Pzem004t/PZEMSensor.h similarity index 100% rename from lib/PZEMSensor/include/PZEMSensor.h rename to src/modules/sensors/Pzem004t/PZEMSensor.h From 51909624af5471caea6526a93cd5fe200f30a6d4 Mon Sep 17 00:00:00 2001 From: biver Date: Sat, 24 Dec 2022 13:07:09 +0300 Subject: [PATCH 08/13] =?UTF-8?q?=D0=9B=D0=BE=D0=BA=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=20=D0=B2=D1=81=D0=B5=20=D1=83=D0=BF?= =?UTF-8?q?=D0=BE=D0=BC=D0=B8=D0=BD=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=20MyS?= =?UTF-8?q?ensors=20=D0=B2=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Const.h | 7 ------- src/modules/exec/MySensors/MySensorsGate.h | 2 ++ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/Const.h b/include/Const.h index 9e571944..e80ae50e 100644 --- a/include/Const.h +++ b/include/Const.h @@ -19,13 +19,6 @@ #define FIRMWARE_NAME "esp32_4mb" #endif -#define MYSENSORS - -//#ifdef esp32_4mb_ms -//#define FIRMWARE_NAME "esp32_4mb_ms" -//#define MYSENSORS -//#endif - //Размер буфера json #define JSON_BUFFER_SIZE 2048 //держим 2 кб не меняем #define WEB_SOCKETS_FRAME_SIZE 2048 diff --git a/src/modules/exec/MySensors/MySensorsGate.h b/src/modules/exec/MySensors/MySensorsGate.h index 5cacdadc..f12a8fc8 100644 --- a/src/modules/exec/MySensors/MySensorsGate.h +++ b/src/modules/exec/MySensors/MySensorsGate.h @@ -1,5 +1,7 @@ #pragma once #include "Const.h" +#define MYSENSORS + #ifdef MYSENSORS /* From 821aeb5ad2a9b2809c5606b613b97b135e1f6e67 Mon Sep 17 00:00:00 2001 From: avaksru Date: Mon, 26 Dec 2022 13:01:08 +0300 Subject: [PATCH 09/13] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=9F=D0=BE=D0=B3=D0=BE=D0=B4=D0=B0=20(Weather)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myProfile.json | 8 ++ src/modules/virtual/Weather/Weather.cpp | 153 +++++++++++++++++++++++ src/modules/virtual/Weather/modinfo.json | 53 ++++++++ 3 files changed, 214 insertions(+) create mode 100644 src/modules/virtual/Weather/Weather.cpp create mode 100644 src/modules/virtual/Weather/modinfo.json diff --git a/myProfile.json b/myProfile.json index a7c149a4..8d86cea2 100644 --- a/myProfile.json +++ b/myProfile.json @@ -53,6 +53,10 @@ { "path": "src/modules/virtual/VButton", "active": true + }, + { + "path": "src/modules/virtual/Weather", + "active": false } ], "Сенсоры": [ @@ -182,6 +186,10 @@ "path": "src/modules/exec/IoTServo", "active": true }, + { + "path": "src/modules/exec/Mcp23008", + "active": false + }, { "path": "src/modules/exec/Mcp23017", "active": true diff --git a/src/modules/virtual/Weather/Weather.cpp b/src/modules/virtual/Weather/Weather.cpp new file mode 100644 index 00000000..2ff85df4 --- /dev/null +++ b/src/modules/virtual/Weather/Weather.cpp @@ -0,0 +1,153 @@ +#include "Global.h" +#include "classes/IoTItem.h" +#include + +long prevWeatherMillis = millis() - 60001; +StaticJsonDocument Weatherdoc; + +extern IoTGpio IoTgpio; +class Weather : public IoTItem +{ +private: + String _location; + String _param; + long interval; + +public: + Weather(String parameters) : IoTItem(parameters) + { + _location = jsonReadStr(parameters, "location"); + _param = jsonReadStr(parameters, "param"); + jsonRead(parameters, F("int"), interval); + interval = interval * 1000 * 60 * 60; // интервал проверки погоды в часах + } + + void getWeather() + { + String ret; + + if (WiFi.status() == WL_CONNECTED) + { + // char c; + String payload; + WiFiClient client; + HTTPClient http; + http.begin(client, "http://live-control.com/iotm/weather.php"); + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + String httpRequestData = "loc=" + _location; + int httpResponseCode = http.POST(httpRequestData); + if (httpResponseCode > 0) + { + ret = httpResponseCode; + + if (httpResponseCode == HTTP_CODE_OK) + { + payload = http.getString(); + + deserializeJson(Weatherdoc, payload); + // ret += payload; + } + } + else + { + ret = http.errorToString(httpResponseCode).c_str(); + } + SerialPrint("<-", F("getWeather"), httpRequestData); + SerialPrint("->", F("getWeather"), "server: " + ret); + + http.end(); + } + } + + void doByInterval() + { + + if (prevWeatherMillis + 60000 < millis()) + { + getWeather(); + prevWeatherMillis = millis(); + } + if (jsonReadStr(Weatherdoc["current_condition"][0], "temp_C", true) != "null") + { + if (_param == "temp_C") + { + value.valS = jsonReadStr(Weatherdoc["current_condition"][0], "temp_C", true); + } + if (_param == "avgtempC") + { + value.valS = jsonReadStr(Weatherdoc["weather"][0], "avgtempC", true); + } + if (_param == "humidity") + { + value.valS = jsonReadStr(Weatherdoc["current_condition"][0], "humidity", true); + } + if (_param == "weatherCode") + { + value.valS = jsonReadStr(Weatherdoc["current_condition"][0], "weatherCode", true); + } + if (_param == "sunrise") + { + + value.valS = jsonReadStr(Weatherdoc["weather"][0]["astronomy"][0], "sunrise", true); + } + if (_param == "sunset") + { + value.valS = jsonReadStr(Weatherdoc["weather"][0]["astronomy"][0], "sunset", true); + } + + if (_param == "rangetempC") + { + value.valS = jsonReadStr(Weatherdoc["weather"][0], "mintempC", true) + "..." + jsonReadStr(Weatherdoc["weather"][0], "maxtempC", true); + } + + // погода на завтра + if (_param == "temp_C_tomorrow") + { + value.valS = jsonReadStr(Weatherdoc["weather"][1], "avgtempC", true); + } + if (_param == "rangetempC_tomorrow") + { + value.valS = jsonReadStr(Weatherdoc["weather"][1], "mintempC", true) + "..." + jsonReadStr(Weatherdoc["weather"][1], "maxtempC", true); + } + + regEvent(value.valS, "Weather"); + } + } + void loop() + { + if (enableDoByInt) + { + currentMillis = millis(); + difference = currentMillis - prevMillis; + if (difference >= interval) + { + prevMillis = millis(); + this->doByInterval(); + } + } + } + IoTValue execute(String command, std::vector ¶m) + { + if (command == "get") + { + getWeather(); + doByInterval(); + } + + return {}; + } + + ~Weather(){}; +}; + +void *getAPI_Weather(String subtype, String param) +{ + if (subtype == F("Weather")) + { + return new Weather(param); + } + else + { + return nullptr; + } +} diff --git a/src/modules/virtual/Weather/modinfo.json b/src/modules/virtual/Weather/modinfo.json new file mode 100644 index 00000000..0530ebdf --- /dev/null +++ b/src/modules/virtual/Weather/modinfo.json @@ -0,0 +1,53 @@ +{ + "menuSection": "Виртуальные элементы", + + "configItem": [ + { + "global": 0, + "name": "Погода", + "type": "Reading", + "subtype": "Weather", + "id": "Weather", + "needSave": 0, + "widget": "anydataDef", + "page": "Погода", + "descr": "", + "int": 3, + "location": "Moscow", + "param": "temp_C", + "round": 0, + "val": "..." + } + ], + + "about": { + "authorName": "AVAKS", + "authorContact": "https://t.me/@avaks_dev", + "authorGit": "https://github.com/avaksru", + "specialThanks": "", + "moduleName": "Weather", + "moduleVersion": "1", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Погода", + "moduleDesc": "Получение погоды из интернет", + "propInfo": { + "location": "Город.", + "param": "temp_C - температура, humidity - влажность, weatherCode - погодный код, sunrise - рассвет, sunset - закат, rangetempC - (-3...-10 C), temp_C_tomorrow - температура завтра, rangetempC_tomorrow - (-3...-10 C) на завтра", + "int": "Интервал запроса погоды в часах" + } + }, + + "defActive": false, + + "usedLibs": { + "esp32_4mb": [], + "esp8266_4mb": [], + "esp8266_1mb": [], + "esp8266_1mb_ota": [], + "esp8285_1mb": [], + "esp8285_1mb_ota": [] + } +} From ee279870850bb1a4b0e7e039b9cc470fd3925919 Mon Sep 17 00:00:00 2001 From: avaksru Date: Mon, 26 Dec 2022 13:04:52 +0300 Subject: [PATCH 10/13] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=A6=D0=B2=D0=B5=D1=82=D0=BD=D0=BE=D0=B9=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D1=82=20(VariableColor)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 162 ++++++++++-------- myProfile.json | 4 + platformio.ini | 1 + src/modules/API.cpp | 2 + .../virtual/VariableColor/VariableColor.cpp | 46 +++++ .../virtual/VariableColor/modinfo.json | 46 +++++ 6 files changed, 187 insertions(+), 74 deletions(-) create mode 100644 src/modules/virtual/VariableColor/VariableColor.cpp create mode 100644 src/modules/virtual/VariableColor/modinfo.json diff --git a/data_svelte/items.json b/data_svelte/items.json index 40756f1a..7ee634ce 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -162,7 +162,21 @@ }, { "global": 0, - "name": "11. Виртуальная кнопка", + "name": "11. Цветной текст", + "type": "Reading", + "subtype": "VariableColor", + "id": "color", + "needSave": 0, + "widget": "anydataDef", + "page": "Вывод", + "descr": "Цветной текст", + "val": "...", + "round": 0, + "num": 11 + }, + { + "global": 0, + "name": "12. Виртуальная кнопка", "type": "Reading", "subtype": "VButton", "id": "vbtn", @@ -172,13 +186,13 @@ "descr": "Кнопка", "int": "0", "val": "0", - "num": 11 + "num": 12 }, { "header": "Сенсоры" }, { - "name": "12. Acs712 Ток", + "name": "13. Acs712 Ток", "type": "Reading", "subtype": "Acs712", "id": "amp", @@ -188,11 +202,11 @@ "round": 3, "pin": 39, "int": 5, - "num": 12 + "num": 13 }, { "global": 0, - "name": "13. AHTXX Температура", + "name": "14. AHTXX Температура", "type": "Reading", "subtype": "AhtXXt", "id": "Temp20", @@ -203,11 +217,11 @@ "addr": "0x38", "shtType": 1, "round": 1, - "num": 13 + "num": 14 }, { "global": 0, - "name": "14. AHTXX Влажность", + "name": "15. AHTXX Влажность", "type": "Reading", "subtype": "AhtXXh", "id": "Hum20", @@ -218,11 +232,11 @@ "addr": "0x38", "shtType": 1, "round": 1, - "num": 14 + "num": 15 }, { "global": 0, - "name": "15. Аналоговый сенсор", + "name": "16. Аналоговый сенсор", "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -236,11 +250,11 @@ "pin": 0, "int": 15, "avgSteps": 1, - "num": 15 + "num": 16 }, { "global": 0, - "name": "16. BME280 Температура", + "name": "17. BME280 Температура", "type": "Reading", "subtype": "Bme280t", "id": "tmp3", @@ -250,11 +264,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 16 + "num": 17 }, { "global": 0, - "name": "17. BME280 Давление", + "name": "18. BME280 Давление", "type": "Reading", "subtype": "Bme280p", "id": "Press3", @@ -264,11 +278,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 17 + "num": 18 }, { "global": 0, - "name": "18. BME280 Влажность", + "name": "19. BME280 Влажность", "type": "Reading", "subtype": "Bme280h", "id": "Hum3", @@ -278,11 +292,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 18 + "num": 19 }, { "global": 0, - "name": "19. BMP280 Температура", + "name": "20. BMP280 Температура", "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -292,11 +306,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 19 + "num": 20 }, { "global": 0, - "name": "20. BMP280 Давление", + "name": "21. BMP280 Давление", "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -306,11 +320,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 20 + "num": 21 }, { "global": 0, - "name": "21. DHT11 Температура", + "name": "22. DHT11 Температура", "type": "Reading", "subtype": "Dht1122t", "id": "tmp3", @@ -320,11 +334,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 21 + "num": 22 }, { "global": 0, - "name": "22. DHT11 Влажность", + "name": "23. DHT11 Влажность", "type": "Reading", "subtype": "Dht1122h", "id": "Hum3", @@ -334,11 +348,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 22 + "num": 23 }, { "global": 0, - "name": "23. DS18B20 Температура", + "name": "24. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -350,11 +364,11 @@ "index": 0, "addr": "", "round": 1, - "num": 23 + "num": 24 }, { "global": 0, - "name": "24. PZEM 004t Напряжение", + "name": "25. PZEM 004t Напряжение", "type": "Reading", "subtype": "Pzem004v", "id": "v", @@ -364,11 +378,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 24 + "num": 25 }, { "global": 0, - "name": "25. PZEM 004t Сила тока", + "name": "26. PZEM 004t Сила тока", "type": "Reading", "subtype": "Pzem004a", "id": "a", @@ -378,11 +392,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 25 + "num": 26 }, { "global": 0, - "name": "26. PZEM 004t Мощность", + "name": "27. PZEM 004t Мощность", "type": "Reading", "subtype": "Pzem004w", "id": "w", @@ -392,11 +406,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 26 + "num": 27 }, { "global": 0, - "name": "27. PZEM 004t Энергия", + "name": "28. PZEM 004t Энергия", "type": "Reading", "subtype": "Pzem004wh", "id": "wh", @@ -406,11 +420,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 27 + "num": 28 }, { "global": 0, - "name": "28. PZEM 004t Частота", + "name": "29. PZEM 004t Частота", "type": "Reading", "subtype": "Pzem004hz", "id": "hz", @@ -420,11 +434,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 28 + "num": 29 }, { "global": 0, - "name": "29. PZEM 004t Косинус", + "name": "30. PZEM 004t Косинус", "type": "Reading", "subtype": "Pzem004pf", "id": "pf", @@ -434,11 +448,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 29 + "num": 30 }, { "global": 0, - "name": "30. PZEM настройка", + "name": "31. PZEM настройка", "type": "Reading", "subtype": "Pzem004cmd", "id": "set", @@ -450,11 +464,11 @@ "changeaddr": 0, "setaddr": "0x01", "reset": 0, - "num": 30 + "num": 31 }, { "global": 0, - "name": "31. Sht20 Температура", + "name": "32. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -463,11 +477,11 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 31 + "num": 32 }, { "global": 0, - "name": "32. Sht20 Влажность", + "name": "33. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -476,11 +490,11 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 32 + "num": 33 }, { "global": 0, - "name": "33. Sht30 Температура", + "name": "34. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -489,11 +503,11 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 33 + "num": 34 }, { "global": 0, - "name": "34. Sht30 Влажность", + "name": "35. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -502,12 +516,12 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 34 + "num": 35 }, { "global": 0, - "name": "35. HC-SR04 Ультразвуковой дальномер", - "num": 35, + "name": "36. HC-SR04 Ультразвуковой дальномер", + "num": 36, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -519,7 +533,7 @@ "int": 5 }, { - "name": "36. UART", + "name": "37. UART", "type": "Reading", "subtype": "UART", "page": "", @@ -531,14 +545,14 @@ "line": 2, "speed": 9600, "eventFormat": 0, - "num": 36 + "num": 37 }, { "header": "Исполнительные устройства" }, { "global": 0, - "name": "37. Кнопка подключенная к пину", + "name": "38. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -552,11 +566,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "fixState": 0, - "num": 37 + "num": 38 }, { "global": 0, - "name": "38. Управление пином", + "name": "39. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -567,11 +581,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 38 + "num": 39 }, { "global": 0, - "name": "39. Сервопривод", + "name": "40. Сервопривод", "type": "Writing", "subtype": "IoTServo", "id": "servo", @@ -582,11 +596,11 @@ "pin": 12, "apin": -1, "amap": "0, 4096, 0, 180", - "num": 39 + "num": 40 }, { "global": 0, - "name": "40. Расширитель портов Mcp23017", + "name": "41. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -596,11 +610,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 40 + "num": 41 }, { "global": 0, - "name": "41. MP3 плеер", + "name": "42. MP3 плеер", "type": "Reading", "subtype": "Mp3", "id": "mp3", @@ -610,11 +624,11 @@ "int": 1, "pins": "14,12", "volume": 20, - "num": 41 + "num": 42 }, { "global": 0, - "name": "42. Сенсорная кнопка", + "name": "43. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -628,11 +642,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 42 + "num": 43 }, { "global": 0, - "name": "43. Расширитель портов Pcf8574", + "name": "44. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -642,11 +656,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 43 + "num": 44 }, { "global": 0, - "name": "44. PWM ESP8266", + "name": "45. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -658,11 +672,11 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 44 + "num": 45 }, { "global": 0, - "name": "45. Телеграм-Лайт", + "name": "46. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -671,14 +685,14 @@ "descr": "", "token": "", "chatID": "", - "num": 45 + "num": 46 }, { "header": "Экраны" }, { "global": 0, - "name": "46. LCD экран 2004", + "name": "47. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -690,10 +704,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 46 + "num": 47 }, { - "name": "47. LCD экран 1602", + "name": "48. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -705,6 +719,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 47 + "num": 48 } ] \ No newline at end of file diff --git a/myProfile.json b/myProfile.json index 8d86cea2..c2d9cd48 100644 --- a/myProfile.json +++ b/myProfile.json @@ -50,6 +50,10 @@ "path": "src/modules/virtual/Variable", "active": true }, + { + "path": "src/modules/virtual/VariableColor", + "active": true + }, { "path": "src/modules/virtual/VButton", "active": true diff --git a/platformio.ini b/platformio.ini index 117bb9e5..d95e5db4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -264,6 +264,7 @@ build_src_filter = + + + + + + + + diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 12df2c22..02ae7391 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -5,6 +5,7 @@ void* getAPI_Loging(String subtype, String params); void* getAPI_LogingDaily(String subtype, String params); void* getAPI_Timer(String subtype, String params); void* getAPI_Variable(String subtype, String params); +void* getAPI_VariableColor(String subtype, String params); void* getAPI_VButton(String subtype, String params); void* getAPI_Acs712(String subtype, String params); void* getAPI_AhtXX(String subtype, String params); @@ -36,6 +37,7 @@ if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_LogingDaily(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_VariableColor(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Acs712(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_AhtXX(subtype, params)) != nullptr) return tmpAPI; diff --git a/src/modules/virtual/VariableColor/VariableColor.cpp b/src/modules/virtual/VariableColor/VariableColor.cpp new file mode 100644 index 00000000..4bdc4bff --- /dev/null +++ b/src/modules/virtual/VariableColor/VariableColor.cpp @@ -0,0 +1,46 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +// дочь - родитель +class VariableColor : public IoTItem +{ +private: +public: + VariableColor(String parameters) : IoTItem(parameters) + { + } + + void doByInterval() + { + } + + // событие когда пользователь подключается приложением или веб интерфейсом к усройству + void onMqttWsAppConnectEvent() + { + SerialPrint("i", "Connecting", "Dashbord open "); + regEvent(value.valD, "VariableColor", false, true); + } + + IoTValue execute(String command, std::vector ¶m) + { + if (command == "widget" && param.size() == 2) + { + String json = "{}"; + jsonWriteStr(json, param[0].valS, param[1].valS); + sendSubWidgetsValues(_id, json); + } + return {}; + } +}; + +void *getAPI_VariableColor(String subtype, String param) +{ + if (subtype == F("VariableColor")) + { + return new VariableColor(param); + } + else + { + return nullptr; + } +} diff --git a/src/modules/virtual/VariableColor/modinfo.json b/src/modules/virtual/VariableColor/modinfo.json new file mode 100644 index 00000000..7a2a6d72 --- /dev/null +++ b/src/modules/virtual/VariableColor/modinfo.json @@ -0,0 +1,46 @@ +{ + "menuSection": "Виртуальные элементы", + "configItem": [ + { + "global": 0, + "name": "Цветной текст", + "type": "Reading", + "subtype": "VariableColor", + "id": "color", + "needSave": 0, + "widget": "anydataDef", + "page": "Вывод", + "descr": "Цветной текст", + "val": "...", + "round": 0 + } + ], + "about": { + "authorName": "AVAKS", + "authorContact": "https://t.me/@avaks_dev", + "authorGit": "https://github.com/avaksru", + "specialThanks": "", + "moduleName": "VariableColor", + "moduleVersion": "1", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Цветной текст", + "moduleDesc": "Текст с возможностью динамического изменения цвета", + "propInfo": { + "val": "Значение при старте" + } + }, + + "defActive": true, + + "usedLibs": { + "esp32_4mb": [], + "esp8266_4mb": [], + "esp8266_1mb": [], + "esp8266_1mb_ota": [], + "esp8285_1mb": [], + "esp8285_1mb_ota": [] + } +} \ No newline at end of file From 987461ed289f14fd4c61def8e69742521747ec0c Mon Sep 17 00:00:00 2001 From: avaksru Date: Mon, 26 Dec 2022 15:45:12 +0300 Subject: [PATCH 11/13] change to value.valS --- src/modules/virtual/VariableColor/VariableColor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/virtual/VariableColor/VariableColor.cpp b/src/modules/virtual/VariableColor/VariableColor.cpp index 4bdc4bff..12e0ff34 100644 --- a/src/modules/virtual/VariableColor/VariableColor.cpp +++ b/src/modules/virtual/VariableColor/VariableColor.cpp @@ -18,10 +18,10 @@ public: void onMqttWsAppConnectEvent() { SerialPrint("i", "Connecting", "Dashbord open "); - regEvent(value.valD, "VariableColor", false, true); + regEvent(value.valS, "VariableColor", false, true); } - - IoTValue execute(String command, std::vector ¶m) + + IoTValue execute(String command, std::vector ¶m) { if (command == "widget" && param.size() == 2) { From 3e24bf61e0b0a1e4d752deaf9162ee1efa61cae3 Mon Sep 17 00:00:00 2001 From: avaksru Date: Tue, 27 Dec 2022 17:54:56 +0300 Subject: [PATCH 12/13] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20Ex?= =?UTF-8?q?ternalMQTT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MqttClient.cpp | 4 +- .../sensors/ExternalMQTT/ExternalMQTT.cpp | 133 ++++++++++++++++++ src/modules/sensors/ExternalMQTT/modinfo.json | 58 ++++++++ 3 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp create mode 100644 src/modules/sensors/ExternalMQTT/modinfo.json diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index a74c66ca..8ec11fe8 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -110,8 +110,8 @@ void mqttSubscribe() { mqtt.subscribe((mqttRootDevice + "/update").c_str()); if (jsonReadBool(settingsFlashJson, "mqttin")) { - mqtt.subscribe((mqttPrefix + "/+/+/event").c_str()); - mqtt.subscribe((mqttPrefix + "/+/+/order").c_str()); + mqtt.subscribe((mqttPrefix + "/+/+/event/#").c_str()); + mqtt.subscribe((mqttPrefix + "/+/+/order/#").c_str()); mqtt.subscribe((mqttPrefix + "/+/+/info").c_str()); } } diff --git a/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp b/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp new file mode 100644 index 00000000..3ad82a54 --- /dev/null +++ b/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp @@ -0,0 +1,133 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +class ExternalMQTT : public IoTItem +{ +private: + String _MAC; + String _sensor; + IoTItem *tmp; + int _minutesPassed = 0; + String json = "{}"; + int orange = 0; + int red = 0; + int offline = 0; + bool dataFromNode = false; + +public: + ExternalMQTT(String parameters) : IoTItem(parameters) + { + _MAC = jsonReadStr(parameters, "MAC"); + _sensor = jsonReadStr(parameters, "sensor"); + jsonRead(parameters, F("orange"), orange); + jsonRead(parameters, F("red"), red); + jsonRead(parameters, F("offline"), offline); + dataFromNode = false; + } + char *TimeToString(unsigned long t) + { + static char str[12]; + long h = t / 3600; + t = t % 3600; + int m = t / 60; + int s = t % 60; + sprintf(str, "%02ld:%02d:%02d", h, m, s); + return str; + } + void onMqttRecive(String &topic, String &msg) + { + if (msg.indexOf("HELLO") == -1) + { + + // SerialPrint("i", "onMqttRecive", "Прилетело " + topic); + // SerialPrint("i", "onMqttRecive", "Прилетело " + msg); + String dev = selectToMarkerLast(topic, "/"); + dev.toUpperCase(); + dev.replace(":", ""); + if (_MAC == "") + { + SerialPrint("i", "onMqttRecive", dev + " --> " + msg); + } + DynamicJsonDocument doc(JSON_BUFFER_SIZE); + DeserializationError error = deserializeJson(doc, msg); + if (error) + { + SerialPrint("E", F("onMqttRecive"), error.f_str()); + } + JsonObject jsonObject = doc.as(); + + for (JsonPair kv : jsonObject) + { + String key = kv.key().c_str(); + String val = kv.value(); + if (_MAC == dev && _sensor == key) + { + dataFromNode = true; + _minutesPassed = 0; + setValue(val); + // setNewWidgetAttributes(); + } + + // Serial.println("Key: " + key); + // Serial.println("Value: " + val); + } + } + } + + void doByInterval() + { + _minutesPassed++; + setNewWidgetAttributes(); + } + void onMqttWsAppConnectEvent() + { + setNewWidgetAttributes(); + } + + void setNewWidgetAttributes() + { + + jsonWriteStr(json, F("info"), prettyMinutsTimeout(_minutesPassed)); + if (dataFromNode) + { + if (orange != 0 && red != 0 && offline != 0) + { + if (_minutesPassed < orange) + { + jsonWriteStr(json, F("color"), ""); + } + if (_minutesPassed >= orange && _minutesPassed < red) + { + jsonWriteStr(json, F("color"), F("orange")); // сделаем виджет оранжевым + } + if (_minutesPassed >= red && _minutesPassed < offline) + { + jsonWriteStr(json, F("color"), F("red")); // сделаем виджет красным + } + if (_minutesPassed >= offline) + { + jsonWriteStr(json, F("info"), F("offline")); + } + } + } + else + { + jsonWriteStr(json, F("info"), F("awaiting")); + } + sendSubWidgetsValues(_id, json); + } + + ~ExternalMQTT(){}; +}; + +void *getAPI_ExternalMQTT(String subtype, String param) +{ + if (subtype == F("ExternalMQTT")) + { + return new ExternalMQTT(param); + } + else + { + return nullptr; + } +} diff --git a/src/modules/sensors/ExternalMQTT/modinfo.json b/src/modules/sensors/ExternalMQTT/modinfo.json new file mode 100644 index 00000000..090344e1 --- /dev/null +++ b/src/modules/sensors/ExternalMQTT/modinfo.json @@ -0,0 +1,58 @@ +{ + "menuSection": "Сенсоры", + + "configItem": [ + { + "global": 0, + "name": "MQTT парсер", + "type": "Reading", + "subtype": "ExternalMQTT", + "id": "MQTTin", + "widget": "", + "page": "", + "descr": "", + "MAC": "", + "sensor": "", + "round": "", + "orange": 60, + "red": 120, + "offline": 180, + "int": 60 + } + ], + + "about": { + "authorName": "AVAKS", + "authorContact": "https://t.me/@avaks_dev", + "authorGit": "https://github.com/avaksru", + "specialThanks": "", + "moduleName": "ExternalMQTT", + "moduleVersion": "1", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "ExternalMQTT", + "moduleDesc": "Модуль получения данных из OpenMQTTGateway, Zigbee2MQTT, SLS, Tasmota, NodeRead, HA, openHAB, Fhem, domotiz, EEdom", + "propInfo": { + "round": "Округление после запятой.", + "int": "Интервал для изменения цвета", + "orange": "количество минут после которого окрасить виджет в оранжевый цвет", + "red": "количество минут после которого окрасить виджет в красный цвет", + "offline": "количество минут после которого отобразить что устройство offline, если все три orange red и offline поставить в ноль - то функция окраски выключится", + "MAC": "MAC адрес беспроводного датчика", + "sensor": "Тип сенсора: температура / влажность / время / ... " + } + }, + + "defActive": false, + + "usedLibs": { + "esp32_4mb": [], + "esp8266_4mb": [], + "esp8266_1mb": [], + "esp8266_1mb_ota": [], + "esp8285_1mb": [], + "esp8285_1mb_ota": [] + } +} From 5f886baa2c5b5502a75d2ec1ff82aa28c2724e3c Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 4 Jan 2023 11:15:36 +0300 Subject: [PATCH 13/13] =?UTF-8?q?=D0=A3=D1=87=D0=B8=D1=82=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20=D1=81=D0=BE=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=BA=D0=B0=D0=BC=D0=B8=20=D0=B2=20=D1=81=D1=86?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D1=83=20=D1=81=20=D1=87=D0=B8=D1=81=D0=BB=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=B7=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=BD=D0=B5=20=D1=83=D1=87=D0=B8=D1=82=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B8=D1=85=20=D0=BE=D0=BA=D1=80=D1=83=D0=B3?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5.=20=D0=BD=D0=B5=D0=B1=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D1=88=D0=BE=D0=B9=20=D0=BA=D0=BE=D1=81=D1=82=D1=8B?= =?UTF-8?q?=D0=BB=D1=8C=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B0=D0=B5=D0=BC=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=D0=BE=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8,=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20long,=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B5=D0=BC,=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D1=82=D0=B8=20=D0=BE=D0=BA=D1=80?= =?UTF-8?q?=D1=83=D0=B3=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B2=20IoTValue=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D0=BA=D1=80=D1=83=D0=B3=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20IoTItem=20=D0=BF=D1=80=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D1=85=D0=B8=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D1=82=D1=8C=20=D1=81=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B2=D0=BD?= =?UTF-8?q?=D0=B5=D1=88=D0=BD=D0=B5=D0=B3=D0=BE=20=D0=B2=D0=B8=D0=B4=D0=B0?= =?UTF-8?q?=20=D1=87=D0=B8=D1=81=D0=BB=D0=B0=20=D0=B2=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D1=83=20valS,=20=D0=BD=D0=BE=20=D0=BD=D0=B5=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=B8=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=BD=D0=B5=20=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D1=8E=D1=82=20=D1=8D=D1=82=D0=BE=D0=B3=D0=BE,=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC=20=D1=8D=D1=82=D1=83=20?= =?UTF-8?q?=D1=81=D0=B8=D1=82=D1=83=D0=B0=D1=86=D0=B8=D1=8E=20=D1=82=D1=83?= =?UTF-8?q?=D1=82=20=D0=B8=20=D1=83=D1=87=D0=B8=D1=82=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTScenario.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index bd6eaf26..9980fce0 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -200,6 +200,9 @@ class BinaryExprAST : public ExprAST { break; } } else { // иначе имеем дело с операциями + или - или ==, которые могут работать с разными типами данных + if (lhs->isDecimal && lhs->valS == "") lhs->valS = (String)lhs->valD; // небольшой костыль пока не переделаем работу со значениями, планируется добавить long, работу со временем, перенести округление и модификаторы в IoTValue + if (rhs->isDecimal && rhs->valS == "") rhs->valS = (String)rhs->valD; // пока для сохранения округления в IoTItem применяется хитрость с сохранением внешнего вида числа в строку valS, + // но некоторые модули и системные не делают этого, поэтому отлавливаем эту ситуацию тут и учитываем. switch (Op) { case tok_equal: if (lhs->isDecimal && rhs->isDecimal)