From a0b8f4067d195c82cc7ed8003915e54d987dbd27 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 24 Feb 2023 16:08:39 +0300 Subject: [PATCH 01/14] =?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=20?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D0=BD=D0=B5=D1=80=D0=B0=20=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=BA=20DS2401?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/DS2401/DS2401.cpp | 62 +++++++++++++++++++++++++ src/modules/sensors/DS2401/modinfo.json | 51 ++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/modules/sensors/DS2401/DS2401.cpp create mode 100644 src/modules/sensors/DS2401/modinfo.json diff --git a/src/modules/sensors/DS2401/DS2401.cpp b/src/modules/sensors/DS2401/DS2401.cpp new file mode 100644 index 00000000..4a8e5745 --- /dev/null +++ b/src/modules/sensors/DS2401/DS2401.cpp @@ -0,0 +1,62 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include + +bool cmpAddr(uint8_t *addr1, uint8_t *addr2, int size) { + for (int i=0; isearch(_addr) && _ds) { + if ( OneWire::crc8( _addr, 7) != _addr[7]) { + SerialPrint("E", "DS2401", "CRC is not valid!", _id); + return; + } + + if (!cmpAddr(_addr, _oldAddr, 8) || _repeatCount > _intRepeat) { + hex2string(_addr, 8, _addrStr); + value.valS = _addrStr; + value.isDecimal = false; + regEvent(value.valS, "DS2401"); + memcpy(_oldAddr, _addr, 8); + _repeatCount = 0; + } + } + + if (_repeatCount <= _intRepeat) _repeatCount++; + } + + ~DS2401() { + if (_ds) delete _ds; + }; +}; + +void* getAPI_DS2401(String subtype, String param) { + if (subtype == F("DS2401")) { + return new DS2401(param); + } else { + return nullptr; + } +} + diff --git a/src/modules/sensors/DS2401/modinfo.json b/src/modules/sensors/DS2401/modinfo.json new file mode 100644 index 00000000..1e241d4e --- /dev/null +++ b/src/modules/sensors/DS2401/modinfo.json @@ -0,0 +1,51 @@ +{ + "menuSection": "Сенсоры", + "configItem": [ + { + "global": 0, + "name": "Сканер DS2401 меток", + "type": "Reading", + "subtype": "DS2401", + "id": "rds", + "int": 100, + "intRepeat": 6, + "pin": 12 + } + ], + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "specialThanks": "", + "moduleName": "DS2401", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Сканер DS2401 меток", + "moduleDesc": "Ожидает появления на шине 1-wire метки DS2401", + "propInfo": { + "pin": "GPIO номер, к которому подключена шина 1-Wire с подтяжкой 4,7к", + "int": "Количество миллисекунд между опросами шины. 0 - выключено.", + "intRepeat": "Количество интервалов int пропускаем повторы, т.е. при int=100 и intRepeat=6, первые 600мс игнорируем одинаковые адреса меток." + }, + "retInfo": "Содержит 64-битный адрес метки в формате HEX строки", + "funcInfo": [] + }, + "defActive": false, + "usedLibs": { + "esp32_4mb": [ + ], + "esp8266_4mb": [ + ], + "esp8266_1mb": [ + ], + "esp8266_1mb_ota": [ + ], + "esp8285_1mb": [ + ], + "esp8285_1mb_ota": [ + ] + } +} \ No newline at end of file From 1cbe0394ef55c2270ca02614311ff1afba441b84 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 24 Feb 2023 16:28:04 +0300 Subject: [PATCH 02/14] =?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=20=D0=BF=D1=80=D0=B8=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=20433=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=B8=D0=B3=D0=BD=D0=BE=D1=80=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=A2=D0=B8=D0=BF=D0=B0=20=D0=B7=D0=B0?= =?UTF-8?q?=D1=89=D0=B8=D1=82=D1=8B=20=D0=BE=D1=82=20=D0=B2=D0=B8=D1=80?= =?UTF-8?q?=D1=82=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B1=D0=B5=D0=B7=D0=B3=D0=B0=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/RCswitch/RCswitch.cpp | 19 ++++++++++++++++--- src/modules/sensors/RCswitch/modinfo.json | 6 ++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modules/sensors/RCswitch/RCswitch.cpp b/src/modules/sensors/RCswitch/RCswitch.cpp index 272d5069..d28ca97f 100644 --- a/src/modules/sensors/RCswitch/RCswitch.cpp +++ b/src/modules/sensors/RCswitch/RCswitch.cpp @@ -9,11 +9,16 @@ class RCswitch : public IoTItem { private: int _pinRx; // Выход радио модуля int _pinTx; // Выход модуля передатчика + int _intRepeat = 6; + int _repeatCount = 0; + unsigned long _oldValue = 0; + unsigned long _newValue = 0; public: RCswitch(String parameters): IoTItem(parameters) { jsonRead(parameters, "pinRx", _pinRx); jsonRead(parameters, "pinTx", _pinTx); + jsonRead(parameters, "intRepeat", _intRepeat); _interval = _interval / 1000; // корректируем величину интервала int, теперь он в миллисекундах if (_pinRx >= 0) { Serial.printf("Protocol: %d", _pinRx); @@ -32,11 +37,19 @@ class RCswitch : public IoTItem { // Serial.print("bit "); // Serial.print("Protocol: "); // Serial.println( mySwitch.getReceivedProtocol() ); - value.valD = mySwitch.getReceivedValue(); - regEvent(value.valD, "RCswitch"); - + + _newValue = mySwitch.getReceivedValue(); + if (_newValue != _oldValue || _repeatCount > _intRepeat) { + value.valD = _newValue; + regEvent(value.valD, "RCswitch"); + _oldValue = _newValue; + _repeatCount = 0; + } + mySwitch.resetAvailable(); } + + if (_repeatCount <= _intRepeat) _repeatCount++; } IoTValue execute(String command, std::vector ¶m) { diff --git a/src/modules/sensors/RCswitch/modinfo.json b/src/modules/sensors/RCswitch/modinfo.json index 434a698b..a5c6fa3c 100644 --- a/src/modules/sensors/RCswitch/modinfo.json +++ b/src/modules/sensors/RCswitch/modinfo.json @@ -8,7 +8,8 @@ "type": "Reading", "subtype": "RCswitch", "id": "rsw", - "int": 500, + "int": 100, + "intRepeat": 6, "pinRx": 12, "pinTx": 12 } @@ -29,7 +30,8 @@ "propInfo": { "pinRx": "GPIO номер, к которому подключен радио приемник 433 MHz. Если < 0, то приемник выключен", "pinTx": "GPIO номер, к которому подключен радио передатчик 433 MHz. Если < 0, то передатчик выключен", - "int": "Количество миллисекунд между опросами датчика. 0 - выключено. (устранение повторений при нажатой кнопке)" + "int": "Количество миллисекунд между опросами датчика. 0 - выключено.", + "intRepeat": "Количество интервалов int пропускаем повторы, т.е. при int=100 и intRepeat=6, первые 600мс игнорируем одинаковые значения." }, "retInfo": "Содержит принятое значение", "funcInfo": [ From e774eec72fde258ba7cbeb655b57dc9439ecaa28 Mon Sep 17 00:00:00 2001 From: biver Date: Sat, 25 Feb 2023 15:08:38 +0300 Subject: [PATCH 03/14] =?UTF-8?q?GY21:=20=D0=A3=D1=82=D0=BE=D1=87=D0=BD?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BF=D1=80=D0=B8=D0=B7=D0=BD=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B2=D0=B5=D1=80=D0=BD=D1=8B=D1=85=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/GY21/GY21.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/sensors/GY21/GY21.cpp b/src/modules/sensors/GY21/GY21.cpp index 5af1923b..73af499b 100644 --- a/src/modules/sensors/GY21/GY21.cpp +++ b/src/modules/sensors/GY21/GY21.cpp @@ -21,7 +21,7 @@ class GY21t : public IoTItem { // wire->read(); value.valD = sensor->GY21_Temperature(); if (value.valD < 300) - regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных + regEvent(value.valD, "GY21"); else SerialPrint("E", "Sensor GY21t", "Error", _id); } @@ -36,8 +36,8 @@ class GY21h : public IoTItem { void doByInterval() { // sht->read(); value.valD = sensor->GY21_Humidity(); - if (value.valD != 0) - regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных + if (value.valD > 0) + regEvent(value.valD, "GY21h"); else SerialPrint("E", "Sensor GY21h", "Error", _id); } From 0f25b97ba1f9ce098edce474b3241e833e4701a7 Mon Sep 17 00:00:00 2001 From: biver Date: Sat, 25 Feb 2023 18:31:18 +0300 Subject: [PATCH 04/14] =?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=20main=20=D0=BF=D0=BE=D0=B4=D1=81?= =?UTF-8?q?=D1=87=D0=B5=D1=82=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= =?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=BB=D0=BE=D0=BA=D0=BE=D0=B2=20=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index ae2e11c0..41d694de 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -30,7 +30,61 @@ void elementsLoop() { } + + +#define SETUPBASE_ERRORMARKER 0 +#define SETUPCONF_ERRORMARKER 1 +#define SETUPSCEN_ERRORMARKER 2 +#define SETUPINET_ERRORMARKER 3 +#define SETUPLAST_ERRORMARKER 4 +#define TICKER_ERRORMARKER 5 +#define HTTP_ERRORMARKER 6 +#define SOCKETS_ERRORMARKER 7 +#define MQTT_ERRORMARKER 8 +#define MODULES_ERRORMARKER 9 + +#define COUNTER_ERRORMARKER 9 // количество шагов счетчика +#define STEPPER_ERRORMARKER 100000 // размер шага счетчика интервала доверия выполнения блока кода мкс + +int initErrorMarkerId = 0; // ИД маркера +int errorMarkerId = 0; +unsigned long errorMarkerCounter = 0; + +hw_timer_t *My_timer = NULL; +void IRAM_ATTR onTimer(){ + if (errorMarkerCounter >= 0) { + if (errorMarkerCounter >= COUNTER_ERRORMARKER) { + errorMarkerId = initErrorMarkerId; + errorMarkerCounter = -1; + } else + errorMarkerCounter++; + } +} + +void initErrorMarker(int id) { + initErrorMarkerId = id; + errorMarkerCounter = 0; +} + +void stopErrorMarker(int id) { + errorMarkerCounter = -1; + if (errorMarkerId) + SerialPrint("I", "WARNING!", "A lazy (freezing loop more than " + (String)(COUNTER_ERRORMARKER * STEPPER_ERRORMARKER / 1000) + " ms) section has been found! With ID=" + (String)errorMarkerId); + errorMarkerId = 0; + initErrorMarkerId = 0; +} + + + void setup() { + My_timer = timerBegin(0, 80, true); + timerAttachInterrupt(My_timer, &onTimer, true); + timerAlarmWrite(My_timer, STEPPER_ERRORMARKER, true); + timerAlarmEnable(My_timer); + //timerAlarmDisable(My_timer); + + initErrorMarker(SETUPBASE_ERRORMARKER); + Serial.begin(115200); Serial.flush(); Serial.println(); @@ -53,9 +107,12 @@ void setup() { // синхронизация глобальных переменных с flash globalVarsSync(); - + stopErrorMarker(SETUPBASE_ERRORMARKER); + + initErrorMarker(SETUPCONF_ERRORMARKER); + // настраиваем микроконтроллер configure("/config.json"); @@ -76,17 +133,24 @@ void setup() { SerialPrint("i", "i2c", F("i2c pins overriding done")); } + stopErrorMarker(SETUPCONF_ERRORMARKER); + + + + initErrorMarker(SETUPSCEN_ERRORMARKER); + // подготавливаем сценарии iotScen.loadScenario("/scenario.txt"); - // создаем событие завершения инициализации основных моментов для возможности выполнения блока кода при загрузке createItemFromNet("onInit", "1", 1); - elementsLoop(); + stopErrorMarker(SETUPSCEN_ERRORMARKER); + - + initErrorMarker(SETUPINET_ERRORMARKER); + // подключаемся к роутеру routerConnect(); @@ -106,14 +170,15 @@ void setup() { standWebSocketsInit(); #endif + stopErrorMarker(SETUPINET_ERRORMARKER); + + + + initErrorMarker(SETUPLAST_ERRORMARKER); + // NTP ntpInit(); - // инициализация mqtt - //mqttInit(); - - - // инициализация задач переодического выполнения periodicTasksInit(); @@ -149,6 +214,8 @@ void setup() { // test Serial.println("-------test start--------"); Serial.println("--------test end---------"); + + stopErrorMarker(SETUPLAST_ERRORMARKER); } @@ -158,21 +225,29 @@ void loop() { unsigned long st = millis(); #endif + initErrorMarker(TICKER_ERRORMARKER); ts.update(); + stopErrorMarker(TICKER_ERRORMARKER); #ifdef STANDARD_WEB_SERVER + initErrorMarker(HTTP_ERRORMARKER); HTTP.handleClient(); + stopErrorMarker(HTTP_ERRORMARKER); #endif #ifdef STANDARD_WEB_SOCKETS + initErrorMarker(SOCKETS_ERRORMARKER); standWebSocket.loop(); + stopErrorMarker(SOCKETS_ERRORMARKER); #endif + initErrorMarker(MQTT_ERRORMARKER); mqttLoop(); - + stopErrorMarker(MQTT_ERRORMARKER); + initErrorMarker(MODULES_ERRORMARKER); elementsLoop(); - + stopErrorMarker(MODULES_ERRORMARKER); // #ifdef LOOP_DEBUG // loopPeriod = millis() - st; From edbb563c535948fd9d8262ac3de22b345005dc24 Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 26 Feb 2023 14:24:15 +0300 Subject: [PATCH 05/14] =?UTF-8?q?Logging:=20=D0=BE=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B0=20=D0=B8?= =?UTF-8?q?=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82=D0=BA=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D0=B0=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/virtual/Loging/Loging.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/virtual/Loging/Loging.cpp b/src/modules/virtual/Loging/Loging.cpp index 0af3b274..7a8efb3b 100644 --- a/src/modules/virtual/Loging/Loging.cpp +++ b/src/modules/virtual/Loging/Loging.cpp @@ -16,7 +16,7 @@ class Loging : public IoTItem { int _wsNum = -1; int points; - int keepdays; + //int keepdays; IoTItem *dateIoTItem; @@ -36,12 +36,12 @@ class Loging : public IoTItem { } jsonRead(parameters, F("int"), interval); interval = interval * 1000 * 60; // приводим к милисекундам - jsonRead(parameters, F("keepdays"), keepdays); + //jsonRead(parameters, F("keepdays"), keepdays, false); // создадим экземпляр класса даты dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}"); IoTItems.push_back(dateIoTItem); - SerialPrint("E", F("Loging"), "created date instance " + id); + SerialPrint("I", F("Loging"), "created date instance " + id); } void doByInterval() { From 907c6046b1f7c5a833f120e0ccd7693a3db7a47e Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 26 Feb 2023 16:27:04 +0300 Subject: [PATCH 06/14] =?UTF-8?q?=D0=98=D0=B7=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=D1=81=D1=8F=20=D0=BE=D1=82=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=8F=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8=20Udp=20packet=20invalid=20=D0=92?= =?UTF-8?q?=D0=BE=D0=B7=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D1=87=D0=B8=D0=BD=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B0=D0=BA?= =?UTF-8?q?=D0=B5=D1=82=D0=B0=20=D0=B8=D0=B7=20=D0=B4=D1=80=D1=83=D0=B3?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D1=8B=20=D0=9F?= =?UTF-8?q?=D0=BB=D1=8E=D1=81=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0=20Json=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F=20wg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/DeviceList.h | 1 - src/DeviceList.cpp | 26 ++++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/include/DeviceList.h b/include/DeviceList.h index 7aeb422a..5f376a29 100644 --- a/include/DeviceList.h +++ b/include/DeviceList.h @@ -13,6 +13,5 @@ extern const String getThisDevice(); extern void addThisDeviceToList(); extern void asyncUdpInit(); extern String uint8tToString(uint8_t* data, size_t len); -extern bool udpPacketValidation(String& data); extern void udpPacketParse(String& data); extern void jsonMergeArrays(String& existJson, String& incJson); \ No newline at end of file diff --git a/src/DeviceList.cpp b/src/DeviceList.cpp index 9e5d99c2..c1e398cb 100644 --- a/src/DeviceList.cpp +++ b/src/DeviceList.cpp @@ -37,12 +37,16 @@ void asyncUdpInit() { // Serial.print(", Data: "); // Serial.write(packet.data(), packet.length()); String data = uint8tToString(packet.data(), packet.length()); - // Serial.println(data); - if (udpPacketValidation(data)) { - SerialPrint("i", F("UDP"), "IP: " + packet.remoteIP().toString() + ":" + String(packet.remotePort())); - // Serial.println(data); - jsonMergeArrays(devListHeapJson, data); - // Serial.println(devListHeapJson); + String remoteWorkgroup = ""; + data.replace("[", ""); + data.replace("]", ""); + if (jsonRead(data, F("wg"), remoteWorkgroup)) { // проверяем чтоб полученный формат был Json и заодно вытягиваем имя группы + String loacalWorkgroup = ""; + jsonRead(settingsFlashJson, F("wg"), loacalWorkgroup); + if (remoteWorkgroup == loacalWorkgroup) { + SerialPrint("i", F("UDP"), "IP: " + packet.remoteIP().toString() + ":" + String(packet.remotePort())); + jsonMergeArrays(devListHeapJson, data); + } } else { SerialPrint("E", F("UDP"), F("Udp packet invalid")); } @@ -68,16 +72,6 @@ void asyncUdpInit() { SerialPrint("i", F("UDP"), F("Udp Init")); } -bool udpPacketValidation(String& data) { - // SerialPrint("i", F("UDP"), data); - String workgroup = jsonReadStr(settingsFlashJson, "wg"); - if (workgroup != "" && data.indexOf(workgroup) != -1) { - return true; - } else { - return false; - } -} - void jsonMergeArrays(String& existJson, String& incJson) { DynamicJsonDocument incJsonDoc(1024); DeserializationError incJsonError = deserializeJson(incJsonDoc, incJson); From 6e14411cc4e2c86e45806203285a5cf6996b4de0 Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 26 Feb 2023 16:38:41 +0300 Subject: [PATCH 07/14] =?UTF-8?q?=D0=A3=D0=B1=D0=B8=D1=80=D0=B0=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D1=8F=D1=8E=D1=89?= =?UTF-8?q?=D0=B8=D0=B5=D1=81=D1=8F=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20=D1=83=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=20=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D1=85=20//upd:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DeviceList.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/DeviceList.cpp b/src/DeviceList.cpp index c1e398cb..2040e669 100644 --- a/src/DeviceList.cpp +++ b/src/DeviceList.cpp @@ -75,23 +75,23 @@ void asyncUdpInit() { void jsonMergeArrays(String& existJson, String& incJson) { DynamicJsonDocument incJsonDoc(1024); DeserializationError incJsonError = deserializeJson(incJsonDoc, incJson); - if (incJsonError) { - SerialPrint("E", F("UDP"), "Invailed json in incomming udp packet " + String(incJsonError.f_str())); - jsonErrorDetected(); - return; - } + // if (incJsonError) { // upd: devlist заведомо верный, зачем проверять еще раз? + // SerialPrint("E", F("UDP"), "Invailed json in incomming udp packet " + String(incJsonError.f_str())); + // jsonErrorDetected(); + // return; + // } DynamicJsonDocument existJsonDoc(1024); DeserializationError existJsonError = deserializeJson(existJsonDoc, existJson); - if (existJsonError) { - SerialPrint("E", F("UDP"), "Invailed json in existing udp dev list " + String(incJsonError.f_str())); - jsonErrorDetected(); - return; - } + // if (existJsonError) { // upd: полученный json уже проверен на целостность + // SerialPrint("E", F("UDP"), "Invailed json in existing udp dev list " + String(incJsonError.f_str())); + // jsonErrorDetected(); + // return; + // } JsonArray existJsonArr = existJsonDoc.as(); - incJson.replace("[", ""); - incJson.replace("]", ""); + // incJson.replace("[", ""); // upd: уже исключены символы ранее при получении пакета + // incJson.replace("]", ""); String incIP = jsonReadStr(incJson, "ip"); String outArr = "["; bool ipExistInList = false; From 2b71aad6f4ac41869f55b3d462331611790a9df4 Mon Sep 17 00:00:00 2001 From: biver Date: Sun, 26 Feb 2023 16:52:01 +0300 Subject: [PATCH 08/14] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8?= =?UTF-8?q?=D0=B7=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20uint8tToString=20=D0=B4?= =?UTF-8?q?=D0=BE=20=D0=BD=D1=83=D0=BB=D1=8F...=20=D0=A1=D0=BF=D0=B0=D1=81?= =?UTF-8?q?=D0=B8=D0=B1=D0=BE=20=D0=AE=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/DeviceList.h | 1 - src/DeviceList.cpp | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/include/DeviceList.h b/include/DeviceList.h index 5f376a29..c67b5551 100644 --- a/include/DeviceList.h +++ b/include/DeviceList.h @@ -12,6 +12,5 @@ extern AsyncUDP asyncUdp; extern const String getThisDevice(); extern void addThisDeviceToList(); extern void asyncUdpInit(); -extern String uint8tToString(uint8_t* data, size_t len); extern void udpPacketParse(String& data); extern void jsonMergeArrays(String& existJson, String& incJson); \ No newline at end of file diff --git a/src/DeviceList.cpp b/src/DeviceList.cpp index 2040e669..f5761930 100644 --- a/src/DeviceList.cpp +++ b/src/DeviceList.cpp @@ -36,7 +36,7 @@ void asyncUdpInit() { // Serial.print(packet.length()); // Serial.print(", Data: "); // Serial.write(packet.data(), packet.length()); - String data = uint8tToString(packet.data(), packet.length()); + String data = {packet.data(), packet.length()}; String remoteWorkgroup = ""; data.replace("[", ""); data.replace("]", ""); @@ -121,11 +121,4 @@ void jsonMergeArrays(String& existJson, String& incJson) { existJson = outArr; } -String uint8tToString(uint8_t* data, size_t len) { - String ret; - while (len--) { - ret += (char)*data++; - } - return ret; -} #endif \ No newline at end of file From 37fc18cdfd133461a79165512be0597b39ee2598 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 28 Feb 2023 21:58:14 +0300 Subject: [PATCH 09/14] =?UTF-8?q?=D0=A0=D1=83=D1=87=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D1=82=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=BE=20uint8tToString=20https://github.c?= =?UTF-8?q?om/IoTManagerProject/IoTManager/commit/2b71aad6f4ac41869f55b3d4?= =?UTF-8?q?62331611790a9df4=20=D0=9A=20=D1=81=D0=BE=D0=B6=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8E,=20=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE=D1=81=D1=8C,=20=D1=87=D1=82=D0=BE=20=D0=BD=D1=83?= =?UTF-8?q?=D0=B6=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=20=D0=BE=D1=82=D1=81=D1=83=D1=82?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D1=83=D0=B5=D1=82=20=D0=B2=20Arduino=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=208266?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/DeviceList.h | 1 + src/DeviceList.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/DeviceList.h b/include/DeviceList.h index c67b5551..5f376a29 100644 --- a/include/DeviceList.h +++ b/include/DeviceList.h @@ -12,5 +12,6 @@ extern AsyncUDP asyncUdp; extern const String getThisDevice(); extern void addThisDeviceToList(); extern void asyncUdpInit(); +extern String uint8tToString(uint8_t* data, size_t len); extern void udpPacketParse(String& data); extern void jsonMergeArrays(String& existJson, String& incJson); \ No newline at end of file diff --git a/src/DeviceList.cpp b/src/DeviceList.cpp index f5761930..9a0c42b4 100644 --- a/src/DeviceList.cpp +++ b/src/DeviceList.cpp @@ -36,7 +36,9 @@ void asyncUdpInit() { // Serial.print(packet.length()); // Serial.print(", Data: "); // Serial.write(packet.data(), packet.length()); - String data = {packet.data(), packet.length()}; + + //String data = {packet.data(), packet.length()}; // для ESP32 подходит как замена uint8tToString, но 8266 не переваривает + String data = uint8tToString(packet.data(), packet.length()); String remoteWorkgroup = ""; data.replace("[", ""); data.replace("]", ""); @@ -121,4 +123,11 @@ void jsonMergeArrays(String& existJson, String& incJson) { existJson = outArr; } +String uint8tToString(uint8_t* data, size_t len) { + String ret; + while (len--) { + ret += (char)*data++; + } + return ret; +} #endif \ No newline at end of file From 2c89974a6a1d4376e2a3024e3b6f980eb684db77 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 7 Mar 2023 15:59:09 +0300 Subject: [PATCH 10/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20ple?= =?UTF-8?q?rup/EspSoftwareSerial@^7.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformio.ini | 23 ++++++++++++++++++++--- src/modules/sensors/UART/modinfo.json | 4 ++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index 2c00f2c2..8703517e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -116,7 +116,7 @@ build_src_filter = lib_deps = ${common_env_data.lib_deps_external} ${env:esp32_4mb_fromitems.lib_deps} - plerup/EspSoftwareSerial + plerup/EspSoftwareSerial@^7.0.0 build_flags = -Desp32_4mb="esp32_4mb" framework = arduino board = esp32dev @@ -135,7 +135,12 @@ build_src_filter = [env:esp8266_1mb_ota_fromitems] lib_deps = - milesburton/DallasTemperature@^3.9.1 + adafruit/Adafruit BMP280 Library + https://github.com/milesburton/Arduino-Temperature-Control-Library + rc-switch @ ^2.6.4 + https://github.com/tremaru/iarduino_RTC + robtillaart/SHT2x@^0.1.1 + WEMOS SHT3x@1.0.0 adafruit/Adafruit MCP23017 Arduino Library@^2.1.0 adafruit/Adafruit BusIO @ ^1.13.2 adafruit/Adafruit BusIO @ ^1.13.2 @@ -144,8 +149,17 @@ build_src_filter = + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -154,6 +168,7 @@ build_src_filter = + + + + + + [env:esp8266_1mb_fromitems] @@ -253,11 +268,12 @@ lib_deps = https://github.com/tremaru/iarduino_RTC robtillaart/SHT2x@^0.1.1 WEMOS SHT3x@1.0.0 - plerup/espsoftwareserial + plerup/EspSoftwareSerial@^7.0.0 adafruit/Adafruit MCP23017 Arduino Library@^2.1.0 adafruit/Adafruit BusIO @ ^1.13.2 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 adafruit/Adafruit BusIO @ ^1.13.2 + https://github.com/robotclass/RobotClass_LiquidCrystal_I2C marcoschwartz/LiquidCrystal_I2C@^1.1.4 build_src_filter = + @@ -307,6 +323,7 @@ lib_deps = adafruit/Adafruit BusIO @ ^1.13.2 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 adafruit/Adafruit BusIO @ ^1.13.2 + https://github.com/robotclass/RobotClass_LiquidCrystal_I2C marcoschwartz/LiquidCrystal_I2C@^1.1.4 build_src_filter = + diff --git a/src/modules/sensors/UART/modinfo.json b/src/modules/sensors/UART/modinfo.json index 3f0c1673..b32dbde0 100644 --- a/src/modules/sensors/UART/modinfo.json +++ b/src/modules/sensors/UART/modinfo.json @@ -66,10 +66,10 @@ "defActive": true, "usedLibs": { "esp32_4mb": [ - "plerup/espsoftwareserial" + "plerup/EspSoftwareSerial@^7.0.0" ], "esp8266_4mb": [ - "plerup/espsoftwareserial" + "plerup/EspSoftwareSerial@^7.0.0" ] } } \ No newline at end of file From e0df67cceecb89179255e6be1bc3c6aa114bb362 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 7 Mar 2023 16:03:52 +0300 Subject: [PATCH 11/14] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20Bh1750=20=D0=B8=20Dwini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte_lite/items.json | 237 ++++++++++++++++++++--- myProfile.json | 12 ++ src/modules/display/DwinI/DwinI.cpp | 56 ++++++ src/modules/display/DwinI/modinfo.json | 61 ++++++ src/modules/sensors/BH_1750/Bh1750.cpp | 32 +++ src/modules/sensors/BH_1750/modinfo.json | 44 +++++ 6 files changed, 418 insertions(+), 24 deletions(-) create mode 100644 src/modules/display/DwinI/DwinI.cpp create mode 100644 src/modules/display/DwinI/modinfo.json create mode 100644 src/modules/sensors/BH_1750/Bh1750.cpp create mode 100644 src/modules/sensors/BH_1750/modinfo.json diff --git a/data_svelte_lite/items.json b/data_svelte_lite/items.json index ff7977f3..e943d7b0 100644 --- a/data_svelte_lite/items.json +++ b/data_svelte_lite/items.json @@ -117,7 +117,21 @@ }, { "global": 0, - "name": "8. Виртуальная кнопка", + "name": "8. Цветной текст", + "type": "Reading", + "subtype": "VariableColor", + "id": "color", + "needSave": 0, + "widget": "anydataDef", + "page": "Вывод", + "descr": "Цветной текст", + "val": "...", + "round": 0, + "num": 8 + }, + { + "global": 0, + "name": "9. Виртуальная кнопка", "type": "Reading", "subtype": "VButton", "id": "vbtn", @@ -127,14 +141,77 @@ "descr": "Кнопка", "int": "0", "val": "0", - "num": 8 + "num": 9 + }, + { + "global": 0, + "name": "10. Погода", + "type": "Reading", + "subtype": "Weather", + "id": "Weather", + "needSave": 0, + "widget": "anydataDef", + "page": "Погода", + "descr": "", + "int": 3, + "location": "Moscow", + "param": "temp_C", + "round": 0, + "val": "...", + "num": 10 }, { "header": "Сенсоры" }, { "global": 0, - "name": "9. DS18B20 Температура", + "name": "11. Аналоговый сенсор", + "type": "Reading", + "subtype": "AnalogAdc", + "id": "t", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "map": "1,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 1, + "pin": 0, + "int": 15, + "avgSteps": 1, + "num": 11 + }, + { + "global": 0, + "name": "12. BMP280 Температура", + "type": "Reading", + "subtype": "Bmp280t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "280 Температура", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 12 + }, + { + "global": 0, + "name": "13. BMP280 Давление", + "type": "Reading", + "subtype": "Bmp280p", + "id": "Press3", + "widget": "anydataMm", + "page": "Сенсоры", + "descr": "280 Давление", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 13 + }, + { + "global": 0, + "name": "14. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -146,12 +223,107 @@ "index": 0, "addr": "", "round": 1, - "num": 9 + "num": 14 }, { "global": 0, - "name": "10. HC-SR04 Ультразвуковой дальномер", - "num": 10, + "name": "15. Сканер DS2401 меток", + "type": "Reading", + "subtype": "DS2401", + "id": "rds", + "int": 100, + "intRepeat": 6, + "pin": 12, + "num": 15 + }, + { + "global": 0, + "name": "16. Сканер кнопок 433 MHz", + "num": 16, + "type": "Reading", + "subtype": "RCswitch", + "id": "rsw", + "int": 100, + "intRepeat": 6, + "pinRx": 12, + "pinTx": 12 + }, + { + "global": 0, + "name": "17. Часы реального времени", + "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": 17 + }, + { + "global": 0, + "name": "18. Sht20 Температура", + "type": "Reading", + "subtype": "Sht20t", + "id": "tmp2", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "round": 1, + "num": 18 + }, + { + "global": 0, + "name": "19. Sht20 Влажность", + "type": "Reading", + "subtype": "Sht20h", + "id": "Hum2", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "round": 1, + "num": 19 + }, + { + "global": 0, + "name": "20. Sht30 Температура", + "type": "Reading", + "subtype": "Sht30t", + "id": "tmp30", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "SHT30 Температура", + "int": 15, + "round": 1, + "num": 20 + }, + { + "global": 0, + "name": "21. Sht30 Влажность", + "type": "Reading", + "subtype": "Sht30h", + "id": "Hum30", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "SHT30 Влажность", + "int": 15, + "round": 1, + "num": 21 + }, + { + "global": 0, + "name": "22. HC-SR04 Ультразвуковой дальномер", + "num": 22, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -167,7 +339,7 @@ }, { "global": 0, - "name": "11. Кнопка подключенная к пину", + "name": "23. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -181,11 +353,12 @@ "pinMode": "INPUT", "debounceDelay": 50, "fixState": 0, - "num": 11 + "inv": 0, + "num": 23 }, { "global": 0, - "name": "12. Управление пином", + "name": "24. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -196,11 +369,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 12 + "num": 24 }, { "global": 0, - "name": "13. Расширитель портов Mcp23017", + "name": "25. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -210,11 +383,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 13 + "num": 25 }, { "global": 0, - "name": "14. Сенсорная кнопка", + "name": "26. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -228,11 +401,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 14 + "num": 26 }, { "global": 0, - "name": "15. Расширитель портов Pcf8574", + "name": "27. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -242,11 +415,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 15 + "num": 27 }, { "global": 0, - "name": "16. PWM ESP8266", + "name": "28. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -258,11 +431,11 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 16 + "num": 28 }, { "global": 0, - "name": "17. Телеграм-Лайт", + "name": "29. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -271,14 +444,30 @@ "descr": "", "token": "", "chatID": "", - "num": 17 + "num": 29 }, { "header": "Экраны" }, { "global": 0, - "name": "18. LCD экран 2004", + "name": "30. LCD Dwin экран", + "type": "Reading", + "subtype": "DwinI", + "id": "dwin", + "widget": "", + "page": "", + "descr": "", + "int": 15, + "TX": 17, + "RX": 16, + "line": 2, + "speed": 115200, + "num": 30 + }, + { + "global": 0, + "name": "31. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -290,10 +479,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 18 + "num": 31 }, { - "name": "19. LCD экран 1602", + "name": "32. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -305,6 +494,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 19 + "num": 32 } ] \ No newline at end of file diff --git a/myProfile.json b/myProfile.json index 4edd08a0..b643f2d5 100644 --- a/myProfile.json +++ b/myProfile.json @@ -80,6 +80,10 @@ "path": "src/modules/sensors/AnalogAdc", "active": true }, + { + "path": "src/modules/sensors/BH_1750", + "active": false + }, { "path": "src/modules/sensors/Ble", "active": false @@ -100,6 +104,10 @@ "path": "src/modules/sensors/Ds18b20", "active": true }, + { + "path": "src/modules/sensors/DS2401", + "active": false + }, { "path": "src/modules/sensors/Emon", "active": false @@ -252,6 +260,10 @@ } ], "Экраны": [ + { + "path": "src/modules/display/DwinI", + "active": false + }, { "path": "src/modules/display/Lcd2004", "active": true diff --git a/src/modules/display/DwinI/DwinI.cpp b/src/modules/display/DwinI/DwinI.cpp new file mode 100644 index 00000000..0e43b29c --- /dev/null +++ b/src/modules/display/DwinI/DwinI.cpp @@ -0,0 +1,56 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#ifdef ESP8266 +#include +#else +#include +#endif + +class DwinI : public IoTItem { + private: +#ifdef ESP8266 + SoftwareSerial* _myUART; +#else + HardwareSerial* _myUART; +#endif + + public: + DwinI(String parameters) : IoTItem(parameters) { + int _tx, _rx, _speed, _line; + jsonRead(parameters, "RX", _rx); + jsonRead(parameters, "TX", _tx); + jsonRead(parameters, "speed", _speed); + jsonRead(parameters, "line", _line); + +#ifdef ESP8266 + _myUART = new SoftwareSerial(_rx, _tx); + _myUART->begin(_speed); +#endif +#ifdef ESP32 + _myUART = new HardwareSerial(_line); + _myUART->begin(_speed, SERIAL_8N1, _rx, _tx); +#endif + } + + void doByInterval() { + Serial.println("ddddddddddddd"); + } + + IoTValue execute(String command, std::vector ¶m) { // будет возможным использовать, когда сценарии запустятся + + return {}; + } + + ~DwinI(){ + + }; +}; + +void *getAPI_DwinI(String subtype, String param) { + if (subtype == F("DwinI")) { + return new DwinI(param); + } else { + return nullptr; + } +} diff --git a/src/modules/display/DwinI/modinfo.json b/src/modules/display/DwinI/modinfo.json new file mode 100644 index 00000000..116fda53 --- /dev/null +++ b/src/modules/display/DwinI/modinfo.json @@ -0,0 +1,61 @@ +{ + "menuSection": "Экраны", + + "configItem": [{ + "global": 0, + "name": "LCD Dwin экран", + "type": "Reading", + "subtype": "DwinI", + "id": "dwin", + "widget": "", + "page": "", + "descr": "", + + "int": 15, + "TX": 17, + "RX": 16, + "line": 2, + "speed": 115200 + }], + + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "specialThanks": "", + "moduleName": "DwinI", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "moduleDesc": "Позволяет выводить на графические экраны фирмы Dwin информацию от элементов конфигурации в автоматическом режиме.", + "propInfo": { + "int": "" + }, + "funcInfo": [ + { + "name": "rrrr", + "descr": "rrrr", + "params": [] + } + ] + }, + + "defActive": false, + + "usedLibs": { + "esp32_4mb": [ + ], + "esp8266_4mb": [ + ], + "esp8266_1mb": [ + ], + "esp8266_1mb_ota": [ + ], + "esp8285_1mb": [ + ], + "esp8285_1mb_ota": [ + ] + } +} \ No newline at end of file diff --git a/src/modules/sensors/BH_1750/Bh1750.cpp b/src/modules/sensors/BH_1750/Bh1750.cpp new file mode 100644 index 00000000..d8a171d3 --- /dev/null +++ b/src/modules/sensors/BH_1750/Bh1750.cpp @@ -0,0 +1,32 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include "BH1750.h" + + +class Bh1750 : public IoTItem { + BH1750 _lightMeter; + + public: + Bh1750(String parameters): IoTItem(parameters){ + _lightMeter.begin(); + } + + void doByInterval() { + value.valD = _lightMeter.readLightLevel(); + if (value.valD < 70000) + regEvent(value.valD, "BH1750"); + else + SerialPrint("E", "Sensor BH1750", "Error"); + } + + ~Bh1750() {}; +}; + +void* getAPI_Bh1750(String subtype, String param) { + if (subtype == F("Bh1750")) { + return new Bh1750(param); + } else { + return nullptr; + } +} \ No newline at end of file diff --git a/src/modules/sensors/BH_1750/modinfo.json b/src/modules/sensors/BH_1750/modinfo.json new file mode 100644 index 00000000..832e4c5c --- /dev/null +++ b/src/modules/sensors/BH_1750/modinfo.json @@ -0,0 +1,44 @@ +{ + "menuSection": "Сенсоры", + + "configItem": [{ + "global": 0, + "name": "Cенсор освещенность Bh1750", + "type": "Reading", + "subtype": "Bh1750", + "id": "Bh1750", + "widget": "anydata", + "page": "Сенсоры", + "descr": "Освещённость", + "round": 1, + "int": 15 + }], + + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "exampleURL": "https://iotmanager.org/wiki", + "specialThanks": "", + "moduleName": "Bh1750", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Cенсор освещённости", + "moduleDesc": "Позволяет получить текущее значение освещённости в LUX.", + "propInfo": { + "int": "Количество секунд между опросами датчика." + } + }, + "defActive": false, + "usedLibs": { + "esp32_4mb": [ + "BH1750" + ], + "esp8266_4mb": [ + "BH1750" + ] + } +} \ No newline at end of file From 5f884e16afbe8fb5f0eb57683aa7255c14c7568f Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 8 Mar 2023 15:19:21 +0300 Subject: [PATCH 12/14] =?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=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=D0=B0=20=D1=81=20?= =?UTF-8?q?=D0=BA=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=D0=B8=D1=86=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20Lcd2004?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/display/Lcd2004/Lcd2004.cpp | 10 +++++++--- src/modules/display/Lcd2004/modinfo.json | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modules/display/Lcd2004/Lcd2004.cpp b/src/modules/display/Lcd2004/Lcd2004.cpp index 968bed0b..0caf4ebe 100644 --- a/src/modules/display/Lcd2004/Lcd2004.cpp +++ b/src/modules/display/Lcd2004/Lcd2004.cpp @@ -1,12 +1,15 @@ #include "Global.h" #include "classes/IoTItem.h" -#include "LiquidCrystal_I2C.h" +//#include "LiquidCrystal_I2C.h" +#include + #include void scanI2C(); -LiquidCrystal_I2C *LCDI2C; +//LiquidCrystal_I2C *LCDI2C; +RobotClass_LiquidCrystal_I2C *LCDI2C; class Lcd2004 : public IoTItem { private: @@ -34,7 +37,8 @@ class Lcd2004 : public IoTItem { int w = selectFromMarkerToMarker(size, ",", 0).toInt(); //количество столбцов int h = selectFromMarkerToMarker(size, ",", 1).toInt(); //количество строк if (LCDI2C == nullptr) { //инициализации экрана еще не было - LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(_addr), w, h); + //LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(_addr), w, h); + LCDI2C = new RobotClass_LiquidCrystal_I2C(hexStringToUint8(_addr), w, h, CP_UTF8); if (LCDI2C != nullptr) { LCDI2C->init(); } diff --git a/src/modules/display/Lcd2004/modinfo.json b/src/modules/display/Lcd2004/modinfo.json index a543be7d..24faf854 100644 --- a/src/modules/display/Lcd2004/modinfo.json +++ b/src/modules/display/Lcd2004/modinfo.json @@ -105,21 +105,27 @@ "usedLibs": { "esp32_4mb": [ + "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", "marcoschwartz/LiquidCrystal_I2C@^1.1.4" ], "esp8266_4mb": [ + "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", "marcoschwartz/LiquidCrystal_I2C@^1.1.4" ], "esp8266_1mb": [ + "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", "marcoschwartz/LiquidCrystal_I2C@^1.1.4" ], "esp8266_1mb_ota": [ + "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", "marcoschwartz/LiquidCrystal_I2C@^1.1.4" ], "esp8285_1mb": [ + "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", "marcoschwartz/LiquidCrystal_I2C@^1.1.4" ], "esp8285_1mb_ota": [ + "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", "marcoschwartz/LiquidCrystal_I2C@^1.1.4" ] } From f4071e42dcaca4659acd39415368fb310244c9b2 Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 8 Mar 2023 15:21:25 +0300 Subject: [PATCH 13/14] =?UTF-8?q?=D0=92=D1=8B=D1=80=D0=B0=D0=B2=D0=BD?= =?UTF-8?q?=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20esp8266?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte_lite/items.json | 132 +++++++++++------------------------- platformio.ini | 6 +- 2 files changed, 39 insertions(+), 99 deletions(-) diff --git a/data_svelte_lite/items.json b/data_svelte_lite/items.json index e943d7b0..c1501407 100644 --- a/data_svelte_lite/items.json +++ b/data_svelte_lite/items.json @@ -143,29 +143,12 @@ "val": "0", "num": 9 }, - { - "global": 0, - "name": "10. Погода", - "type": "Reading", - "subtype": "Weather", - "id": "Weather", - "needSave": 0, - "widget": "anydataDef", - "page": "Погода", - "descr": "", - "int": 3, - "location": "Moscow", - "param": "temp_C", - "round": 0, - "val": "...", - "num": 10 - }, { "header": "Сенсоры" }, { "global": 0, - "name": "11. Аналоговый сенсор", + "name": "10. Аналоговый сенсор", "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -179,11 +162,11 @@ "pin": 0, "int": 15, "avgSteps": 1, - "num": 11 + "num": 10 }, { "global": 0, - "name": "12. BMP280 Температура", + "name": "11. BMP280 Температура", "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -193,11 +176,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 12 + "num": 11 }, { "global": 0, - "name": "13. BMP280 Давление", + "name": "12. BMP280 Давление", "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -207,11 +190,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 13 + "num": 12 }, { "global": 0, - "name": "14. DS18B20 Температура", + "name": "13. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -223,34 +206,11 @@ "index": 0, "addr": "", "round": 1, - "num": 14 + "num": 13 }, { "global": 0, - "name": "15. Сканер DS2401 меток", - "type": "Reading", - "subtype": "DS2401", - "id": "rds", - "int": 100, - "intRepeat": 6, - "pin": 12, - "num": 15 - }, - { - "global": 0, - "name": "16. Сканер кнопок 433 MHz", - "num": 16, - "type": "Reading", - "subtype": "RCswitch", - "id": "rsw", - "int": 100, - "intRepeat": 6, - "pinRx": 12, - "pinTx": 12 - }, - { - "global": 0, - "name": "17. Часы реального времени", + "name": "14. Часы реального времени", "type": "Reading", "subtype": "RTC", "id": "rtc", @@ -266,11 +226,11 @@ "int": 5, "btn-setUTime": "0", "btn-setSysTime": "nil", - "num": 17 + "num": 14 }, { "global": 0, - "name": "18. Sht20 Температура", + "name": "15. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -279,11 +239,11 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 18 + "num": 15 }, { "global": 0, - "name": "19. Sht20 Влажность", + "name": "16. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -292,11 +252,11 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 19 + "num": 16 }, { "global": 0, - "name": "20. Sht30 Температура", + "name": "17. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -305,11 +265,11 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 20 + "num": 17 }, { "global": 0, - "name": "21. Sht30 Влажность", + "name": "18. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -318,12 +278,12 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 21 + "num": 18 }, { "global": 0, - "name": "22. HC-SR04 Ультразвуковой дальномер", - "num": 22, + "name": "19. HC-SR04 Ультразвуковой дальномер", + "num": 19, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -339,7 +299,7 @@ }, { "global": 0, - "name": "23. Кнопка подключенная к пину", + "name": "20. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -354,11 +314,11 @@ "debounceDelay": 50, "fixState": 0, "inv": 0, - "num": 23 + "num": 20 }, { "global": 0, - "name": "24. Управление пином", + "name": "21. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -369,11 +329,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 24 + "num": 21 }, { "global": 0, - "name": "25. Расширитель портов Mcp23017", + "name": "22. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -383,11 +343,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 25 + "num": 22 }, { "global": 0, - "name": "26. Сенсорная кнопка", + "name": "23. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -401,11 +361,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 26 + "num": 23 }, { "global": 0, - "name": "27. Расширитель портов Pcf8574", + "name": "24. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -415,11 +375,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 27 + "num": 24 }, { "global": 0, - "name": "28. PWM ESP8266", + "name": "25. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -431,11 +391,11 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 28 + "num": 25 }, { "global": 0, - "name": "29. Телеграм-Лайт", + "name": "26. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -444,30 +404,14 @@ "descr": "", "token": "", "chatID": "", - "num": 29 + "num": 26 }, { "header": "Экраны" }, { "global": 0, - "name": "30. LCD Dwin экран", - "type": "Reading", - "subtype": "DwinI", - "id": "dwin", - "widget": "", - "page": "", - "descr": "", - "int": 15, - "TX": 17, - "RX": 16, - "line": 2, - "speed": 115200, - "num": 30 - }, - { - "global": 0, - "name": "31. LCD экран 2004", + "name": "27. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -479,10 +423,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 31 + "num": 27 }, { - "name": "32. LCD экран 1602", + "name": "28. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -494,6 +438,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 32 + "num": 28 } ] \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 8703517e..42c25d4c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -137,13 +137,13 @@ build_src_filter = lib_deps = adafruit/Adafruit BMP280 Library https://github.com/milesburton/Arduino-Temperature-Control-Library - rc-switch @ ^2.6.4 https://github.com/tremaru/iarduino_RTC robtillaart/SHT2x@^0.1.1 WEMOS SHT3x@1.0.0 adafruit/Adafruit MCP23017 Arduino Library@^2.1.0 adafruit/Adafruit BusIO @ ^1.13.2 adafruit/Adafruit BusIO @ ^1.13.2 + https://github.com/robotclass/RobotClass_LiquidCrystal_I2C marcoschwartz/LiquidCrystal_I2C@^1.1.4 build_src_filter = + @@ -151,12 +151,9 @@ build_src_filter = + + + - + + + + - + - + + + + @@ -168,7 +165,6 @@ build_src_filter = + + + - + + [env:esp8266_1mb_fromitems] From b19b51d2bf3f73bd5fd2eb9512824ec4b76d0049 Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 8 Mar 2023 15:23:16 +0300 Subject: [PATCH 14/14] =?UTF-8?q?=D0=9E=D0=B3=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=87=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC=20=D0=BF=D1=80=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=D0=B0=20=D0=B7=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE=D0=B4=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=208266?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 41d694de..daabef89 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -32,6 +32,7 @@ void elementsLoop() { + #define SETUPBASE_ERRORMARKER 0 #define SETUPCONF_ERRORMARKER 1 #define SETUPSCEN_ERRORMARKER 2 @@ -43,12 +44,14 @@ void elementsLoop() { #define MQTT_ERRORMARKER 8 #define MODULES_ERRORMARKER 9 -#define COUNTER_ERRORMARKER 9 // количество шагов счетчика +#define COUNTER_ERRORMARKER 4 // количество шагов счетчика #define STEPPER_ERRORMARKER 100000 // размер шага счетчика интервала доверия выполнения блока кода мкс -int initErrorMarkerId = 0; // ИД маркера -int errorMarkerId = 0; -unsigned long errorMarkerCounter = 0; +#ifdef esp32_4mb + +static int IRAM_ATTR initErrorMarkerId = 0; // ИД маркера +static int IRAM_ATTR errorMarkerId = 0; +static int IRAM_ATTR errorMarkerCounter = 0; hw_timer_t *My_timer = NULL; void IRAM_ATTR onTimer(){ @@ -60,23 +63,30 @@ void IRAM_ATTR onTimer(){ errorMarkerCounter++; } } +#endif void initErrorMarker(int id) { +#ifdef esp32_4mb initErrorMarkerId = id; errorMarkerCounter = 0; +#endif } void stopErrorMarker(int id) { +#ifdef esp32_4mb errorMarkerCounter = -1; if (errorMarkerId) SerialPrint("I", "WARNING!", "A lazy (freezing loop more than " + (String)(COUNTER_ERRORMARKER * STEPPER_ERRORMARKER / 1000) + " ms) section has been found! With ID=" + (String)errorMarkerId); errorMarkerId = 0; initErrorMarkerId = 0; +#endif } void setup() { + +#ifdef esp32_4mb My_timer = timerBegin(0, 80, true); timerAttachInterrupt(My_timer, &onTimer, true); timerAlarmWrite(My_timer, STEPPER_ERRORMARKER, true); @@ -84,6 +94,7 @@ void setup() { //timerAlarmDisable(My_timer); initErrorMarker(SETUPBASE_ERRORMARKER); +#endif Serial.begin(115200); Serial.flush();