From d337dea1b8942f6ccb9258c78116855ad932e463 Mon Sep 17 00:00:00 2001 From: Mit4el Date: Mon, 13 Jan 2025 19:58:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=20=D0=BF=D0=BE=20=D1=83?= =?UTF-8?q?=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrepareProject.py | 3 + myProfile.json | 38 +- platformio.ini | 184 +++------ src/modules/display/DwinI/modinfo.json | 30 +- src/modules/display/Lcd2004/modinfo.json | 2 +- src/modules/display/Nextion/modinfo.json | 9 +- src/modules/display/Oled64/modinfo.json | 2 +- src/modules/exec/Mcp23017/modinfo.json | 2 +- src/modules/exec/Mp3/modinfo.json | 2 +- src/modules/exec/Pcf8574/modinfo.json | 2 +- src/modules/exec/SIM800/modinfo.json | 2 - src/modules/exec/SmartBoiler/modinfo.json | 1 - src/modules/sensors/A02Distance/modinfo.json | 2 +- src/modules/sensors/Acs712/modinfo.json | 2 +- src/modules/sensors/BL0937/modinfo.json | 2 +- src/modules/sensors/BL0942/modinfo.json | 2 +- src/modules/sensors/EnergyMon485/modinfo.json | 13 +- src/modules/sensors/MQgas/modinfo.json | 17 +- .../sensors/ModbusRTUasync/MudbusRTU.cpp | 381 ------------------ src/modules/sensors/Ntc/modinfo.json | 2 +- src/modules/sensors/Pzem004t_v2/modinfo.json | 15 +- src/modules/sensors/S8/modinfo.json | 2 +- src/modules/sensors/Sht20/modinfo.json | 2 +- src/modules/sensors/Sonar/modinfo.json | 2 +- 24 files changed, 95 insertions(+), 624 deletions(-) delete mode 100644 src/modules/sensors/ModbusRTUasync/MudbusRTU.cpp diff --git a/PrepareProject.py b/PrepareProject.py index 53037698..7e8a495d 100644 --- a/PrepareProject.py +++ b/PrepareProject.py @@ -98,10 +98,13 @@ for opt, arg in opts: printHelp() sys.exit() elif opt in ("-p", "--profile"): + print('Загрузка профиля из файла:' + arg) profile = arg elif opt in ("-u", "--update"): + print('Создание новой конфигурации по исходным файлам!') update = True elif opt in ("-b", "--board"): + print('Создание профиля для платы:' + arg) selectDevice = arg if Path(profile).is_file(): diff --git a/myProfile.json b/myProfile.json index f4b9d32d..72e3986e 100644 --- a/myProfile.json +++ b/myProfile.json @@ -213,16 +213,12 @@ ], "sensors": [ { - "path": "src/modules/exec/Pcf8591", + "path": "src/modules/sensors/A02Distance", "active": false }, - { - "path": "src/modules/sensors/A02Distance", - "active": true - }, { "path": "src/modules/sensors/Acs712", - "active": true + "active": false }, { "path": "src/modules/sensors/Ads1115", @@ -242,11 +238,11 @@ }, { "path": "src/modules/sensors/BL0937", - "active": true + "active": false }, { "path": "src/modules/sensors/BL0942", - "active": true + "active": false }, { "path": "src/modules/sensors/Ble", @@ -346,15 +342,15 @@ }, { "path": "src/modules/sensors/ModbusRTUasync", - "active": true + "active": false }, { "path": "src/modules/sensors/MQgas", - "active": true + "active": false }, { "path": "src/modules/sensors/Ntc", - "active": false + "active": true }, { "path": "src/modules/sensors/Pcf8591", @@ -366,7 +362,7 @@ }, { "path": "src/modules/sensors/Pzem004t_v2", - "active": true + "active": false }, { "path": "src/modules/sensors/RCswitch", @@ -378,7 +374,7 @@ }, { "path": "src/modules/sensors/S8", - "active": true + "active": false }, { "path": "src/modules/sensors/Scd40", @@ -394,7 +390,7 @@ }, { "path": "src/modules/sensors/Sht20", - "active": true + "active": false }, { "path": "src/modules/sensors/Sht30", @@ -402,7 +398,7 @@ }, { "path": "src/modules/sensors/Sonar", - "active": true + "active": false }, { "path": "src/modules/sensors/UART", @@ -464,11 +460,11 @@ }, { "path": "src/modules/exec/Mcp23017", - "active": true + "active": false }, { "path": "src/modules/exec/Mp3", - "active": true + "active": false }, { "path": "src/modules/exec/Multitouch", @@ -480,7 +476,7 @@ }, { "path": "src/modules/exec/Pcf8574", - "active": true + "active": false }, { "path": "src/modules/exec/Pwm32", @@ -530,7 +526,7 @@ "screens": [ { "path": "src/modules/display/DwinI", - "active": true + "active": false }, { "path": "src/modules/display/GyverLAMP", @@ -538,7 +534,7 @@ }, { "path": "src/modules/display/Lcd2004", - "active": true + "active": false }, { "path": "src/modules/display/Nextion", @@ -554,7 +550,7 @@ }, { "path": "src/modules/display/Oled64", - "active": true + "active": false }, { "path": "src/modules/display/Smi2_m", diff --git a/platformio.ini b/platformio.ini index 7870772c..ce9d468f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -679,62 +679,38 @@ lib_deps = adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx https://github.com/milesburton/Arduino-Temperature-Control-Library - robtillaart/SHT2x@^0.1.1 - WEMOS SHT3x@1.0.0 plerup/EspSoftwareSerial gyverlibs/EncButton @ ^2.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 - plerup/EspSoftwareSerial - https://github.com/robotclass/RobotClass_LiquidCrystal_I2C - marcoschwartz/LiquidCrystal_I2C@^1.1.4 - https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED - https://github.com/adafruit/Adafruit-GFX-Library build_src_filter = + + + + + + + + + + + + + - + - + + + - + + + + + + - + - + + + + - + - + - + - + + + + + + + - + - + - + + - + - + + - + - + - + + + [env:esp32_4mb_fromitems] lib_deps = @@ -743,31 +719,20 @@ lib_deps = adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx https://github.com/milesburton/Arduino-Temperature-Control-Library - robtillaart/SHT2x@^0.1.1 - WEMOS SHT3x@1.0.0 plerup/EspSoftwareSerial gyverlibs/EncButton @ ^2.0 - https://github.com/RoboticsBrno/ServoESP32#v1.0.3 - 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 - https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED - https://github.com/adafruit/Adafruit-GFX-Library - https://github.com/maxint-rd/TM16xx - adafruit/Adafruit GFX Library @ ^1.11.5 - adafruit/Adafruit BusIO @ ^1.13.2 build_src_filter = + + + + + + + + + + + + + + + - + + + + @@ -775,29 +740,18 @@ build_src_filter = + + + - + + + + - + - + - + - + + + + + + + + - + - + - + + - + - + + + - + - + - + - + + + [env:esp32_4mb3f_fromitems] lib_deps = @@ -806,64 +760,39 @@ lib_deps = adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx https://github.com/milesburton/Arduino-Temperature-Control-Library - robtillaart/SHT2x@^0.1.1 - WEMOS SHT3x@1.0.0 plerup/EspSoftwareSerial gyverlibs/EncButton @ ^2.0 - https://github.com/RoboticsBrno/ServoESP32#v1.0.3 - 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 - plerup/EspSoftwareSerial - https://github.com/robotclass/RobotClass_LiquidCrystal_I2C - marcoschwartz/LiquidCrystal_I2C@^1.1.4 - https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED - https://github.com/adafruit/Adafruit-GFX-Library build_src_filter = + + + + + + + + + + + + + - + - + + + - + + + + + + - + - + + + + - + - + - + - + + + + + + + - + - + - + + - + + + - + - + - + - + + + [env:esp32cam_4mb_fromitems] lib_deps = @@ -896,19 +825,44 @@ build_src_filter = [env:esp8266_16mb_fromitems] lib_deps = + https://github.com/dancol90/ESP8266Ping + https://github.com/enjoyneering/AHTxx.git + adafruit/Adafruit BME280 Library + adafruit/Adafruit BMP280 Library + beegee-tokyo/DHT sensor library for ESPx + https://github.com/milesburton/Arduino-Temperature-Control-Library + plerup/EspSoftwareSerial gyverlibs/EncButton @ ^2.0 build_src_filter = + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [env:esp32_16mb_fromitems] lib_deps = @@ -953,58 +907,39 @@ lib_deps = adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg - robtillaart/SHT2x@^0.1.1 - WEMOS SHT3x@1.0.0 plerup/EspSoftwareSerial gyverlibs/EncButton @ ^2.0 - https://github.com/RoboticsBrno/ServoESP32#v1.0.3 - 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 - https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED - https://github.com/adafruit/Adafruit-GFX-Library build_src_filter = + + + + + + + + + + + + + - + - + + + - + + + + + + + + + - + - + - + - + + + + + + + - + - + + - + + + - + - + - + + + [env:esp32c6_8mb_fromitems] lib_deps = @@ -1013,58 +948,39 @@ lib_deps = adafruit/Adafruit BMP280 Library beegee-tokyo/DHT sensor library for ESPx https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg - robtillaart/SHT2x@^0.1.1 - WEMOS SHT3x@1.0.0 plerup/EspSoftwareSerial gyverlibs/EncButton @ ^2.0 - https://github.com/RoboticsBrno/ServoESP32#v1.0.3 - 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 - https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED - https://github.com/adafruit/Adafruit-GFX-Library build_src_filter = + + + + + + + + + + + + + - + - + + + - + + + + + + + + + - + - + - + - + + + + + + + - + - + + - + + + - + - + - + + + [env:bk7231n_fromitems] lib_deps = @@ -1072,13 +988,13 @@ build_src_filter = + + + + + + + + + + + - + + + + diff --git a/src/modules/display/DwinI/modinfo.json b/src/modules/display/DwinI/modinfo.json index c5a57f04..863ee10c 100644 --- a/src/modules/display/DwinI/modinfo.json +++ b/src/modules/display/DwinI/modinfo.json @@ -40,36 +40,12 @@ "btn-uploadUI": "Формирует автоматически графический интерфейс на базе конфигурации и выгружает в экран. Занимает продолжительное время! (в разработке)" } }, - "defActive": true, + "defActive": false, "usedLibs": { - "esp32_4mb": [ + "esp32*": [ "plerup/EspSoftwareSerial" ], - "esp32_4mb3f": [ - "plerup/EspSoftwareSerial" - ], - "esp32cam_4mb": [ - "plerup/EspSoftwareSerial" - ], - "esp8266_4mb": [ - "plerup/EspSoftwareSerial" - ], - "esp8266_1mb": [ - "plerup/EspSoftwareSerial" - ], - "esp8266_1mb_ota": [ - "plerup/EspSoftwareSerial" - ], - "esp8266_2mb": [ - "plerup/EspSoftwareSerial" - ], - "esp8266_2mb_ota": [ - "plerup/EspSoftwareSerial" - ], - "esp8285_1mb": [ - "plerup/EspSoftwareSerial" - ], - "esp8285_1mb_ota": [ + "esp82*": [ "plerup/EspSoftwareSerial" ] } diff --git a/src/modules/display/Lcd2004/modinfo.json b/src/modules/display/Lcd2004/modinfo.json index 0700b92f..bdf3f34f 100644 --- a/src/modules/display/Lcd2004/modinfo.json +++ b/src/modules/display/Lcd2004/modinfo.json @@ -117,7 +117,7 @@ } ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [ "https://github.com/robotclass/RobotClass_LiquidCrystal_I2C", diff --git a/src/modules/display/Nextion/modinfo.json b/src/modules/display/Nextion/modinfo.json index f473471c..be965fb7 100644 --- a/src/modules/display/Nextion/modinfo.json +++ b/src/modules/display/Nextion/modinfo.json @@ -89,12 +89,7 @@ }, "defActive": false, "usedLibs": { - "esp32_4mb": [], - "esp32_4mb3f": [], - "esp8266_4mb": [], - "esp8266_1mb": [], - "esp8266_1mb_ota": [], - "esp8285_1mb": [], - "esp8285_1mb_ota": [] + "esp32*": [], + "esp82*": [] } } \ No newline at end of file diff --git a/src/modules/display/Oled64/modinfo.json b/src/modules/display/Oled64/modinfo.json index b64b4eef..ee34620c 100644 --- a/src/modules/display/Oled64/modinfo.json +++ b/src/modules/display/Oled64/modinfo.json @@ -75,7 +75,7 @@ } ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [ "https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED", diff --git a/src/modules/exec/Mcp23017/modinfo.json b/src/modules/exec/Mcp23017/modinfo.json index 5d2fba62..91a6f97c 100644 --- a/src/modules/exec/Mcp23017/modinfo.json +++ b/src/modules/exec/Mcp23017/modinfo.json @@ -34,7 +34,7 @@ "index": "Значения от 1 до 4, где при выборе 1 будет нумерация pin 100-115, при выборе 2 200-215 и т.д." } }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [ "adafruit/Adafruit MCP23017 Arduino Library@^2.1.0", diff --git a/src/modules/exec/Mp3/modinfo.json b/src/modules/exec/Mp3/modinfo.json index e64d1460..3494d9a5 100644 --- a/src/modules/exec/Mp3/modinfo.json +++ b/src/modules/exec/Mp3/modinfo.json @@ -87,7 +87,7 @@ } ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [ "dfrobot/DFRobotDFPlayerMini @ ^1.0.5" diff --git a/src/modules/exec/Pcf8574/modinfo.json b/src/modules/exec/Pcf8574/modinfo.json index f3ece10d..6a040c14 100644 --- a/src/modules/exec/Pcf8574/modinfo.json +++ b/src/modules/exec/Pcf8574/modinfo.json @@ -30,7 +30,7 @@ }, "title": "Расширитель портов Pcf8574" }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [ "adafruit/Adafruit BusIO @ ^1.13.2" diff --git a/src/modules/exec/SIM800/modinfo.json b/src/modules/exec/SIM800/modinfo.json index 959879ed..aac9f890 100644 --- a/src/modules/exec/SIM800/modinfo.json +++ b/src/modules/exec/SIM800/modinfo.json @@ -78,8 +78,6 @@ }, "defActive": false, "usedLibs": { - "esp32_4mb": [], - "esp32_4mb3f": [], "esp32*": [], "esp82*": [] } diff --git a/src/modules/exec/SmartBoiler/modinfo.json b/src/modules/exec/SmartBoiler/modinfo.json index af2aa194..a5a1e861 100644 --- a/src/modules/exec/SmartBoiler/modinfo.json +++ b/src/modules/exec/SmartBoiler/modinfo.json @@ -164,7 +164,6 @@ }, "defActive": false, "usedLibs": { - "esp32_4mb3f": [], "esp32*": [], "esp82*": [] } diff --git a/src/modules/sensors/A02Distance/modinfo.json b/src/modules/sensors/A02Distance/modinfo.json index ba970862..85ac0c70 100644 --- a/src/modules/sensors/A02Distance/modinfo.json +++ b/src/modules/sensors/A02Distance/modinfo.json @@ -35,7 +35,7 @@ }, "title": "A0221AU, A02YYUW Ультразвуковой датчик дальности" }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [], "esp82*": [] diff --git a/src/modules/sensors/Acs712/modinfo.json b/src/modules/sensors/Acs712/modinfo.json index b741d377..c542e2c1 100644 --- a/src/modules/sensors/Acs712/modinfo.json +++ b/src/modules/sensors/Acs712/modinfo.json @@ -39,7 +39,7 @@ }, "title": "Acs712 Датчик тока" }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [], "esp82*": [] diff --git a/src/modules/sensors/BL0937/modinfo.json b/src/modules/sensors/BL0937/modinfo.json index f6dea0d2..66aeba0f 100644 --- a/src/modules/sensors/BL0937/modinfo.json +++ b/src/modules/sensors/BL0937/modinfo.json @@ -129,7 +129,7 @@ } ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [], "esp82*": [], diff --git a/src/modules/sensors/BL0942/modinfo.json b/src/modules/sensors/BL0942/modinfo.json index de771e05..39ac37b8 100644 --- a/src/modules/sensors/BL0942/modinfo.json +++ b/src/modules/sensors/BL0942/modinfo.json @@ -99,7 +99,7 @@ } ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [], "esp82*": [], diff --git a/src/modules/sensors/EnergyMon485/modinfo.json b/src/modules/sensors/EnergyMon485/modinfo.json index 233bfabc..1e5823a0 100644 --- a/src/modules/sensors/EnergyMon485/modinfo.json +++ b/src/modules/sensors/EnergyMon485/modinfo.json @@ -67,17 +67,6 @@ "defActive": false, "usedLibs": { "esp32*": [], - "esp82*": [], - "esp32_4mb": [], - "esp32_4mb3f": [], - "esp32cam_4mb": [], - "esp32c3m_4mb": [], - "esp8266_4mb": [], - "esp8266_1mb": [], - "esp8266_1mb_ota": [], - "esp8285_1mb": [], - "esp8285_1mb_ota": [], - "esp8266_2mb": [], - "esp8266_2mb_ota": [] + "esp82*": [] } } \ No newline at end of file diff --git a/src/modules/sensors/MQgas/modinfo.json b/src/modules/sensors/MQgas/modinfo.json index bcaa1fd6..4b1f42d9 100644 --- a/src/modules/sensors/MQgas/modinfo.json +++ b/src/modules/sensors/MQgas/modinfo.json @@ -252,20 +252,9 @@ ] }, - "defActive": true, + "defActive": false, "usedLibs": { - "esp32_4mb": [], - "esp32_4mb3f": [], - "esp32cam_4mb": [], - "esp32_16mb": [], - "esp32s2_4mb": [], - "esp8266_4mb": [], - "esp8266_16mb": [], - "esp8266_1mb": [], - "esp8266_1mb_ota": [], - "esp8285_1mb": [], - "esp8285_1mb_ota": [], - "esp8266_2mb": [], - "esp8266_2mb_ota": [] + "esp32*": [], + "esp82*": [] } } diff --git a/src/modules/sensors/ModbusRTUasync/MudbusRTU.cpp b/src/modules/sensors/ModbusRTUasync/MudbusRTU.cpp deleted file mode 100644 index 1c455594..00000000 --- a/src/modules/sensors/ModbusRTUasync/MudbusRTU.cpp +++ /dev/null @@ -1,381 +0,0 @@ -#include "Global.h" -#include "classes/IoTItem.h" -#include -#include - -#include "Logging.h" -#include "ModbusClientRTU.h" -#include "CoilData.h" - -// class ModbusUart; -Stream *_modbusUART = nullptr; - -// Данные Modbus по умолчанию -int8_t _DIR_PIN = 0; -#define UART_LINE 2 -#define MODBUS_RX_PIN 18 // Rx pin -#define MODBUS_TX_PIN 19 // Tx pin -#define MODBUS_SERIAL_BAUD 9600 // Baud rate for esp32 and max485 communication - -bool data_ready = false; -uint32_t request_time; - -ModbusClientRTU *MB = nullptr; - -ModbusClientRTU *instanceModBus(int8_t _DR) -{ - if (!MB) - { // Если библиотека ранее инициализировалась, т о просто вернем указатель - // Инициализируем библиотеку - if (_DR) - MB = new ModbusClientRTU(_DR); - else - MB = new ModbusClientRTU(); - } - return MB; -} -// ModbusClientRTU MB(_DIR_PIN); -// ModbusClientRTU MB(); - -// TODO УБРАТЬ ЭТО ИЗ ПРИМЕРА -#define NUM_VALUES 21 -float values[NUM_VALUES]; -// Define an onData handler function to receive the regular responses -// Arguments are received response message and the request's token -void handleModBusData(ModbusMessage response, uint32_t token) -{ - printf("Response --- FC:%02X Server:%d Length:%d\n", - response.getFunctionCode(), - response.getServerID(), - response.size()); - HEXDUMP_N("Data dump", response.data(), response.size()); - data_ready = true; -} - -// Define an onError handler function to receive error responses -// Arguments are the error code returned and a user-supplied token to identify the causing request -void handleModBusError(Error error, uint32_t token) -{ - // ModbusError wraps the error code and provides a readable error message for it - ModbusError me(error); - // LOG_E("Error response: %02X - %s\n", (int)me, (const char *)me); - Serial.printf("Error response: %02X - %s\n", (int)me, (const char *)me); -} - -class ModbusClientAsync : public IoTItem -{ -private: - int8_t _rx = MODBUS_RX_PIN; // адреса прочитаем с веба - int8_t _tx = MODBUS_TX_PIN; - int _baud = MODBUS_SERIAL_BAUD; - String _prot = "SERIAL_8N1"; - int protocol = SERIAL_8N1; - - int _addr = 0; // Адрес слейва от 1 до 247 ( вроде ) - String _regStr = ""; // Адрес регистра который будем дергать ( по коду от 0х0000 до 0х????) - uint16_t _reg = 0; - bool _debug; // Дебаг - -public: - ModbusClientAsync(String parameters) : IoTItem(parameters) - { - _rx = (int8_t)jsonReadInt(parameters, "RX"); // прочитаем с веба - _tx = (int8_t)jsonReadInt(parameters, "TX"); - _DIR_PIN = (int8_t)jsonReadInt(parameters, "DIR_PIN"); - _baud = jsonReadInt(parameters, "baud"); - _prot = jsonReadStr(parameters, "protocol"); - jsonRead(parameters, "debug", _debug); - - if (_prot == "SERIAL_8N1") - { - protocol = SERIAL_8N1; - } - else if (_prot == "SERIAL_8N2") - { - protocol = SERIAL_8N2; - } - - pinMode(_DIR_PIN, OUTPUT); - digitalWrite(_DIR_PIN, LOW); - - // Serial2.begin(baud-rate, protocol, RX pin, TX pin); - instanceModBus(_DIR_PIN); - _modbusUART = new HardwareSerial(UART_LINE); - - if (_debug) - { - SerialPrint("I", "ModbusClientAsync", "baud: " + String(_baud) + ", protocol: " + String(protocol, HEX) + ", RX: " + String(_rx) + ", TX: " + String(_tx)); - } - RTUutils::prepareHardwareSerial((HardwareSerial &)*_modbusUART); - // Serial2.begin(BAUDRATE, SERIAL_8N1, RXPIN, TXPIN); - ((HardwareSerial *)_modbusUART)->begin(_baud, protocol, _rx, _tx); // выбираем тип протокола, скорость и все пины с веба - ((HardwareSerial *)_modbusUART)->setTimeout(200); - - // Set up ModbusRTU client. - // - provide onData handler function - MB->onDataHandler(&handleModBusData); - // - provide onError handler function - MB->onErrorHandler(&handleModBusError); - // Set message timeout to 2000ms - MB->setTimeout(2000); - // Start ModbusRTU background task - MB->begin((HardwareSerial &)*_modbusUART); - } - - // Комманды из сценария - IoTValue execute(String command, std::vector ¶m) - { - IoTValue val; - uint8_t result; - uint32_t reading; - - uint16_t _reg = 0; - uint8_t count = 1; - bool isFloat = 0; - if (command == "readInputRegisters") // vout = mb.readInputRegisters(1, "0х0000", 1, 0) - "Адрес","Регистр","Кличество регистров","1-float, 0-long" - { - if (param.size()) - { - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - count = (uint8_t)param[2].valD; - count = count > 2 ? 2 : count; - count = count < 1 ? 1 : count; - isFloat = (bool)param[3].valD; - // val.valD = readFunctionModBus(0x04, _addr, _reg, count, isFloat); - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, READ_INPUT_REGISTER, _reg, count); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - return val; - } - else if (command == "readHoldingRegisters") // vout = mb.readHoldingRegisters(1, "0х0000", 2, 1) - "Адрес","Регистр","Кличество регистров","1-float, 0-long" - { - if (param.size()) - { - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - count = (uint8_t)param[2].valD; - count = count > 2 ? 2 : count; - count = count < 1 ? 1 : count; - isFloat = (bool)param[3].valD; - // val.valD = readFunctionModBus(0x03, _addr, _reg, count, isFloat); - - // Create request for - // (Fill in your data here!) - // - server ID = 1 - // - function code = 0x03 (read holding register) - // - start address to read = word 10 - // - number of words to read = 4 - // - token to match the response with the request. We take the current millis() value for it. - // - // If something is missing or wrong with the call parameters, we will immediately get an error code - // and the request will not be issued - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, READ_HOLD_REGISTER, _reg, count); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - return val; - } - else if (command == "readCoils") // vout = mb.readCoils(1, \"0х0000\", 1) - "Адрес","Регистр","Кличество бит" - { - if (param.size()) - { - count = (uint8_t)param[2].valD; - count = count > 16 ? 16 : count; - count = count < 1 ? 1 : count; - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - // node.begin(_addr, (Stream &)*_modbusUART); - // val.valD = readFunctionModBus(0x01, _addr, _reg, count); - - // Read a slice of 12 coils, starting at 13 - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, READ_COIL, _reg, count); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - return val; - } - else if (command == "readDiscreteInputs") // vout = mb.readDiscreteInputs(1, \"0х0000\", 1) - "Адрес","Регистр","Кличество бит" - { - if (param.size()) - { - count = (uint8_t)param[2].valD; - count = count > 16 ? 16 : count; - count = count < 1 ? 1 : count; - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - // node.begin(_addr, (Stream &)*_modbusUART); - // val.valD = readFunctionModBus(0x02, _addr, _reg, count); - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, READ_DISCR_INPUT, _reg, count); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - return val; - } - else if (command == "writeSingleRegister") // vout = mb.writeSingleRegister(1,"0x0003", 1) - addr, register, state - { - if (param.size()) - { - // node.begin((uint8_t)param[0].valD, (Stream &)*_modbusUART); - - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - // bool state = param[2].valD; - uint16_t state = param[2].valD; - // result = node.writeSingleRegister(_reg, state); - if (_debug) - { - SerialPrint("I", "ModbusClientAsync", "writeSingleRegister, addr: " + String((uint8_t)_addr, HEX) + ", regStr: " + _regStr + ", reg: " + String(_reg, HEX) + ", state: " + String(state) + " = result: " + String(result, HEX)); - } - - // We will first set the register to a known state, read the register, - // then write to it and finally read it again to verify the change - - // Set defined conditions first - write 0x1234 to the register - // The Token value is used in handleData to avoid the output for this first preparation request! - // uint32_t Token = 1111; - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, WRITE_HOLD_REGISTER, _reg, state); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - // Что можно вернуть в ответ на запись ??? - return {}; - } - else if (command == "writeSingleCoil") // vout = mb.writeSingleCoil(1,"0x0003", 1) - addr, register, state - { - if (param.size()) - { - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - // node.begin(_addr, (Stream &)*_modbusUART); - - bool state = param[2].valD; - // result = node.writeSingleCoil(_reg, state); - if (_debug) - { - SerialPrint("I", "ModbusClientAsync", "writeSingleCoil, addr: " + String((uint8_t)_addr, HEX) + ", regStr: " + _regStr + ", reg: " + String(_reg, HEX) + ", state: " + String(state) + " = result: " + String(result, HEX)); - } - - // next set a single coil at 8 - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, WRITE_COIL, _reg, state); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - // Что можно вернуть в ответ на запись койлов??? - return {}; - } - else if (command == "writeMultipleCoils") // Пример: mb.writeMultipleCoils(1, \"0х0000\", 4, 3) - будут записаны в четыре бита 0011 - { - if (param.size()) - { - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - count = (uint8_t)param[2].valD; - count = count > 16 ? 16 : count; - count = count < 1 ? 1 : count; - // node.begin(_addr, (Stream &)*_modbusUART); - - uint16_t state = param[3].valD; - // node.setTransmitBuffer(0, state); - // result = node.writeMultipleRegisters(_reg, count); - // node.clearTransmitBuffer(); - if (_debug) - { - SerialPrint("I", "ModbusClientAsync", "writeSingleCoil, addr: " + String((uint8_t)_addr, HEX) + ", regStr: " + _regStr + ", reg: " + String(_reg, HEX) + ", state: " + String(state) + " = result: " + String(result, HEX)); - } - - CoilData cd(12); - // Finally set a a bunch of coils starting at 20 - cd = "011010010110"; - uint32_t lastMillis = millis(); - Serial.printf("sending request with token %d\n", (uint32_t)lastMillis); - Error err; - err = MB->addRequest((uint32_t)lastMillis, _addr, WRITE_MULT_COILS, _reg, cd.coils(), cd.size(), cd.data()); - if (err != SUCCESS) - { - ModbusError e(err); - Serial.printf("Error creating request: %02X - %s\n", (int)e, (const char *)e); - } - } - return {}; - } - // На данный момент записывает 2(два) регистра!!!!! Подходит для записи float?? Функция 0х10 протокола. - else if (command == "writeMultipleRegisters") // mb.writeMultipleRegisters(1, \"0х0000\", 1234.987) - { - if (param.size()) - { - _addr = param[0].valD; - _reg = hexStringToUint16(param[1].valS); - // node.begin(_addr, (Stream &)*_modbusUART); - - float state = param[2].valD; - - // node.setTransmitBuffer(0, lowWord(state)); - // node.setTransmitBuffer(1, highWord(state)); - // result = node.writeMultipleRegisters(_reg, 2); - // node.clearTransmitBuffer(); - Serial.printf("NOT SUPPORTED!\n"); - if (_debug) - { - SerialPrint("I", "ModbusClientAsync", "writeMultipleRegisters, addr: " + String((uint8_t)_addr, HEX) + ", reg: " + String(_reg, HEX) + ", state: " + String(state) + " (" + String(state, HEX) + ")"); - } - } - return {}; - } - return val; - } - - ~ModbusClientAsync() - { - delete _modbusUART; - _modbusUART = nullptr; - }; -}; - -void *getAPI_ModbusRTUasync(String subtype, String param) -{ - if (subtype == F("mbClient")) - { - return new ModbusClientAsync(param); - } - { - return nullptr; - } -} diff --git a/src/modules/sensors/Ntc/modinfo.json b/src/modules/sensors/Ntc/modinfo.json index 6e0dc849..f7876979 100644 --- a/src/modules/sensors/Ntc/modinfo.json +++ b/src/modules/sensors/Ntc/modinfo.json @@ -48,7 +48,7 @@ "Beta": "Beta термистора" } }, - "defActive": false, + "defActive": true, "usedLibs": { "esp32*": [], "esp82*": [] diff --git a/src/modules/sensors/Pzem004t_v2/modinfo.json b/src/modules/sensors/Pzem004t_v2/modinfo.json index 57008f54..6b543024 100644 --- a/src/modules/sensors/Pzem004t_v2/modinfo.json +++ b/src/modules/sensors/Pzem004t_v2/modinfo.json @@ -142,18 +142,9 @@ "btn-reset": "pzem будет сброшен к нулю. Смотрите в логе результат: [i] Pzem reset done" } }, - "defActive": true, + "defActive": false, "usedLibs": { - "esp32_4mb": [], - "esp32_4mb3f": [], - "esp32cam_4mb": [], - "esp32c3m_4mb": [], - "esp8266_4mb": [], - "esp8266_1mb": [], - "esp8266_1mb_ota": [], - "esp8285_1mb": [], - "esp8285_1mb_ota": [], - "esp8266_2mb": [], - "esp8266_2mb_ota": [] + "esp32*": [], + "esp82*": [] } } \ No newline at end of file diff --git a/src/modules/sensors/S8/modinfo.json b/src/modules/sensors/S8/modinfo.json index 5aeadc3f..eab320b8 100644 --- a/src/modules/sensors/S8/modinfo.json +++ b/src/modules/sensors/S8/modinfo.json @@ -34,7 +34,7 @@ "int": "Количество секунд между опросами датчика." } }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [], "esp82*": [] diff --git a/src/modules/sensors/Sht20/modinfo.json b/src/modules/sensors/Sht20/modinfo.json index fdded673..b2feed28 100644 --- a/src/modules/sensors/Sht20/modinfo.json +++ b/src/modules/sensors/Sht20/modinfo.json @@ -47,7 +47,7 @@ "int": "Количество секунд между опросами датчика." } }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [ "robtillaart/SHT2x@^0.1.1" diff --git a/src/modules/sensors/Sonar/modinfo.json b/src/modules/sensors/Sonar/modinfo.json index 737ecd3f..de6fcd56 100644 --- a/src/modules/sensors/Sonar/modinfo.json +++ b/src/modules/sensors/Sonar/modinfo.json @@ -35,7 +35,7 @@ "int": "Количество секунд между опросами датчика." } }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32*": [], "esp82*": []