From 1189b7c289ced586774612cc6bee0bea99247fc4 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 17 Feb 2023 20:26:29 +0300 Subject: [PATCH 01/10] =?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=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20RTC?= =?UTF-8?q?=20=D0=B8=20=D0=B5=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D1=83=20=D0=B2=20=D1=81=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Global.h | 1 + include/classes/IoTItem.h | 3 + src/ESPConfiguration.cpp | 5 ++ src/Global.cpp | 1 + src/NTP.cpp | 9 ++- src/classes/IoTItem.cpp | 8 +++ src/modules/sensors/RTC/RTC.cpp | 82 ++++++++++++++++++++++++++++ src/modules/sensors/RTC/modinfo.json | 67 +++++++++++++++++++++++ 8 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 src/modules/sensors/RTC/RTC.cpp create mode 100644 src/modules/sensors/RTC/modinfo.json diff --git a/include/Global.h b/include/Global.h index 38bc36c4..91cd2047 100644 --- a/include/Global.h +++ b/include/Global.h @@ -55,6 +55,7 @@ *****************************************глобальные объекты классов*************************************************** **********************************************************************************************************************/ extern IoTGpio IoTgpio; +extern IoTItem* rtcItem; extern TickerScheduler ts; extern WiFiClient espClient; diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index c0cce8ed..342bc02f 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -46,6 +46,9 @@ class IoTItem { bool enableDoByInt = true; virtual IoTGpio* getGpioDriver(); + virtual IoTItem* getRtcDriver(); + virtual ulong getRtcUnixTime(); + virtual void setValue(const IoTValue& Value, bool genEvent = true); virtual void setValue(const String& valStr, bool genEvent = true); String getRoundValue(); diff --git a/src/ESPConfiguration.cpp b/src/ESPConfiguration.cpp index 1ab3a874..796e7bb5 100644 --- a/src/ESPConfiguration.cpp +++ b/src/ESPConfiguration.cpp @@ -29,6 +29,8 @@ void configure(String path) { void* driver; // пробуем спросить драйвер GPIO if (driver = myIoTItem->getGpioDriver()) IoTgpio.regDriver((IoTGpio*)driver); + // пробуем спросить драйвер RTC + if (driver = myIoTItem->getRtcDriver()) rtcItem = (IoTItem*)driver; IoTItems.push_back(myIoTItem); } @@ -41,6 +43,9 @@ void configure(String path) { void clearConfigure() { Serial.printf("Start clearing config\n"); + rtcItem = nullptr; + IoTgpio.clearDrivers(); + for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { Serial.printf("Start delete iotitem %s \n", (*it)->getID().c_str()); if (*it) delete *it; diff --git a/src/Global.cpp b/src/Global.cpp index cbe0310f..efab097a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -30,6 +30,7 @@ WebSocketsServer standWebSocket = WebSocketsServer(81); ***********************************************глобальные переменные************************************************** **********************************************************************************************************************/ IoTGpio IoTgpio(0); +IoTItem* rtcItem = nullptr; String settingsFlashJson = "{}"; // переменная в которой хранятся все настройки, находится в оперативной памяти и синхронизированна с flash памятью String valuesFlashJson = "{}"; // переменная в которой хранятся все значения элементов, которые необходимо сохранить на flash. Находится в оперативной памяти и синхронизированна с flash памятью diff --git a/src/NTP.cpp b/src/NTP.cpp index 112050fa..f9f8a4a1 100644 --- a/src/NTP.cpp +++ b/src/NTP.cpp @@ -9,14 +9,19 @@ void ntpInit() { ts.add( TIME, 1000, [&](void*) { unixTime = getSystemTime(); - unixTimeShort = unixTime - START_DATETIME; if (unixTime < MIN_DATETIME) { isTimeSynch = false; // SerialPrint("E", "NTP", "Time not synched"); jsonWriteInt(errorsHeapJson, F("tme1"), 1); synchTime(); - return; + + // проверяем присутствие RTC с батарейкой и получаем время при наличии + if (rtcItem) { + unixTime = rtcItem->getRtcUnixTime(); + } else return; } + + unixTimeShort = unixTime - START_DATETIME; jsonWriteInt(errorsHeapJson, F("tme1"), 0); breakEpochToTime(unixTime + jsonReadInt(settingsFlashJson, F("timezone")) * 60 * 60, _time_local); breakEpochToTime(unixTime, _time_utc); diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 5b8c5476..c3606775 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -208,6 +208,14 @@ IoTGpio* IoTItem::getGpioDriver() { return nullptr; } +IoTItem* IoTItem::getRtcDriver() { + return nullptr; +} + +ulong IoTItem::getRtcUnixTime() { + return 0; +} + // сетевое общение==================================================================================================================================== // externalVariable::externalVariable(const String& parameters) : IoTItem(parameters) { diff --git a/src/modules/sensors/RTC/RTC.cpp b/src/modules/sensors/RTC/RTC.cpp new file mode 100644 index 00000000..727303f0 --- /dev/null +++ b/src/modules/sensors/RTC/RTC.cpp @@ -0,0 +1,82 @@ +#include "Global.h" +#include "classes/IoTItem.h" +#include + +class RTC : public IoTItem { + private: + bool _ticker = false; + iarduino_RTC* _watch; + String _timeFormat = ""; + + public: + RTC(String parameters) : IoTItem(parameters) { + jsonRead(parameters, F("ticker"), _ticker); + jsonRead(parameters, F("timeFormat"), _timeFormat); + _timeFormat = _timeFormat + " "; // костыль для коррекции ошибки в библиотеке + + int chipCode = 3; + jsonRead(parameters, F("chipCode"), chipCode); + if (chipCode == 1) { + int RST, CLK, DAT; + jsonRead(parameters, "RST", RST); + jsonRead(parameters, "CLK", CLK); + jsonRead(parameters, "DAT", DAT); + _watch = new iarduino_RTC(RTC_DS1302, RST, CLK, DAT); + } else { + _watch = new iarduino_RTC(chipCode); + } + _watch->begin(); + } + + void doByInterval() { + value.isDecimal = false; + value.valS = _watch->gettime(_timeFormat); + + if (_ticker) regEvent(value.valS, F("RTC tick")); + } + + IoTItem* getRtcDriver() { + return this; + } + + ulong getRtcUnixTime() { + return _watch->gettimeUnix(); + } + + void onModuleOrder(String &key, String &value) { + if (key == "setUTime") { + char *stopstring; + ulong ut = strtoul(value.c_str(), &stopstring, 10); + _watch->settimeUnix(ut); + SerialPrint("i", F("RTC"), "Устанавливаем время: " + value); + } else if (key == "setSysTime") { + _watch->settimeUnix(unixTime); + SerialPrint("i", F("RTC"), F("Запоминаем системное время")); + } + } + + IoTValue execute(String command, std::vector ¶m) { + if (command == "getTime") { + if (param.size() == 1) { + IoTValue valTmp; + valTmp.isDecimal = false; + valTmp.valS = _watch->gettime(param[0].valS + " "); + return valTmp; + } + } + + return {}; + } + + ~RTC(){ + if (_watch) delete _watch; + }; +}; + +void* getAPI_RTC(String subtype, String param) { + if (subtype == F("RTC")) { + return new RTC(param); + } else { + return nullptr; + } +} diff --git a/src/modules/sensors/RTC/modinfo.json b/src/modules/sensors/RTC/modinfo.json new file mode 100644 index 00000000..464dcb9c --- /dev/null +++ b/src/modules/sensors/RTC/modinfo.json @@ -0,0 +1,67 @@ +{ + "menuSection": "Сенсоры", + "configItem": [ + { + "global": 0, + "name": "Часы реального времени", + "type": "Reading", + "subtype": "RTC", + "id": "rtc", + "widget": "anydataDef", + "page": "Таймеры", + "descr": "Время RTC", + "chipCode": 1, + "timeFormat": "d-m-Y H:i:s", + "RST": -1, + "CLK": -1, + "DAT": -1, + "ticker": 0, + "int": 5, + "btn-setUTime": "0", + "btn-setSysTime": "nil" + } + ], + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "exampleURL": "https://iotmanager.org/wiki", + "specialThanks": "", + "moduleName": "RTC", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Часы реального времени", + "moduleDesc": "Позволяет хранить и получать время из модуля с батарейкой.", + "propInfo": { + "chipCode": "RX8025 - 4, DS3231 - 3, DS1307 - 2, DS1302 - 1 (необходимо установить пины RST, CLK и DAT)", + "timeFormat": "Формат времени для вывода. Как у функции date() в PHP", + "RST": "Пин RST", + "CLK": "Пин CLK", + "DAT": "Пин DAT", + "ticker": "Генерировать(1) или нет(0) события при каждом тике часов (каждые int секунд).", + "int": "Количество секунд между получениями данных из модуля", + "btn-setUTime": "Кнопка установки времени модуля на основе указанного unixtime", + "btn-setSysTime": "Кнопка установки времени модуля на основе системного с платы ESP" + }, + "retInfo": "Содержит текущее время из модуля RTC", + "funcInfo": [ + { + "name": "getTime", + "descr": "Получить строковое значение времени по указанному формату.", + "params": ["Формат как у функции date() в PHP"] + } + ] + }, + "defActive": true, + "usedLibs": { + "esp32_4mb": ["https://github.com/tremaru/iarduino_RTC"], + "esp8266_4mb": ["https://github.com/tremaru/iarduino_RTC"], + "esp8266_1mb": ["https://github.com/tremaru/iarduino_RTC"], + "esp8266_1mb_ota": ["https://github.com/tremaru/iarduino_RTC"], + "esp8285_1mb": ["https://github.com/tremaru/iarduino_RTC"], + "esp8285_1mb_ota": ["https://github.com/tremaru/iarduino_RTC"] + } +} \ No newline at end of file From a3b99a9e8d76ec353372dd3650c18d618ba9d3f6 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 17 Feb 2023 20:28:02 +0300 Subject: [PATCH 02/10] =?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=BE=D1=87=D0=B8=D1=81=D1=82=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B4=D1=80=D0=B0=D0=B9=D0=B2=D0=B5=D1=80=D0=BE=D0=B2=20GPI?= =?UTF-8?q?O=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D1=81=D0=B1=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=BE=D0=BC=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=94=D0=BB=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=BE=D1=82=D0=B2=D1=80=D0=B0=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D1=89=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BF=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E?= =?UTF-8?q?=D1=89=D0=B8=D0=BC=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/classes/IoTGpio.h | 1 + src/classes/IoTGpio.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/classes/IoTGpio.h b/include/classes/IoTGpio.h index a83a63c5..8f3175ab 100644 --- a/include/classes/IoTGpio.h +++ b/include/classes/IoTGpio.h @@ -15,6 +15,7 @@ class IoTGpio { int index; void regDriver(IoTGpio* newDriver); + void clearDrivers(); private: IoTGpio* _drivers[5] = {nullptr}; //ссылки на объекты доступа к портам более 100, 200, 300, 400. Нулевой элемент используется как маркер - и возвращается nullptr при обращении diff --git a/src/classes/IoTGpio.cpp b/src/classes/IoTGpio.cpp index 29e164e8..71e01b49 100644 --- a/src/classes/IoTGpio.cpp +++ b/src/classes/IoTGpio.cpp @@ -57,4 +57,10 @@ void IoTGpio::digitalInvert(uint8_t pin) { void IoTGpio::regDriver(IoTGpio* newDriver) { _drivers[newDriver->index] = newDriver; +} + +void IoTGpio::clearDrivers() { + for (int i=0; i<5; i++) { + _drivers[i] = nullptr; + } } \ No newline at end of file From 0f9a185163e60b9ca10d800836b2ccd9e15277fd Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 17 Feb 2023 22:21:10 +0300 Subject: [PATCH 03/10] =?UTF-8?q?=D0=A3=D1=81=D0=BA=D0=BE=D1=80=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B5=D0=B2=20=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B5=20onInit=20=D0=9A=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B5=20=D0=BF=D0=BE=D1=8F=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=B8=20=D0=B2=D1=8B=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=BD=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=B4=D0=BE?= =?UTF-8?q?=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=81=D0=B5=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.cpp | 61 +++++++++++++++++++++++++++++------------ src/classes/IoTItem.cpp | 2 +- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 815c56dd..95cf99ab 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -10,6 +10,26 @@ String volStrForSave = ""; unsigned long currentMillis; unsigned long prevMillis; + + +void elementsLoop() { + // передаем управление каждому элементу конфигурации для выполнения своих функций + for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { + (*it)->loop(); + + // if ((*it)->iAmDead) { + if (!((*it)->iAmLocal) && (*it)->getIntFromNet() == -1) { + delete *it; + IoTItems.erase(it); + break; + } + } + + handleOrder(); + handleEvent(); +} + + void setup() { Serial.begin(115200); Serial.flush(); @@ -33,6 +53,24 @@ void setup() { // синхронизация глобальных переменных с flash globalVarsSync(); + + + + + // настраиваем микроконтроллер + configure("/config.json"); + + // подготавливаем сценарии + iotScen.loadScenario("/scenario.txt"); + + // создаем событие завершения инициализации основных моментов для возможности выполнения блока кода при загрузке + createItemFromNet("onInit", "1", 1); + + elementsLoop(); + + + + // подключаемся к роутеру routerConnect(); @@ -75,8 +113,7 @@ void setup() { SerialPrint("i", "i2c", F("i2c pins overriding done")); } - // настраиваем микроконтроллер - configure("/config.json"); + // инициализация задач переодического выполнения periodicTasksInit(); @@ -87,9 +124,6 @@ void setup() { // запуск работы udp asyncUdpInit(); - // подготавливаем сценарии - iotScen.loadScenario("/scenario.txt"); - // создаем событие завершения конфигурирования для возможности выполнения блока кода при загрузке createItemFromNet("onStart", "1", 1); @@ -134,6 +168,8 @@ void setup() { // } } + + void loop() { #ifdef LOOP_DEBUG unsigned long st = millis(); @@ -151,20 +187,9 @@ void loop() { mqttLoop(); - // передаем управление каждому элементу конфигурации для выполнения своих функций - for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { - (*it)->loop(); + + elementsLoop(); - // if ((*it)->iAmDead) { - if (!((*it)->iAmLocal) && (*it)->getIntFromNet() == -1) { - delete *it; - IoTItems.erase(it); - break; - } - } - - handleOrder(); - handleEvent(); // #ifdef LOOP_DEBUG // loopPeriod = millis() - st; diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index c3606775..26fb41d1 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -173,7 +173,7 @@ void IoTItem::checkIntFromNet() { if (_intFromNet >= 0) { // если время жизни истекло, то удаляем элемент чуть позже на следующем такте loop // если это было уведомление не об ошибке или начале работы, то сообщаем, что сетевое событие давно не приходило - if (_intFromNet == 0 && _id.indexOf("onError") == -1 && _id.indexOf("onStart") == -1) { + if (_intFromNet == 0 && _id.indexOf("onError") == -1 && _id.indexOf("onStart") == -1 && _id.indexOf("onInit") == -1) { SerialPrint("E", _id, "The new data did not come from the network. The level of trust is low.", _id); } _intFromNet--; From aae0331415931d0948cac6833d9f93d9bdbd07f4 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 17 Feb 2023 22:27:37 +0300 Subject: [PATCH 04/10] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20i2c=20=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D1=8C=D1=88=D0=B5=20=D0=B4=D0=BE=20=D1=81=D1=86?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.cpp | 51 +++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 95cf99ab..192ca776 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -54,11 +54,27 @@ void setup() { globalVarsSync(); - // настраиваем микроконтроллер configure("/config.json"); + + // настраиваем i2c шину + int i2c, pinSCL, pinSDA, i2cFreq; + jsonRead(settingsFlashJson, "pinSCL", pinSCL, false); + jsonRead(settingsFlashJson, "pinSDA", pinSDA, false); + jsonRead(settingsFlashJson, "i2cFreq", i2cFreq, false); + jsonRead(settingsFlashJson, "i2c", i2c, false); + if (i2c != 0) { +#ifdef esp32_4mb + Wire.end(); + Wire.begin(pinSDA, pinSCL, (uint32_t)i2cFreq); +#else + Wire.begin(pinSDA, pinSCL); + Wire.setClock(i2cFreq); +#endif + SerialPrint("i", "i2c", F("i2c pins overriding done")); + } // подготавливаем сценарии iotScen.loadScenario("/scenario.txt"); @@ -96,23 +112,6 @@ void setup() { // инициализация mqtt mqttInit(); - // настраиваем i2c шину - int i2c, pinSCL, pinSDA, i2cFreq; - jsonRead(settingsFlashJson, "pinSCL", pinSCL, false); - jsonRead(settingsFlashJson, "pinSDA", pinSDA, false); - jsonRead(settingsFlashJson, "i2cFreq", i2cFreq, false); - jsonRead(settingsFlashJson, "i2c", i2c, false); - if (i2c != 0) { -#ifdef esp32_4mb - Wire.end(); - Wire.begin(pinSDA, pinSCL, (uint32_t)i2cFreq); -#else - Wire.begin(pinSDA, pinSCL); - Wire.setClock(i2cFreq); -#endif - SerialPrint("i", "i2c", F("i2c pins overriding done")); - } - // инициализация задач переодического выполнения @@ -150,22 +149,6 @@ void setup() { // test Serial.println("-------test start--------"); Serial.println("--------test end---------"); - - // симуляция добавления внешних событий - // IoTItems.push_back((IoTItem*)new externalVariable("{\"id\":\"rel1\",\"val\":10,\"int\":20}")); - // IoTItems.push_back((IoTItem*)new externalVariable("{\"id\":\"rel4\",\"val\":34,\"int\":30}")); - // пример получения JSON всех Items - // Serial.println(getParamsJson()); - // чтение одного параметра - // Serial.println(findIoTItem("t1")->getValue()); - // тест перебора пинов из расширения - // for (int i = 109; i < 112; i++) { - // IoTgpio.pinMode(i, OUTPUT); - // IoTgpio.digitalWrite(i, !IoTgpio.digitalRead(i)); - // delay(1000); - // IoTgpio.digitalWrite(i, !IoTgpio.digitalRead(i)); - // delay(1000); - // } } From a27b937c9c2136504df062bd71b4b3d2cb6adbcb Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 17 Feb 2023 22:47:16 +0300 Subject: [PATCH 05/10] =?UTF-8?q?=D0=A3=D0=B1=D0=B8=D1=80=D0=B0=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BB=D0=B8=D1=88=D0=BD=D1=8E=D1=8E=20=D0=B8=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20MQTT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.cpp b/src/Main.cpp index 192ca776..ae2e11c0 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -110,7 +110,7 @@ void setup() { ntpInit(); // инициализация mqtt - mqttInit(); + //mqttInit(); From e10bfaa4b5fba5de25c4057f2a4404cecfe4f856 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 17 Feb 2023 22:48:41 +0300 Subject: [PATCH 06/10] =?UTF-8?q?=D0=A3=D1=81=D0=BA=D0=BE=D1=80=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=80=D0=B5=D0=B0=D0=BA=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=20=D0=B8=D0=BB=D0=B8=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/WiFiUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/WiFiUtils.cpp b/src/utils/WiFiUtils.cpp index 99daaacd..af23f900 100644 --- a/src/utils/WiFiUtils.cpp +++ b/src/utils/WiFiUtils.cpp @@ -28,6 +28,7 @@ void routerConnect() { SerialPrint("E", "WIFI", "password is not correct"); tries = 1; jsonWriteInt(errorsHeapJson, "passer", 1); + break; } Serial.print("."); delay(1000); From 7709116734067e1e9925b494144a614340688e61 Mon Sep 17 00:00:00 2001 From: biver Date: Sat, 18 Feb 2023 13:42:30 +0300 Subject: [PATCH 07/10] =?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=20BME=20=D1=80=D0=B0=D1=81=D1=87?= =?UTF-8?q?=D0=B5=D1=82=20=D1=82=D0=BE=D1=87=D0=BA=D0=B8=20=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Bme280/Bme280.cpp | 115 +++++++++++++++++------- src/modules/sensors/Bme280/modinfo.json | 36 ++++---- 2 files changed, 103 insertions(+), 48 deletions(-) diff --git a/src/modules/sensors/Bme280/Bme280.cpp b/src/modules/sensors/Bme280/Bme280.cpp index 071525c4..73c0d8b7 100644 --- a/src/modules/sensors/Bme280/Bme280.cpp +++ b/src/modules/sensors/Bme280/Bme280.cpp @@ -10,18 +10,21 @@ #include #include -std::map bmes; +std::map bmes; -class Bme280t : public IoTItem { - private: - Adafruit_BME280* _bme; +class Bme280t : public IoTItem +{ +private: + Adafruit_BME280 *_bme; - public: - Bme280t(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) { +public: + Bme280t(Adafruit_BME280 *bme, String parameters) : IoTItem(parameters) + { _bme = bme; } - void doByInterval() { + void doByInterval() + { value.valD = _bme->readTemperature(); if (value.valD != NAN && value.valD < 145) regEvent(value.valD, "Bme280t"); @@ -32,16 +35,19 @@ class Bme280t : public IoTItem { ~Bme280t(){}; }; -class Bme280h : public IoTItem { - private: - Adafruit_BME280* _bme; +class Bme280h : public IoTItem +{ +private: + Adafruit_BME280 *_bme; - public: - Bme280h(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) { +public: + Bme280h(Adafruit_BME280 *bme, String parameters) : IoTItem(parameters) + { _bme = bme; } - void doByInterval() { + void doByInterval() + { value.valD = _bme->readHumidity(); if (value.valD != NAN && value.valD < 100) regEvent(value.valD, "Bme280h"); @@ -52,49 +58,96 @@ class Bme280h : public IoTItem { ~Bme280h(){}; }; -class Bme280p : public IoTItem { - private: - Adafruit_BME280* _bme; +class Bme280p : public IoTItem +{ +private: + Adafruit_BME280 *_bme; - public: - Bme280p(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) { +public: + Bme280p(Adafruit_BME280 *bme, String parameters) : IoTItem(parameters) + { _bme = bme; } - void doByInterval() { + void doByInterval() + { value.valD = _bme->readPressure(); - if (value.valD != NAN && value.valD > 0) { + if (value.valD != NAN && value.valD > 0) + { value.valD = value.valD / 1.333224 / 100; regEvent(value.valD, "Bme280p"); - } else + } + else SerialPrint("E", "Sensor Bme280p", "Error", _id); } ~Bme280p(){}; }; -void* getAPI_Bme280(String subtype, String param) { - if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) { +class Bme280dp : public IoTItem +{ +private: + Adafruit_BME280 *_bme; + +public: + Bme280dp(Adafruit_BME280 *bme, String parameters) : IoTItem(parameters) + { + _bme = bme; + } + + void doByInterval() + { + + float humi = _bme->readHumidity(); + float temp = _bme->readTemperature(); + + if (temp != NAN && temp < 145 && humi != NAN && humi > 0 && humi < 100) + { + value.valD = (temp - (14.55 + 0.114 * temp) * (1 - (0.01 * humi)) - pow(((2.5 + 0.007 * temp) * (1 - (0.01 * humi))), 3) - (15.9 + 0.117 * temp) * pow((1 - (0.01 * humi)), 14)); + regEvent(value.valD, "Bme280dp"); + } + else + SerialPrint("E", "Sensor Bme280dp", "Error", _id); + } + + ~Bme280dp(){}; +}; + +void *getAPI_Bme280(String subtype, String param) +{ + if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p") || subtype == F("Bme280dp")) + { String addr; jsonRead(param, "addr", addr); - if (addr == "") { + if (addr == "") + { scanI2C(); return nullptr; } - - if (bmes.find(addr) == bmes.end()) { + + if (bmes.find(addr) == bmes.end()) + { bmes[addr] = new Adafruit_BME280(); bmes[addr]->begin(hexStringToUint8(addr)); } - - if (subtype == F("Bme280t")) { + + if (subtype == F("Bme280t")) + { return new Bme280t(bmes[addr], param); - } else if (subtype == F("Bme280h")) { + } + else if (subtype == F("Bme280h")) + { return new Bme280h(bmes[addr], param); - } else if (subtype == F("Bme280p")) { + } + else if (subtype == F("Bme280p")) + { return new Bme280p(bmes[addr], param); } + else if (subtype == F("Bme280dp")) + { + return new Bme280dp(bmes[addr], param); + } } - + return nullptr; } diff --git a/src/modules/sensors/Bme280/modinfo.json b/src/modules/sensors/Bme280/modinfo.json index ca6dd652..965551f7 100644 --- a/src/modules/sensors/Bme280/modinfo.json +++ b/src/modules/sensors/Bme280/modinfo.json @@ -6,7 +6,7 @@ "name": "BME280 Температура", "type": "Reading", "subtype": "Bme280t", - "id": "tmp3", + "id": "Tmp3", "widget": "anydataTmp", "page": "Сенсоры", "descr": "Температура", @@ -39,6 +39,19 @@ "int": 15, "addr": "0x77", "round": 1 + }, + { + "global": 0, + "name": "BME280 Tочка росы", + "type": "Reading", + "subtype": "Bme280dp", + "id": "Dew3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Точка росы", + "int": 15, + "addr": "0x77", + "round": 1 } ], "about": { @@ -55,12 +68,13 @@ "subTypes": [ "Bme280t", "Bme280p", - "Bme280h" + "Bme280h", + "Bme280dp" ], - "title": "Сенсор температуры, давления и влажности с Bme280", - "moduleDesc": "Позволяет получить значения температуры, давления и влажности с Bme280.", + "title": "Сенсор температуры, давления, влажности и точки росы с Bme280", + "moduleDesc": "Позволяет получить значения температуры, давления, влажности и точки росы с Bme280.", "propInfo": { - "addr": "Адрес датчика на шине, обычно 0x77.", + "addr": "Адрес датчика на шине, обычно 0x77. Для стабильности надо пин SDO притянуть к 3.3В. Если пин SDO притянуть к GND то адрес будет 0х76", "int": "Количество секунд между опросами датчика." } }, @@ -71,18 +85,6 @@ ], "esp8266_4mb": [ "adafruit/Adafruit BME280 Library" - ], - "esp8266_1mb": [ - "adafruit/Adafruit BME280 Library" - ], - "esp8266_1mb_ota": [ - "adafruit/Adafruit BME280 Library" - ], - "esp8285_1mb": [ - "adafruit/Adafruit BME280 Library" - ], - "esp8285_1mb_ota": [ - "adafruit/Adafruit BME280 Library" ] } } \ No newline at end of file From bd4244bef37d025be69cded570c974f5137ce7ba Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 19 Feb 2023 11:35:41 +0300 Subject: [PATCH 08/10] =?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=D1=81=20=D0=BF=D0=BE=D0=B4=D1=82=D1=8F=D0=B6=D0=BA=D0=BE?= =?UTF-8?q?=D0=B9,=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/ButtonIn/ButtonIn.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/exec/ButtonIn/ButtonIn.cpp b/src/modules/exec/ButtonIn/ButtonIn.cpp index aecaf87e..7ae01693 100644 --- a/src/modules/exec/ButtonIn/ButtonIn.cpp +++ b/src/modules/exec/ButtonIn/ButtonIn.cpp @@ -26,9 +26,9 @@ class ButtonIn : public IoTItem { _round = 0; //Serial.printf("vvvvvvvvvvvvvvvv =%d \n", _fixState); - IoTgpio.pinMode(_pin, INPUT); - if (_pinMode == "INPUT_PULLUP") IoTgpio.digitalWrite(_pin, HIGH); - else if (_pinMode == "INPUT_PULLDOWN") IoTgpio.digitalWrite(_pin, LOW); + if (_pinMode == "INPUT") IoTgpio.pinMode(_pin, INPUT); + else if (_pinMode == "INPUT_PULLDOWN") {IoTgpio.pinMode(_pin, INPUT); IoTgpio.digitalWrite(_pin, LOW);} + else if (_pinMode == "INPUT_PULLUP") IoTgpio.pinMode(_pin, INPUT_PULLUP); value.valD = _buttonState = IoTgpio.digitalRead(_pin); // сообщаем всем о стартовом статусе без генерации события From f53a7341d8b0074108fd4e6b7fa68ada48842b05 Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 19 Feb 2023 19:11:15 +0300 Subject: [PATCH 09/10] =?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=B8=D0=BD=D0=B2=D0=B5=D1=80=D1=81=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B2=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=BD=D1=83?= =?UTF-8?q?=D1=8E=20=D0=BA=20=D0=BF=D0=B8=D0=BD=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 169 ++++++++++++++++--------- platformio.ini | 12 +- src/modules/API.cpp | 4 + src/modules/exec/ButtonIn/ButtonIn.cpp | 47 +++---- src/modules/exec/ButtonIn/modinfo.json | 6 +- 5 files changed, 148 insertions(+), 90 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 7ee634ce..1194fb68 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -257,7 +257,7 @@ "name": "17. BME280 Температура", "type": "Reading", "subtype": "Bme280t", - "id": "tmp3", + "id": "Tmp3", "widget": "anydataTmp", "page": "Сенсоры", "descr": "Температура", @@ -296,7 +296,21 @@ }, { "global": 0, - "name": "20. BMP280 Температура", + "name": "20. BME280 Tочка росы", + "type": "Reading", + "subtype": "Bme280dp", + "id": "Dew3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Точка росы", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 20 + }, + { + "global": 0, + "name": "21. BMP280 Температура", "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -306,11 +320,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 20 + "num": 21 }, { "global": 0, - "name": "21. BMP280 Давление", + "name": "22. BMP280 Давление", "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -320,11 +334,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 21 + "num": 22 }, { "global": 0, - "name": "22. DHT11 Температура", + "name": "23. DHT11 Температура", "type": "Reading", "subtype": "Dht1122t", "id": "tmp3", @@ -334,11 +348,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 22 + "num": 23 }, { "global": 0, - "name": "23. DHT11 Влажность", + "name": "24. DHT11 Влажность", "type": "Reading", "subtype": "Dht1122h", "id": "Hum3", @@ -348,11 +362,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 23 + "num": 24 }, { "global": 0, - "name": "24. DS18B20 Температура", + "name": "25. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -364,11 +378,11 @@ "index": 0, "addr": "", "round": 1, - "num": 24 + "num": 25 }, { "global": 0, - "name": "25. PZEM 004t Напряжение", + "name": "26. PZEM 004t Напряжение", "type": "Reading", "subtype": "Pzem004v", "id": "v", @@ -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": "Pzem004a", "id": "a", @@ -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": "Pzem004w", "id": "w", @@ -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": "Pzem004wh", "id": "wh", @@ -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": "Pzem004hz", "id": "hz", @@ -434,11 +448,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 29 + "num": 30 }, { "global": 0, - "name": "30. PZEM 004t Косинус", + "name": "31. PZEM 004t Косинус", "type": "Reading", "subtype": "Pzem004pf", "id": "pf", @@ -448,11 +462,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 30 + "num": 31 }, { "global": 0, - "name": "31. PZEM настройка", + "name": "32. PZEM настройка", "type": "Reading", "subtype": "Pzem004cmd", "id": "set", @@ -464,11 +478,31 @@ "changeaddr": 0, "setaddr": "0x01", "reset": 0, - "num": 31 + "num": 32 }, { "global": 0, - "name": "32. Sht20 Температура", + "name": "33. Часы реального времени", + "type": "Reading", + "subtype": "RTC", + "id": "rtc", + "widget": "anydataDef", + "page": "Таймеры", + "descr": "Время RTC", + "chipCode": 1, + "timeFormat": "d-m-Y H:i:s", + "RST": -1, + "CLK": -1, + "DAT": -1, + "ticker": 0, + "int": 5, + "btn-setUTime": "0", + "btn-setSysTime": "nil", + "num": 33 + }, + { + "global": 0, + "name": "34. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -477,11 +511,11 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 32 + "num": 34 }, { "global": 0, - "name": "33. Sht20 Влажность", + "name": "35. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -490,11 +524,11 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 33 + "num": 35 }, { "global": 0, - "name": "34. Sht30 Температура", + "name": "36. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -503,11 +537,11 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 34 + "num": 36 }, { "global": 0, - "name": "35. Sht30 Влажность", + "name": "37. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -516,12 +550,12 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 35 + "num": 37 }, { "global": 0, - "name": "36. HC-SR04 Ультразвуковой дальномер", - "num": 36, + "name": "38. HC-SR04 Ультразвуковой дальномер", + "num": 38, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -533,7 +567,7 @@ "int": 5 }, { - "name": "37. UART", + "name": "39. UART", "type": "Reading", "subtype": "UART", "page": "", @@ -545,14 +579,14 @@ "line": 2, "speed": 9600, "eventFormat": 0, - "num": 37 + "num": 39 }, { "header": "Исполнительные устройства" }, { "global": 0, - "name": "38. Кнопка подключенная к пину", + "name": "40. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -566,11 +600,12 @@ "pinMode": "INPUT", "debounceDelay": 50, "fixState": 0, - "num": 38 + "inv": 0, + "num": 40 }, { "global": 0, - "name": "39. Управление пином", + "name": "41. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -581,11 +616,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 39 + "num": 41 }, { "global": 0, - "name": "40. Сервопривод", + "name": "42. Сервопривод", "type": "Writing", "subtype": "IoTServo", "id": "servo", @@ -596,11 +631,11 @@ "pin": 12, "apin": -1, "amap": "0, 4096, 0, 180", - "num": 40 + "num": 42 }, { "global": 0, - "name": "41. Расширитель портов Mcp23017", + "name": "43. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -610,11 +645,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 41 + "num": 43 }, { "global": 0, - "name": "42. MP3 плеер", + "name": "44. MP3 плеер", "type": "Reading", "subtype": "Mp3", "id": "mp3", @@ -624,11 +659,11 @@ "int": 1, "pins": "14,12", "volume": 20, - "num": 42 + "num": 44 }, { "global": 0, - "name": "43. Сенсорная кнопка", + "name": "45. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -642,11 +677,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 43 + "num": 45 }, { "global": 0, - "name": "44. Расширитель портов Pcf8574", + "name": "46. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -656,11 +691,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 44 + "num": 46 }, { "global": 0, - "name": "45. PWM ESP8266", + "name": "47. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -672,11 +707,11 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 45 + "num": 47 }, { "global": 0, - "name": "46. Телеграм-Лайт", + "name": "48. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -685,14 +720,30 @@ "descr": "", "token": "", "chatID": "", - "num": 46 + "num": 48 }, { "header": "Экраны" }, { "global": 0, - "name": "47. LCD экран 2004", + "name": "49. LCD Dwin экран", + "type": "Reading", + "subtype": "DwinI", + "id": "dwin", + "widget": "", + "page": "", + "descr": "", + "int": 15, + "TX": 17, + "RX": 16, + "line": 2, + "speed": 115200, + "num": 49 + }, + { + "global": 0, + "name": "50. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -704,10 +755,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 47 + "num": 50 }, { - "name": "48. LCD экран 1602", + "name": "51. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -719,6 +770,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 48 + "num": 51 } ] \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index d95e5db4..85482de0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -249,7 +249,8 @@ lib_deps = adafruit/Adafruit BME280 Library adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx - milesburton/DallasTemperature@^3.9.1 + https://github.com/milesburton/Arduino-Temperature-Control-Library + https://github.com/tremaru/iarduino_RTC robtillaart/SHT2x@^0.1.1 WEMOS SHT3x@1.0.0 plerup/espsoftwareserial @@ -274,6 +275,7 @@ build_src_filter = + + + + + + + + @@ -287,6 +289,7 @@ build_src_filter = + + + + + + [env:esp32_4mb_fromitems] @@ -295,7 +298,8 @@ lib_deps = adafruit/Adafruit BME280 Library adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx - milesburton/DallasTemperature@^3.9.1 + https://github.com/milesburton/Arduino-Temperature-Control-Library + https://github.com/tremaru/iarduino_RTC robtillaart/SHT2x@^0.1.1 WEMOS SHT3x@1.0.0 plerup/espsoftwareserial @@ -311,6 +315,7 @@ build_src_filter = + + + + + + + + @@ -320,6 +325,7 @@ build_src_filter = + + + + + + + + @@ -330,9 +336,9 @@ build_src_filter = + + + - + + + + + + + diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 02ae7391..732a6db2 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -15,6 +15,7 @@ void* getAPI_Bmp280(String subtype, String params); void* getAPI_Dht1122(String subtype, String params); void* getAPI_Ds18b20(String subtype, String params); void* getAPI_Pzem004(String subtype, String params); +void* getAPI_RTC(String subtype, String params); void* getAPI_Sht20(String subtype, String params); void* getAPI_Sht30(String subtype, String params); void* getAPI_Sonar(String subtype, String params); @@ -28,6 +29,7 @@ void* getAPI_Multitouch(String subtype, String params); void* getAPI_Pcf8574(String subtype, String params); void* getAPI_Pwm8266(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); +void* getAPI_DwinI(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); void* getAPI(String subtype, String params) { @@ -47,6 +49,7 @@ if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pzem004(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_RTC(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI; @@ -60,6 +63,7 @@ if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_DwinI(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; return nullptr; } \ No newline at end of file diff --git a/src/modules/exec/ButtonIn/ButtonIn.cpp b/src/modules/exec/ButtonIn/ButtonIn.cpp index 7ae01693..9d5910c7 100644 --- a/src/modules/exec/ButtonIn/ButtonIn.cpp +++ b/src/modules/exec/ButtonIn/ButtonIn.cpp @@ -7,30 +7,29 @@ extern IoTGpio IoTgpio; class ButtonIn : public IoTItem { private: int _pin; - bool _execLevel; - int _fixState; - String _pinMode; - int _lastButtonState = LOW; + bool _execLevel, _fixState, _inv, _buttonState, _reading; + bool _lastButtonState = LOW; unsigned long _lastDebounceTime = 0; - long _debounceDelay = 50; - int _buttonState; - int _reading; + int _debounceDelay = 50; public: ButtonIn(String parameters): IoTItem(parameters) { - jsonRead(parameters, "pin", _pin); - jsonRead(parameters, "execLevel", _execLevel); - jsonRead(parameters, "pinMode", _pinMode); - jsonRead(parameters, "debounceDelay", _debounceDelay); - jsonRead(parameters, "fixState", _fixState); - _round = 0; - //Serial.printf("vvvvvvvvvvvvvvvv =%d \n", _fixState); - - if (_pinMode == "INPUT") IoTgpio.pinMode(_pin, INPUT); - else if (_pinMode == "INPUT_PULLDOWN") {IoTgpio.pinMode(_pin, INPUT); IoTgpio.digitalWrite(_pin, LOW);} - else if (_pinMode == "INPUT_PULLUP") IoTgpio.pinMode(_pin, INPUT_PULLUP); + String _pinMode; + jsonRead(parameters, F("inv"), _inv); + jsonRead(parameters, F("pin"), _pin); + jsonRead(parameters, F("execLevel"), _execLevel); + jsonRead(parameters, F("pinMode"), _pinMode); + jsonRead(parameters, F("debounceDelay"), _debounceDelay); + jsonRead(parameters, F("fixState"), _fixState); + _round = 0; + + if (_pinMode == F("INPUT")) IoTgpio.pinMode(_pin, INPUT); + else if (_pinMode == F("INPUT_PULLUP")) IoTgpio.pinMode(_pin, INPUT_PULLUP); + else if (_pinMode == F("INPUT_PULLDOWN")) {IoTgpio.pinMode(_pin, INPUT); IoTgpio.digitalWrite(_pin, LOW);} + value.valD = _buttonState = IoTgpio.digitalRead(_pin); + if (_inv) value.valD = _buttonState = !_buttonState; // инвертируем, если нужно показания // сообщаем всем о стартовом статусе без генерации события regEvent(_buttonState, "", false, false); } @@ -48,17 +47,13 @@ class ButtonIn : public IoTItem { if (_fixState == 1 && _buttonState == _execLevel) { value.valD = !value.valD; - regEvent(value.valD, "ButtonIn"); - } - - if (_fixState == 2) { - value.valD = !value.valD; - regEvent(value.valD, "ButtonIn"); + regEvent(value.valD, F("ButtonIn")); } if (_fixState == 0) { value.valD = _buttonState; - regEvent(value.valD, "ButtonIn"); + if (_inv) value.valD = !_buttonState; // инвертируем, если нужно показания + regEvent(value.valD, F("ButtonIn")); } } } @@ -68,7 +63,7 @@ class ButtonIn : public IoTItem { void setValue(const IoTValue& Value, bool genEvent = true) { value = Value; - regEvent((String)(int)value.valD, "ButtonIn", false, genEvent); + regEvent((String)(int)value.valD, F("ButtonIn"), false, genEvent); } String getValue() { diff --git a/src/modules/exec/ButtonIn/modinfo.json b/src/modules/exec/ButtonIn/modinfo.json index c2abcd99..951df888 100644 --- a/src/modules/exec/ButtonIn/modinfo.json +++ b/src/modules/exec/ButtonIn/modinfo.json @@ -16,7 +16,8 @@ "execLevel": "1", "pinMode": "INPUT", "debounceDelay": 50, - "fixState": 0 + "fixState": 0, + "inv": 0 } ], "about": { @@ -38,7 +39,8 @@ "execLevel": "Высокий 1 или низкий 0 уровень переключения состояния в режиме fixState = 1", "pinMode": "Может быть INPUT_PULLUP INPUT_PULLDOWN INPUT", "debounceDelay": "Время обработки дребезга", - "fixState": "Поведение входа, срабатывание на переходе или на фиксации уровня (триггерный режим)" + "fixState": "Поведение кнопки. При fixState = 0 - нет фиксации и значение кнопки повторяет уровень сигнала на входе. fixState = 1 - кнопка работает как переключатель и переключение происходит по высокому или низкому уровню сигнала (execLevel).", + "inv": "Инвертировать снимаемые показания на последнем этапе." } }, "defActive": true, From d45fc0ed1e31cc9a39f72ad2733a77bceb9faa13 Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 19 Feb 2023 19:13:05 +0300 Subject: [PATCH 10/10] =?UTF-8?q?=D0=98=D1=81=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=20partitions.bin=20=D0=B8=D0=B7=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=BA=D0=B5=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrepareServer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PrepareServer.py b/PrepareServer.py index 6ab6d57a..7289a2f5 100644 --- a/PrepareServer.py +++ b/PrepareServer.py @@ -29,7 +29,8 @@ homeDir = os.path.expanduser('~') os.system(homeDir + "\.platformio\penv\Scripts\pio run") os.system(homeDir + "\.platformio\penv\Scripts\pio run -t buildfs --disable-auto-clean") -if copyFileIfExist("firmware.bin", deviceName) and copyFileIfExist("littlefs.bin", deviceName) and copyFileIfExist("partitions.bin", deviceName): +if copyFileIfExist("firmware.bin", deviceName) and copyFileIfExist("littlefs.bin", deviceName): + copyFileIfExist("partitions.bin", deviceName) versionsJson = json.loads('{"' + deviceName + '": {"0": "400"}}') with open("iotm/ver.json", "w", encoding='utf-8') as write_file: json.dump(versionsJson, write_file, ensure_ascii=False, indent=4, sort_keys=False)