From d9e111470a15ea03c2f48a2f8510dec5958eb773 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 7 Mar 2022 11:54:25 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20MHZ19=20=D0=B8=20Sds011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 148 ++++++++- platformio.ini | 2 + src/modules/API.cpp | 4 + src/modules/Mhz19.cpp | 689 +++++++++++++++++++++++++++++++++++++++++ src/modules/Sds011.cpp | 209 +++++++++++++ 5 files changed, 1038 insertions(+), 14 deletions(-) create mode 100644 src/modules/Mhz19.cpp create mode 100644 src/modules/Sds011.cpp diff --git a/data_svelte/items.json b/data_svelte/items.json index d161eec1..52db34f6 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -228,12 +228,132 @@ "round": 1, "int": 15 }, + { + "name": "18. Датчик пыли SDS011 PM25", + "num": 18, + "type": "Reading", + "subtype": "Sds011_25", + "id": "pmuart25", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "PM-2.5", + "plus": 0, + "multiply": 1, + "round": 10, + "rxPin": 13, + "txPin": 12, + "int": 15, + "warmUp": 30, + "period": 300 + }, + { + "name": "19. Датчик пыли SDS011 PM10", + "num": 19, + "type": "Reading", + "subtype": "Sds011_10", + "id": "pmuart10", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "PM-10", + "plus": 0, + "multiply": 1, + "round": 10, + "rxPin": 13, + "txPin": 12, + "int": 15, + "warmUp": 30, + "period": 300 + }, + { + "name": "20. Датчик CO2 MHZ-19 UART", + "num": 20, + "type": "Reading", + "subtype": "Mhz19uart", + "id": "co2uart", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "CO2uart", + "plus": 0, + "multiply": 1, + "round": 1, + "pin": 0, + "rxPin": 14, + "txPin": 16, + "int": 15, + "range": 5000, + "ABC": 1 + }, + { + "name": "21. Датчик CO2 MHZ-19 PWM", + "num": 21, + "type": "Reading", + "subtype": "Mhz19pwm", + "id": "co2pwm", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "CO2pwm", + "plus": 0, + "multiply": 1, + "round": 1, + "pin": 16, + "int": 300 + }, + { + "name": "22. Cенсор температуры от MHZ-19 UART", + "num": 22, + "type": "Reading", + "subtype": "Mhz19temp", + "id": "Mhz19temp", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "plus": 0, + "multiply": 1, + "round": 1, + "rxPin": 14, + "txPin": 16, + "ABC": 1, + "int": 30 + }, + { + "name": "23. Рабочий диапазон от MHZ-19 UART", + "num": 23, + "type": "Reading", + "subtype": "Mhz19range", + "id": "Mhz19range", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "Диапазон", + "plus": 0, + "multiply": 1, + "round": 1, + "rxPin": 14, + "txPin": 16, + "range": 5000, + "ABC": 1, + "int": 30 + }, + { + "name": "24. Автокалибровка от MHZ-19 UART", + "num": 24, + "type": "Reading", + "subtype": "Mhz19ABC", + "id": "Mhz19ABC", + "widget": "anydataDef", + "page": "Сенсоры", + "descr": "ABC", + "rxPin": 14, + "txPin": 16, + "range": 5000, + "ABC": 1, + "int": 30 + }, { "header": "Экраны" }, { - "name": "18. LCD экран 2004", - "num": 18, + "name": "25. LCD экран 2004", + "num": 25, "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -247,8 +367,8 @@ "id2show": "id датчика" }, { - "name": "19. LCD экран 1602", - "num": 19, + "name": "26. LCD экран 1602", + "num": 26, "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -265,8 +385,8 @@ "header": "Расширения" }, { - "name": "20. Доп. функции системы", - "num": 20, + "name": "27. Доп. функции системы", + "num": 27, "type": "Reading", "subtype": "SysExt", "id": "SysExt", @@ -276,8 +396,8 @@ "int": 15 }, { - "name": "21. Датчик напряжения ADS1115", - "num": 21, + "name": "28. Датчик напряжения ADS1115", + "num": 28, "type": "Reading", "subtype": "Ads1115", "id": "Ads3", @@ -295,8 +415,8 @@ "int": 10 }, { - "name": "22. Расширитель портов Mcp23017", - "num": 22, + "name": "29. Расширитель портов Mcp23017", + "num": 29, "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -309,8 +429,8 @@ "index": 1 }, { - "name": "23. Переменная", - "num": 23, + "name": "30. Переменная", + "num": 30, "type": "Reading", "subtype": "Variable", "id": "var", @@ -325,8 +445,8 @@ "header": "Исполнительные устройства" }, { - "name": "24. Кнопка управляющая пином (Реле с кнопкой)", - "num": 24, + "name": "31. Кнопка управляющая пином (Реле с кнопкой)", + "num": 31, "type": "Writing", "subtype": "ButtonOut", "id": "btn", diff --git a/platformio.ini b/platformio.ini index 25a94fd4..54224f82 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,6 +39,7 @@ lib_deps = https://github.com/JonasGMorsch/GY-21.git adafruit/Adafruit ADS1X15 @ ^2.3.0 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + Nova Fitness Sds dust sensors library@1.5.1 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -62,6 +63,7 @@ lib_deps = https://github.com/JonasGMorsch/GY-21.git adafruit/Adafruit ADS1X15 @ ^2.3.0 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + Nova Fitness Sds dust sensors library@1.5.1 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 diff --git a/src/modules/API.cpp b/src/modules/API.cpp index df878315..b08d148d 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -17,6 +17,8 @@ void* getAPI_Ads1115(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params); void* getAPI_ButtonOut(String subtype, String params); void* getAPI_Variable(String subtype, String params); +void* getAPI_Sds011(String subtype, String params); +void* getAPI_Mhz19(String subtype, String params); //============================================================================================ void* getAPI(String subtype, String params) { @@ -38,6 +40,8 @@ void* getAPI(String subtype, String params) { if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; + if ((tmpAPI = getAPI_Sds011(subtype, params)) != nullptr) return tmpAPI; + if ((tmpAPI = getAPI_Mhz19(subtype, params)) != nullptr) return tmpAPI; //================================================================================================================ return nullptr; diff --git a/src/modules/Mhz19.cpp b/src/modules/Mhz19.cpp new file mode 100644 index 00000000..5fa92ae1 --- /dev/null +++ b/src/modules/Mhz19.cpp @@ -0,0 +1,689 @@ +/****************************************************************** + Support for MHZ19 + + adapted for version 4 @cmche + ******************************************************************/ +#include "Global.h" +#include "classes/IoTItem.h" +#include + +extern IoTGpio IoTgpio; + +int rxPinCO2 = 14; // D5 // зеленый провод сенсора к D2 / 4 +int txPinCO2 = 16; // D0 // синий провод сенсора к D1/5 +SoftwareSerial swSerialCO2(rxPinCO2, txPinCO2); // RX, TX// ESP8266 D7 / D6 Blue/Green + +int MHZ19_request(int request); + +void MHZ19uart_init(); + +bool MHZ19uart_flag = true; +// int MHZ19C_PREHEATING_TIME = 2 * 60 * 1000;// покажет реальные данные после прогрева, через 2 мин. +int MHZ19C_PREHEATING_TIME = 2 * 30 * 1000; // покажет реальные данные после прогрева, через 2 мин. + +//int prevTemperature = 0; +int temperature = 0; +bool temperatureUpdated = false; +int prevRange = 5000; +int range = 5000; // по умолнчанию стоит шкала 5000 (не 2000 как в мануале) +bool rangeChaged = false; +int prevABC = 1; +int ABC = 1; +bool ABCchanged = false; + + +//Это файл сенсора, в нем осуществляется чтение сенсора. + +class Mhz19uart : public IoTItem +{ +private: + //======================================================================================================= + // Секция переменных. + +public: + //======================================================================================================= + + Mhz19uart(String parameters) : IoTItem(parameters) + { + rxPinCO2 = jsonReadInt(parameters, "rxPin"); + txPinCO2 = jsonReadInt(parameters, "txPin"); + range = jsonReadInt(parameters, "range"); + ABC = jsonReadInt(parameters, "ABC"); + } + //======================================================================================================= + // doByInterval() + + void doByInterval() + { + MHZ19uart_init(); + if (millis() > MHZ19C_PREHEATING_TIME) + { + Serial.println("Start checkUARTCO2"); + value.valD = MHZ19_request(1); + } + regEvent(value.valD, "Mhz19uart"); //обязательный вызов хотяб один + } + //======================================================================================================= + + ~Mhz19uart() {}; +}; + +//после замены названия сенсора, на функцию можно не обращать внимания +//если сенсор предполагает использование общего объекта библиотеки для нескольких экземпляров сенсора, то в данной функции необходимо предусмотреть +//создание и контроль соответствующих глобальных переменных + +class Mhz19pwm : public IoTItem +{ +private: + //======================================================================================================= + // Секция переменных. + int pwmPin; ///// желтый провод сенсора к D8 (14-D5 ok) + +public: + //======================================================================================================= + + Mhz19pwm(String parameters) : IoTItem(parameters) + { + pwmPin = jsonReadInt(parameters, "pin"); + } + //======================================================================================================= + + void doByInterval() + { + MHZ19pwm_init(); + if (millis() > MHZ19C_PREHEATING_TIME) // + { + Serial.println("Start checkPWM_CO2"); + value.valD = MHZ19pwm_request(); + } + regEvent(value.valD, "Mhz19pwm"); //обязательный вызов хотяб один + } + //======================================================================================================= + + void MHZ19pwm_init() + { + static bool MHZ19pwm_flag = true; + if (MHZ19pwm_flag) + { + pinMode(pwmPin, INPUT); + MHZ19pwm_flag = false; + } + } + + int MHZ19pwm_request() + { + int reply; + Serial.println("Запрос замера по PWM запущен"); + unsigned long th, tl, ppm = 0, ppm2 = 0, ppm3 = 0; + do + { + th = pulseIn(pwmPin, HIGH, 1004000) / 1000; + tl = 1004 - th; + ppm2 = 2000 * (th - 2) / (th + tl - 4); // расчёт для диапазона от 0 до 2000ppm + ppm3 = 5000 * (th - 2) / (th + tl - 4); // расчёт для диапазона от 0 до 5000ppm + } while (th == 0); + + // Serial.print(th); + // Serial.println(" <- Milliseconds PWM is HIGH"); + + if (range == 2000) + { + reply = ppm2; + Serial.print(ppm2); + Serial.println(" <- ppm2 (PWM) with 2000ppm as limit"); + } + else + { + reply = ppm3; + Serial.print(ppm3); + Serial.println(" <- ppm3 (PWM) with 5000ppm as limit"); + } + Serial.println("Completed checkPwmCO2"); + return reply; + } + + ~Mhz19pwm() {}; +}; + +//====================TEMP=================================================================================== + +class Mhz19temp : public IoTItem +{ +private: + //======================================================================================================= + // Секция переменных. +public: + //====================TEMP=================================================================================== + + Mhz19temp(String parameters) : IoTItem(parameters) + { + rxPinCO2 = jsonReadInt(parameters, "rxPin"); + txPinCO2 = jsonReadInt(parameters, "txPin"); + range = jsonReadInt(parameters, "range"); + ABC = jsonReadInt(parameters, "ABC"); + } + //======================================================================================================= + + void doByInterval() + { + // Serial.println("Start Mhz19temp doByInterval"); + if (temperatureUpdated) + { + value.valD = temperature; + temperatureUpdated = false; + } + else + { + MHZ19uart_init(); + Serial.println("Start temperature request"); + if (MHZ19_request(13)) + { + value.valD = temperature; + }; // change + } + regEvent(value.valD, "Mhz19temp"); //обязательный вызов хотяб один + } + //======================================================================================================= + + //======================================================================================================= + + ~Mhz19temp() {}; +}; + +//=======================Range================ +class Mhz19range : public IoTItem +{ + +private: +public: + Mhz19range(String parameters) : IoTItem(parameters) + { + rxPinCO2 = jsonReadInt(parameters, "rxPin"); + txPinCO2 = jsonReadInt(parameters, "txPin"); + range = jsonReadInt(parameters, "range"); + ABC = jsonReadInt(parameters, "ABC"); + } + + void doByInterval() + { + if (range != prevRange) + { + MHZ19uart_init(); + Serial.println("Start change range"); + + if (range == 2000) + { + if (MHZ19_request(9)) + { + prevRange = 2000; + value.valD = 2000; + } // change range to 2000 + } + else + { + if (MHZ19_request(10)) + { + prevRange = 5000; + value.valD = 5000; + } // change range to 5000 + } + } + else + { + value.valD = prevRange; + } + regEvent(value.valD, "Mhz19range"); //обязательный вызов хотяб один + } + + ~Mhz19range() {}; +}; + +//===================ABC================= + +class Mhz19ABC : public IoTItem +{ + +private: +public: + Mhz19ABC(String parameters) : IoTItem(parameters) + { + rxPinCO2 = jsonReadInt(parameters, "rxPin"); + txPinCO2 = jsonReadInt(parameters, "txPin"); + range = jsonReadInt(parameters, "range"); + ABC = jsonReadInt(parameters, "ABC"); + } + + void doByInterval() + { + if (ABC != prevABC) + { + if (ABC == 1) + { + if (MHZ19_request(7)) + { + prevABC = 1; + value.valD = 1; + } // change ABC to 1 + } + else + { + if (MHZ19_request(8)) + { + prevABC = 0; + value.valD = 0; + } // change ABC to 0 + } + } + else + { + value.valD = prevABC; + } + regEvent(value.valD, "Mhz19ABC"); //обязательный вызов хотяб один + } + + ~Mhz19ABC() {}; +}; + +///============== end of classes========================== + +void *getAPI_Mhz19(String subtype, String param) +{ + + if (subtype == F("Mhz19uart")) + { + return new Mhz19uart(param); + } + else if (subtype == F("Mhz19pwm")) + { + return new Mhz19pwm(param); + } + else if (subtype == F("Mhz19temp")) + { + return new Mhz19temp(param); + } + else if (subtype == F("Mhz19range")) + { + return new Mhz19range(param); + } + else if (subtype == F("Mhz19ABC")) + { + return new Mhz19ABC(param); + } + else + { + return nullptr; + } +} + +void MHZ19uart_init() +{ + + if (MHZ19uart_flag) + { + int reply; + swSerialCO2.begin(9600); + + delay(50); + + reply = MHZ19_request(2); // show range, for test of uart only + Serial.print("show range reply = "); + Serial.println(reply); + + if (reply) + { + MHZ19uart_flag = false; + } + + } + + if (!MHZ19uart_flag) + { + static int prevABC; + int reply; + + if (ABC != prevABC) + { + if (ABC) + { + reply = MHZ19_request(7); // ABC on + } + else + { + reply = MHZ19_request(8); // ABC off + } + Serial.print("ABC change reply = "); + Serial.println(reply); + } + if (reply) + { + prevABC = ABC; + } + } + + static bool MHZ19_range_flag = true; + if (MHZ19_range_flag && !MHZ19uart_flag && (millis() > 30 * 1000)) + { + int reply; + if (range == 2000) + { + reply = MHZ19_request(9); // Установка шкалы 0-2000 + // 255 155 0 0 7 208 0 3 139 + } + else + { + reply = MHZ19_request(10); // Установка шкалы 0-5000 + // 255 155 0 0 19 136 0 3 199 + } + Serial.print("Scale change reply = "); + Serial.println(reply); + if (reply) + { + reply = MHZ19_request(2); // show range + Serial.print("show range reply = "); + Serial.println(reply); + + MHZ19_range_flag = false; + } + } +} + +int MHZ19_request(int request) +{ + int reply; + Serial.print("prevRange = "); + Serial.println(prevRange); + + byte uartReqSamplePpm[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; // PPM + // 255 1 134 0 0 0 0 0 121 +// Response 255 134 1 148 67 0 0 0 162 + + byte uartReqSampleABCon[9] = {0xFF, 0x01, 0x79, 0xA0, 0x00, 0x00, 0x00, 0x00, 0xE6}; // ABC logic on + // 255 1 121 160 0 0 0 0 230 +//Response 255 121 1 0 0 0 0 0 134 + byte uartReqSampleABCoff[9] = {0xFF, 0x01, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86}; // ABC logic off + byte uartReqSampleABCstatus[9] = {0xFF, 0x01, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82}; // ABC logic status + + byte uartReqSample1000Range[9] = {0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x03, 0xE8, 0x7B}; + byte uartReqSample2000Range[9] = {0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x8F}; // задаёт диапазон 0 - 2000ppm + byte uartReqSample3000Range[9] = {0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x0B, 0xB8, 0xA3}; // задаёт диапазон 0 - 2000ppm + + byte uartReqSample5000Range[9] = {0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x13, 0x88, 0xCB}; // задаёт диапазон 0 - 5000ppm +// 255 1 153 0 0 0 19 136 203 +// Response 255 153 1 0 0 0 0 0 102 + byte uartReqSampleRequestRange[9] = {0xFF, 0x01, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64}; // запрос диапазона + // request // 255 1 155 0 0 0 0 0 100 + //reply // 255 1 155 0 0 0 0 0 100 + byte uartReqSampleZeroPnt[9] = {0xFF, 0x01, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78}; // !!ZERO POINT CALIBRATION + byte uartReqSampleReset[9] = {0xFF, 0x01, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72}; // reset + + byte uartReqSampleReset1[9] = {0xFF, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87}; // reset - did not work out + + byte request_cmd[9]; + // byte c; + switch (request) + { + // случаи 3-7 для перезапуска сенсора + case 1: + { + Serial.println("Запрос No.1 - отправлен. Запрос замера по UART"); + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSamplePpm[i]; + } + } + break; + + case 2: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSampleRequestRange[i]; + } + Serial.println("Запрос No.2 - отправлен. Запрос шкалы"); + } + break; + + case 3: + { + // код для запуска сенсора с работой по UART (запуск таймера) + Serial.println("Запрос No.3 - отправлен. Сенсор по UART запущен"); + } + break; + case 4: + { + // код для остановке сенсора с работой по UART (остановка таймера) + Serial.println("Запрос No.4 - отправлен. Сенсор по UART остановлен"); + } + break; + case 5: + { + // код для запуска сенсора с работой по PWM (запуск таймера) + Serial.println("Запрос No.5 - отправлен. Сенсор по PWM запущен"); + } + break; + case 6: + { + // код для остановки сенсора с работой по PWM (остановка таймера) + Serial.println("Запрос No.6 - отправлен. Сенсор по PWM остановлен"); + } + break; + case 7: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSampleABCon[i]; + } + Serial.println("Запрос No.7 - отправлен. Включаем функцию атокалибровки"); + } + break; + case 8: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSampleABCoff[i]; + } + Serial.println("Запрос No.8 - отправлен. Выключаем функцию атокалибровки"); + } + break; + case 9: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSample2000Range[i]; + } + Serial.println("Запрос No.9 - отправлен. Установливаем шкалу 0-2000"); + } + break; + case 10: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSample5000Range[i]; + } + Serial.println("Запрос No.10 - отправлен. Установливаем шкалу 0-5000"); + } + break; + case 11: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSampleZeroPnt[i]; + } + Serial.println("Запрос No.11 - отправлен. Калибровка. Установливаем нулевой уровень"); + } + break; + case 12: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSampleReset1[i]; + } + Serial.println("Запрос No.11 - отправлен. Запрос на Сброс"); + } + break; + case 13: + { + for (int i = 0; i < 9; i++) + { + request_cmd[i] = uartReqSamplePpm[i]; + } + Serial.println("Запрос No.13 - отправлен. Запрос по Температуре"); + } + break; + default: + // byte c = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; + // if nothing else matches, do the default + // default is optional + break; + } + + swSerialCO2.write(request_cmd, 9); + + Serial.print("Request : "); + for (int i = 0; i < 9; i++) + { + Serial.print(" "); + Serial.print(request_cmd[i]); + } + Serial.println(" "); + + delay(50); + + unsigned char response[9]; + + Serial.print("Response :"); + swSerialCO2.readBytes(response, 9); + + for (int i = 0; i < 9; i++) + { + Serial.print(" "); + Serial.print(response[i]); + } + Serial.println(" "); + + byte crc = 0; + for (int i = 1; i < 8; i++) crc += response[i]; + crc = 255 - crc; + crc += 1; + + if (!(response[0] == 0xFF && response[8] == crc)) + { + Serial.println("Range CRC error: " + String(crc) + " / " + String(response[8])); + reply = 0; + } + else + { + // Serial.println("No CRC errors"); + switch (request) + { + + case 1: + { + unsigned int responseHigh = (unsigned int)response[2]; + unsigned int responseLow = (unsigned int)response[3]; + unsigned int ppm = (256*responseHigh) + responseLow; + + Serial.print("CO2 UART = "); + Serial.println(ppm); + + temperature = response[4] - 44; // - 40; + Serial.print("Temperature = "); + Serial.println(temperature); + temperatureUpdated = true; + + reply = ppm; + } + break; + + case 2: + { + reply = 1; + Serial.println("Case 2 - OK. На запрос шкалы пришел ответ"); + } + break; + case 3: + { + // Serial.println("Case 3 - OK"); + reply = 1; + } + break; + case 4: + { + // Serial.println("Case 4 - OK"); + reply = 1; + } + break; + case 5: + { + // Serial.println("Case 5 - OK"); + reply = 1; + } + break; + case 6: + { + Serial.println("Case 6 - OK"); + reply = 1; + } + break; + case 7: + { + Serial.println("Case 7 - OK. ABC включен"); + reply = 1; + } + break; + case 8: + { + Serial.println("Case 8 - OK. ABC выключен"); + reply = 1; + } + break; + case 9: + { + Serial.println("Case 9 - OK. Установлена шкала 0-2000"); + reply = 1; + prevRange = 2000; + } + break; + case 10: + { + Serial.println("Case 9 - OK. Установлена шкала 0-5000"); + reply = 1; + prevRange = 5000; + } + break; + case 11: + { + reply = 1; + Serial.println("Запрос No.11 - сработал. Калибровка. Установлен нулевой уровень"); + } + break; + + case 12: + { + reply = 1; + Serial.println("Запрос No.12 - сработал. Сброс произошел"); + } + break; + + case 13: + { + reply = 1; + temperature = response[4] - 44; // - 40; + + Serial.println("Запрос No.12 - сработал. Температура получена"); + Serial.println(temperature); + } + break; + + default: + // byte c = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79}; + // if nothing else matches, do the default + // default is optional + + break; + } + } + // Serial.print("reply = "); + // Serial.println(reply); + return reply; +} diff --git a/src/modules/Sds011.cpp b/src/modules/Sds011.cpp new file mode 100644 index 00000000..b230312a --- /dev/null +++ b/src/modules/Sds011.cpp @@ -0,0 +1,209 @@ +/****************************************************************** + Supports Sds011, implements whole Laser Dust Sensor Control Protocol V1.3, + should also work with other Sds sensors. + + https://github.com/lewapek/sds-dust-sensors-arduino-library + + adapted for version 4 @cmche + ******************************************************************/ + +#include "Global.h" +#include "classes/IoTItem.h" + +extern IoTGpio IoTgpio; + +#include "SdsDustSensor.h" + +int rxPinSDS = 13; // D7 – подключаем к Tx сенсора +int txPinSDS = 12; // D6 – подключаем к Rx сенсора +SdsDustSensor sds(rxPinSDS, txPinSDS); + +unsigned int warmUp; +unsigned int period; + +bool SDS011_init_flag = true; +void SDS011_init(); +float Sds011request(int sensorID); + +//Это файл сенсора, в нем осуществляется чтение сенсора. +//для добавления сенсора вам нужно скопировать этот файл и заменить в нем текст AnalogAdc на название вашего сенсора +//Название должно быть уникальным, коротким и отражать суть сенсора. + +class Sds011_25 : public IoTItem +{ +private: + //======================================================================================================= + // Секция переменных. + //Это секция где Вы можете объявлять переменные и объекты arduino библиотек, что бы + //впоследствии использовать их в loop и setup + // unsigned int _pin; + +public: + //======================================================================================================= + // setup() + //это аналог setup из arduino. Здесь вы можете выполнять методы инициализации сенсора. + //Такие как ...begin и подставлять в них параметры полученные из web интерфейса. + //Все параметры хранятся в перемененной parameters, вы можете прочитать любой параметр используя jsonRead функции: + // jsonReadStr, jsonReadBool, jsonReadInt + Sds011_25(String parameters) : IoTItem(parameters) + { + // _pin = jsonReadInt(parameters, "pin"); + rxPinSDS = jsonReadInt(parameters, "rxPin"); + txPinSDS = jsonReadInt(parameters, "txPin"); + warmUp = jsonReadInt(parameters, "warmUp"); // сек. пробужнение должен быть больше + period = jsonReadInt(parameters, "period"); // сек. время зарогрева/продувки, затем идут замеры + } + //======================================================================================================= + // doByInterval() + //это аналог loop из arduino, но вызываемый каждые int секунд, заданные в настройках. Здесь вы должны выполнить чтение вашего сенсора + //а затем выполнить regEvent - это регистрация произошедшего события чтения + //здесь так же доступны все переменные из секции переменных, и полученные в setup + //если у сенсора несколько величин то делайте несколько regEvent + //не используйте delay - помните, что данный loop общий для всех модулей. Если у вас планируется длительная операция, постарайтесь разбить ее на порции + //и выполнить за несколько тактов + void doByInterval() + { + SDS011_init(); + Serial.println("request from 25"); + value.valD = Sds011request(25); + + regEvent(value.valD, "Sds011_25"); //обязательный вызов хотяб один + } + + ~Sds011_25() {}; +}; + +//////////////////////////////////// for PM 10//= + +class Sds011_10 : public IoTItem +{ +private: + //======================================================================================================= + // Секция переменных. + //Это секция где Вы можете объявлять переменные и объекты arduino библиотек, что бы + //впоследствии использовать их в loop и setup + +public: + //======================================================================================================= + // setup() + //это аналог setup из arduino. Здесь вы можете выполнять методы инициализации сенсора. + //Такие как ...begin и подставлять в них параметры полученные из web интерфейса. + //Все параметры хранятся в перемененной parameters, вы можете прочитать любой параметр используя jsonRead функции: + // jsonReadStr, jsonReadBool, jsonReadInt + Sds011_10(String parameters) : IoTItem(parameters) + { + // _pin = jsonReadInt(parameters, "pin"); + rxPinSDS = jsonReadInt(parameters, "rxPin"); + txPinSDS = jsonReadInt(parameters, "txPin"); + warmUp = jsonReadInt(parameters, "warmUp"); // сек. пробужнение должен быть больше + period = jsonReadInt(parameters, "period"); // сек. время зарогрева/продувки, затем идут замеры + } + //======================================================================================================= + // doByInterval() + //это аналог loop из arduino, но вызываемый каждые int секунд, заданные в настройках. Здесь вы должны выполнить чтение вашего сенсора + //а затем выполнить regEvent - это регистрация произошедшего события чтения + //здесь так же доступны все переменные из секции переменных, и полученные в setup + //если у сенсора несколько величин то делайте несколько regEvent + //не используйте delay - помните, что данный loop общий для всех модулей. Если у вас планируется длительная операция, постарайтесь разбить ее на порции + //и выполнить за несколько тактов + + void doByInterval() + { + SDS011_init(); + Serial.println("request from 10"); + value.valD = Sds011request(10); + + regEvent(value.valD, "Sds011_10"); //обязательный вызов хотяб один + } + ~Sds011_10() {}; +}; + +//после замены названия сенсора, на функцию можно не обращать внимания +//если сенсор предполагает использование общего объекта библиотеки для нескольких экземпляров сенсора, то в данной функции необходимо предусмотреть +//создание и контроль соответствующих глобальных переменных +void *getAPI_Sds011(String subtype, String param) +{ + if (subtype == F("Sds011_25")) + { + return new Sds011_25(param); + } + else if (subtype == F("Sds011_10")) + { + return new Sds011_10(param); + } + else + { + return nullptr; + } +} + +float Sds011request(int sensorID) +{ + float reply = 0; + static int a = 0; + static float pm25 = 0; + static float pm10 = 0; + static int startMillis = millis(); + + if (a == 0) + { + Serial.print("SDS011 ... warmUp = "); + Serial.print(warmUp); + Serial.print(" period = "); + Serial.println(period); + sds.wakeup(); + startMillis = millis(); + a = a + 1; + } + if (a == 1 && millis() >= (startMillis + warmUp * 1000)) + { + PmResult pm = sds.readPm(); + if (pm.isOk()) + { + pm25 = pm.pm25; + pm10 = pm.pm10; + Serial.print("PM2.5 = "); + Serial.print(pm25); + Serial.print(" PM10 = "); + Serial.println(pm10); + a = a + 1; + sds.sleep(); + } + else + { + Serial.print("Could not read values from sensor 25, reason: "); + Serial.println(pm.statusToString()); + a = a + 1; + } + } + if (a > 1 && millis() >= (startMillis + period * 1000)) + { + Serial.println("end of period for pm25"); + a = 0; + } + if (sensorID == 25) + { + reply = pm25; + } + if (sensorID == 10) + { + reply = pm10; + } + return reply; +} + +void SDS011_init() +{ + if (SDS011_init_flag) + { + sds.begin(); + Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version + // Serial.println(sds.setActiveReportingMode().toString()); // + String ReportingMode = sds.setActiveReportingMode().toString(); + Serial.println(ReportingMode); + if (ReportingMode == "Mode: active") + { + SDS011_init_flag = false; + } + } +} From c453a986852da4ef02f75cbfe91d7e3981174fcd Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 7 Mar 2022 11:56:09 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9C=D0=B5=D0=BD=D1=8F=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=83=20FS=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=D0=B9=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=BA=D1=80=D0=B8=D0=BF=D1=82=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=D0=B9=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B8=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B2=20=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=B8=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accembleItems.py | 72 +++ data_svelte/items.json | 511 +++++++++--------- platformio.ini | 98 ++-- .../{ => exec/ButtonOut}/ButtonOut.cpp | 0 src/modules/exec/ButtonOut/items.json | 16 + src/modules/exec/items.json | 5 + src/modules/items.json | 6 + src/modules/{ => lcd/Lcd2004}/Lcd2004.cpp | 0 src/modules/lcd/Lcd2004/items.json | 32 ++ src/modules/lcd/Lcd2004/platformio.ini | 7 + src/modules/lcd/items.json | 5 + src/modules/{ => sensors/Ads1115}/Ads1115.cpp | 0 src/modules/sensors/Ads1115/items.json | 21 + src/modules/sensors/Ads1115/platformio.ini | 7 + src/modules/{ => sensors/Aht20}/Aht20.cpp | 0 src/modules/sensors/Aht20/items.json | 27 + src/modules/sensors/Aht20/platformio.ini | 7 + .../{ => sensors/AnalogAdc}/AnalogAdc.cpp | 0 src/modules/sensors/AnalogAdc/items.json | 18 + src/modules/{ => sensors/Bme280}/Bme280.cpp | 0 src/modules/sensors/Bme280/items.json | 41 ++ src/modules/sensors/Bme280/platformio.ini | 8 + src/modules/{ => sensors/Bmp280}/Bmp280.cpp | 0 src/modules/sensors/Bmp280/items.json | 28 + src/modules/sensors/Bmp280/platformio.ini | 8 + src/modules/{ => sensors/Dht1122}/Dht1122.cpp | 0 src/modules/sensors/Dht1122/items.json | 28 + src/modules/sensors/Dht1122/platformio.ini | 7 + src/modules/{ => sensors/Ds18b20}/Ds18b20.cpp | 0 src/modules/sensors/Ds18b20/items.json | 17 + src/modules/sensors/Ds18b20/platformio.ini | 8 + src/modules/{ => sensors/GY-21}/GY-21.cpp | 0 src/modules/sensors/GY-21/items.json | 26 + src/modules/sensors/GY-21/platformio.ini | 8 + src/modules/{ => sensors/Hdc1080}/Hdc1080.cpp | 0 src/modules/sensors/Hdc1080/items.json | 28 + src/modules/sensors/Hdc1080/platformio.ini | 7 + src/modules/{ => sensors/Mhz19}/Mhz19.cpp | 0 src/modules/sensors/Mhz19/items.json | 86 +++ src/modules/{ => sensors/Sds011}/Sds011.cpp | 0 src/modules/sensors/Sds011/items.json | 38 ++ src/modules/sensors/Sds011/platformio.ini | 7 + src/modules/{ => sensors/Sht20}/Sht20.cpp | 0 src/modules/sensors/Sht20/items.json | 26 + src/modules/sensors/Sht20/platformio.ini | 7 + src/modules/sensors/items.json | 5 + .../{ => system/Mcp23017}/Mcp23017.cpp | 0 src/modules/system/Mcp23017/items.json | 16 + src/modules/system/Mcp23017/platformio.ini | 8 + src/modules/{ => system/SysExt}/SysExt.cpp | 0 src/modules/system/SysExt/items.json | 13 + .../{ => system/Variable}/Variable.cpp | 0 src/modules/system/Variable/items.json | 15 + src/modules/system/items.json | 5 + 54 files changed, 964 insertions(+), 308 deletions(-) create mode 100644 accembleItems.py rename src/modules/{ => exec/ButtonOut}/ButtonOut.cpp (100%) create mode 100644 src/modules/exec/ButtonOut/items.json create mode 100644 src/modules/exec/items.json create mode 100644 src/modules/items.json rename src/modules/{ => lcd/Lcd2004}/Lcd2004.cpp (100%) create mode 100644 src/modules/lcd/Lcd2004/items.json create mode 100644 src/modules/lcd/Lcd2004/platformio.ini create mode 100644 src/modules/lcd/items.json rename src/modules/{ => sensors/Ads1115}/Ads1115.cpp (100%) create mode 100644 src/modules/sensors/Ads1115/items.json create mode 100644 src/modules/sensors/Ads1115/platformio.ini rename src/modules/{ => sensors/Aht20}/Aht20.cpp (100%) create mode 100644 src/modules/sensors/Aht20/items.json create mode 100644 src/modules/sensors/Aht20/platformio.ini rename src/modules/{ => sensors/AnalogAdc}/AnalogAdc.cpp (100%) create mode 100644 src/modules/sensors/AnalogAdc/items.json rename src/modules/{ => sensors/Bme280}/Bme280.cpp (100%) create mode 100644 src/modules/sensors/Bme280/items.json create mode 100644 src/modules/sensors/Bme280/platformio.ini rename src/modules/{ => sensors/Bmp280}/Bmp280.cpp (100%) create mode 100644 src/modules/sensors/Bmp280/items.json create mode 100644 src/modules/sensors/Bmp280/platformio.ini rename src/modules/{ => sensors/Dht1122}/Dht1122.cpp (100%) create mode 100644 src/modules/sensors/Dht1122/items.json create mode 100644 src/modules/sensors/Dht1122/platformio.ini rename src/modules/{ => sensors/Ds18b20}/Ds18b20.cpp (100%) create mode 100644 src/modules/sensors/Ds18b20/items.json create mode 100644 src/modules/sensors/Ds18b20/platformio.ini rename src/modules/{ => sensors/GY-21}/GY-21.cpp (100%) create mode 100644 src/modules/sensors/GY-21/items.json create mode 100644 src/modules/sensors/GY-21/platformio.ini rename src/modules/{ => sensors/Hdc1080}/Hdc1080.cpp (100%) create mode 100644 src/modules/sensors/Hdc1080/items.json create mode 100644 src/modules/sensors/Hdc1080/platformio.ini rename src/modules/{ => sensors/Mhz19}/Mhz19.cpp (100%) create mode 100644 src/modules/sensors/Mhz19/items.json rename src/modules/{ => sensors/Sds011}/Sds011.cpp (100%) create mode 100644 src/modules/sensors/Sds011/items.json create mode 100644 src/modules/sensors/Sds011/platformio.ini rename src/modules/{ => sensors/Sht20}/Sht20.cpp (100%) create mode 100644 src/modules/sensors/Sht20/items.json create mode 100644 src/modules/sensors/Sht20/platformio.ini create mode 100644 src/modules/sensors/items.json rename src/modules/{ => system/Mcp23017}/Mcp23017.cpp (100%) create mode 100644 src/modules/system/Mcp23017/items.json create mode 100644 src/modules/system/Mcp23017/platformio.ini rename src/modules/{ => system/SysExt}/SysExt.cpp (100%) create mode 100644 src/modules/system/SysExt/items.json rename src/modules/{ => system/Variable}/Variable.cpp (100%) create mode 100644 src/modules/system/Variable/items.json create mode 100644 src/modules/system/items.json diff --git a/accembleItems.py b/accembleItems.py new file mode 100644 index 00000000..6f19c5a7 --- /dev/null +++ b/accembleItems.py @@ -0,0 +1,72 @@ +import configparser +import os +import json, pprint + +config = configparser.ConfigParser() # создаём объекта парсера INI +allLibs_esp8266_4mb = "" +allLibs_esp32_4mb = "" +allMenuItems = json.loads('[]') +allMenuItemsCount = 1; + + +def getDirs(path): + for file in os.listdir(path): + if os.path.isdir(os.path.join(path, file)): + yield file + + +def getPIOLibs(patch): + global allLibs_esp8266_4mb, allLibs_esp32_4mb + for dir in getDirs(patch): + if (config.read(patch + dir + "/platformio.ini")): + print(patch + dir + "/platformio.ini") + allLibs_esp8266_4mb = allLibs_esp8266_4mb + config["env:esp8266_4mb"]["lib_deps"] + allLibs_esp32_4mb = allLibs_esp32_4mb + config["env:esp32_4mb"]["lib_deps"] + + +def getMenuItems(patch): + global allMenuItems, allMenuItemsCount + with open(patch + "items.json", "r") as read_file: + allMenuItems = allMenuItems + json.load(read_file) + + for dir in getDirs(patch): + with open(patch + dir + "/items.json", "r") as read_file: + print(patch + dir + "/items.json") + data = json.load(read_file) + for item in data: + item["name"] = str(allMenuItemsCount) + ". " + item["name"] + item["num"] = allMenuItemsCount + allMenuItemsCount = allMenuItemsCount + 1 + allMenuItems = allMenuItems + data + + + +# читаем и запоминаем все либы мз каждого модуля +getPIOLibs("src/modules/system/") +getPIOLibs("src/modules/exec/") +getPIOLibs("src/modules/sensors/") +getPIOLibs("src/modules/lcd/") + + +# сохраняем собранные либы в настройках PIO +config.read("platformio.ini") +config["env:esp8266_4mb_fromitems"]["lib_deps"] = allLibs_esp8266_4mb +config["env:esp32_4mb_fromitems"]["lib_deps"] = allLibs_esp32_4mb +with open("platformio.ini", 'w') as configfile: + config.write(configfile) + + + +# готовим первый элемент меню +with open("src/modules/items.json", "r") as read_file: + allMenuItems = allMenuItems + json.load(read_file) + +# читаем и запоминаем пункты меню модуелей +getMenuItems("src/modules/system/") +getMenuItems("src/modules/exec/") +getMenuItems("src/modules/sensors/") +getMenuItems("src/modules/lcd/") + +# сохраняем пункты меню в общий файл +with open('data_svelte/items.json', 'w') as f: + json.dump(allMenuItems, f, ensure_ascii=False, indent=4, sort_keys=False) \ No newline at end of file diff --git a/data_svelte/items.json b/data_svelte/items.json index 52db34f6..d4989dad 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -3,12 +3,110 @@ "name": "Выберите элемент", "num": 0 }, + { + "header": "Расширения" + }, + { + "name": "1. Расширитель портов Mcp23017", + "num": 1, + "type": "Reading", + "subtype": "Mcp23017", + "id": "Mcp", + "widget": "", + "page": "", + "descr": "", + "int": "0", + "addr": "0x20", + "index": 1 + }, + { + "name": "2. Доп. функции системы", + "num": 2, + "type": "Reading", + "subtype": "SysExt", + "id": "SysExt", + "widget": "", + "page": "", + "descr": "", + "int": 15 + }, + { + "name": "3. Переменная", + "num": 3, + "type": "Reading", + "subtype": "Variable", + "id": "var", + "widget": "", + "page": "", + "descr": "", + "int": "0", + "val": "0" + }, + { + "header": "Модули управления" + }, + { + "name": "4. Кнопка управляющая пином (Реле с кнопкой)", + "num": 4, + "type": "Writing", + "subtype": "ButtonOut", + "id": "btn", + "widget": "toggle", + "page": "Кнопки", + "descr": "", + "int": 0, + "inv": 0, + "pin": 2 + }, { "header": "Сенсоры" }, { - "name": "1. Аналоговый сенсор", - "num": 1, + "name": "5. Датчик напряжения ADS1115", + "num": 5, + "type": "Reading", + "subtype": "Ads1115", + "id": "Ads3", + "widget": "anydataVlt", + "page": "Сенсоры", + "descr": "ADS_3", + "pin": "0", + "mode": "volt", + "gain": "3/4x", + "plus": 0, + "multiply": 1, + "round": 100, + "int": 10 + }, + { + "name": "6. Cенсор температуры AHT20", + "num": 6, + "type": "Reading", + "subtype": "Aht20t", + "id": "Temp20", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "AHT20 Температура", + "int": 15, + "addr": "0x38", + "round": 1 + }, + { + "name": "7. Cенсор влажности AHT20", + "num": 7, + "type": "Reading", + "subtype": "Aht20h", + "id": "Hum20", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "AHT20 Влажность", + "int": 15, + "addr": "0x38", + "round": 1 + }, + { + "name": "8. Аналоговый сенсор", + "num": 8, "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -22,97 +120,6 @@ "pin": 0, "int": 15 }, - { - "name": "2. Cенсор температуры ds18b20", - "num": 2, - "type": "Reading", - "subtype": "Ds18b20", - "id": "dstmp", - "widget": "anydataTmp", - "page": "Сенсоры", - "descr": "DS Температура", - "int": 15, - "pin": 2, - "index": 0, - "addr": "", - "round": 1 - }, - { - "name": "3. Cенсор температуры Sht20", - "num": 3, - "type": "Reading", - "subtype": "Sht20t", - "id": "tmp2", - "widget": "anydataTmp", - "page": "Сенсоры", - "descr": "Температура", - "int": 15, - "round": 1 - }, - { - "name": "4. Cенсор влажности Sht20", - "num": 4, - "type": "Reading", - "subtype": "Sht20h", - "id": "Hum2", - "widget": "anydataHum", - "page": "Сенсоры", - "descr": "Влажность", - "int": 15, - "round": 1 - }, - { - "name": "5. Cенсор температуры dht11", - "num": 5, - "type": "Reading", - "subtype": "Dht1122t", - "id": "tmp3", - "widget": "anydataTmp", - "page": "Сенсоры", - "descr": "Температура", - "int": 15, - "pin": 0, - "senstype": "dht11" - }, - { - "name": "6. Cенсор влажности dht11", - "num": 6, - "type": "Reading", - "subtype": "Dht1122h", - "id": "Hum3", - "widget": "anydataHum", - "page": "Сенсоры", - "descr": "Влажность", - "int": 15, - "pin": 0, - "senstype": "dht11" - }, - { - "name": "7. Cенсор температуры Bmp280", - "num": 7, - "type": "Reading", - "subtype": "Bmp280t", - "id": "tmp3", - "widget": "anydataTmp", - "page": "Сенсоры", - "descr": "280 Температура", - "int": 15, - "addr": "0x77", - "round": 1 - }, - { - "name": "8. Cенсор давления Bmp280", - "num": 8, - "type": "Reading", - "subtype": "Bmp280p", - "id": "Press3", - "widget": "anydataMm", - "page": "Сенсоры", - "descr": "280 Давление", - "int": 15, - "addr": "0x77", - "round": 1 - }, { "name": "9. Cенсор температуры Bme280", "num": 9, @@ -153,35 +160,100 @@ "round": 1 }, { - "name": "12. Cенсор температуры AHT20", + "name": "12. Cенсор температуры Bmp280", "num": 12, "type": "Reading", - "subtype": "Aht20t", - "id": "Temp20", + "subtype": "Bmp280t", + "id": "tmp3", "widget": "anydataTmp", "page": "Сенсоры", - "descr": "AHT20 Температура", + "descr": "280 Температура", "int": 15, - "addr": "0x38", + "addr": "0x77", "round": 1 }, { - "name": "13. Cенсор влажности AHT20", + "name": "13. Cенсор давления Bmp280", "num": 13, "type": "Reading", - "subtype": "Aht20h", - "id": "Hum20", - "widget": "anydataHum", + "subtype": "Bmp280p", + "id": "Press3", + "widget": "anydataMm", "page": "Сенсоры", - "descr": "AHT20 Влажность", + "descr": "280 Давление", "int": 15, - "addr": "0x38", + "addr": "0x77", "round": 1 }, { - "name": "14. Cенсор температуры HDC1080", + "name": "14. Cенсор температуры dht11", "num": 14, "type": "Reading", + "subtype": "Dht1122t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "pin": 0, + "senstype": "dht11" + }, + { + "name": "15. Cенсор влажности dht11", + "num": 15, + "type": "Reading", + "subtype": "Dht1122h", + "id": "Hum3", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "pin": 0, + "senstype": "dht11" + }, + { + "name": "16. Cенсор температуры ds18b20", + "num": 16, + "type": "Reading", + "subtype": "Ds18b20", + "id": "dstmp", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "DS Температура", + "int": 15, + "pin": 2, + "index": 0, + "addr": "", + "round": 1 + }, + { + "name": "17. Cенсор температуры GY21", + "num": 17, + "type": "Reading", + "subtype": "GY21t", + "id": "tmp4", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "round": 1, + "int": 15 + }, + { + "name": "18. Cенсор влажности GY21", + "num": 18, + "type": "Reading", + "subtype": "GY21h", + "id": "Hum4", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "round": 1, + "int": 15 + }, + { + "name": "19. Cенсор температуры HDC1080", + "num": 19, + "type": "Reading", "subtype": "Hdc1080t", "id": "Temp1080", "widget": "anydataTmp", @@ -192,8 +264,8 @@ "round": 1 }, { - "name": "15. Cенсор влажности HDC1080", - "num": 15, + "name": "20. Cенсор влажности HDC1080", + "num": 20, "type": "Reading", "subtype": "Hdc1080h", "id": "Hum1080", @@ -205,68 +277,8 @@ "round": 1 }, { - "name": "16. Cенсор температуры GY21", - "num": 16, - "type": "Reading", - "subtype": "GY21t", - "id": "tmp4", - "widget": "anydataTmp", - "page": "Сенсоры", - "descr": "Температура", - "round": 1, - "int": 15 - }, - { - "name": "17. Cенсор влажности GY21", - "num": 17, - "type": "Reading", - "subtype": "GY21h", - "id": "Hum4", - "widget": "anydataHum", - "page": "Сенсоры", - "descr": "Влажность", - "round": 1, - "int": 15 - }, - { - "name": "18. Датчик пыли SDS011 PM25", - "num": 18, - "type": "Reading", - "subtype": "Sds011_25", - "id": "pmuart25", - "widget": "anydataPpm", - "page": "Сенсоры", - "descr": "PM-2.5", - "plus": 0, - "multiply": 1, - "round": 10, - "rxPin": 13, - "txPin": 12, - "int": 15, - "warmUp": 30, - "period": 300 - }, - { - "name": "19. Датчик пыли SDS011 PM10", - "num": 19, - "type": "Reading", - "subtype": "Sds011_10", - "id": "pmuart10", - "widget": "anydataPpm", - "page": "Сенсоры", - "descr": "PM-10", - "plus": 0, - "multiply": 1, - "round": 10, - "rxPin": 13, - "txPin": 12, - "int": 15, - "warmUp": 30, - "period": 300 - }, - { - "name": "20. Датчик CO2 MHZ-19 UART", - "num": 20, + "name": "21. Датчик CO2 MHZ-19 UART", + "num": 21, "type": "Reading", "subtype": "Mhz19uart", "id": "co2uart", @@ -284,8 +296,8 @@ "ABC": 1 }, { - "name": "21. Датчик CO2 MHZ-19 PWM", - "num": 21, + "name": "22. Датчик CO2 MHZ-19 PWM", + "num": 22, "type": "Reading", "subtype": "Mhz19pwm", "id": "co2pwm", @@ -299,8 +311,8 @@ "int": 300 }, { - "name": "22. Cенсор температуры от MHZ-19 UART", - "num": 22, + "name": "23. Cенсор температуры от MHZ-19 UART", + "num": 23, "type": "Reading", "subtype": "Mhz19temp", "id": "Mhz19temp", @@ -316,8 +328,8 @@ "int": 30 }, { - "name": "23. Рабочий диапазон от MHZ-19 UART", - "num": 23, + "name": "24. Рабочий диапазон от MHZ-19 UART", + "num": 24, "type": "Reading", "subtype": "Mhz19range", "id": "Mhz19range", @@ -334,8 +346,8 @@ "int": 30 }, { - "name": "24. Автокалибровка от MHZ-19 UART", - "num": 24, + "name": "25. Автокалибровка от MHZ-19 UART", + "num": 25, "type": "Reading", "subtype": "Mhz19ABC", "id": "Mhz19ABC", @@ -348,12 +360,72 @@ "ABC": 1, "int": 30 }, + { + "name": "26. Датчик пыли SDS011 PM25", + "num": 26, + "type": "Reading", + "subtype": "Sds011_25", + "id": "pmuart25", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "PM-2.5", + "plus": 0, + "multiply": 1, + "round": 10, + "rxPin": 13, + "txPin": 12, + "int": 15, + "warmUp": 30, + "period": 300 + }, + { + "name": "27. Датчик пыли SDS011 PM10", + "num": 27, + "type": "Reading", + "subtype": "Sds011_10", + "id": "pmuart10", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "PM-10", + "plus": 0, + "multiply": 1, + "round": 10, + "rxPin": 13, + "txPin": 12, + "int": 15, + "warmUp": 30, + "period": 300 + }, + { + "name": "28. Cенсор температуры Sht20", + "num": 28, + "type": "Reading", + "subtype": "Sht20t", + "id": "tmp2", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "round": 1 + }, + { + "name": "29. Cенсор влажности Sht20", + "num": 29, + "type": "Reading", + "subtype": "Sht20h", + "id": "Hum2", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "round": 1 + }, { "header": "Экраны" }, { - "name": "25. LCD экран 2004", - "num": 25, + "name": "30. LCD экран 2004", + "num": 30, "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -367,8 +439,8 @@ "id2show": "id датчика" }, { - "name": "26. LCD экран 1602", - "num": 26, + "name": "31. LCD экран 1602", + "num": 31, "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -380,82 +452,5 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика" - }, - { - "header": "Расширения" - }, - { - "name": "27. Доп. функции системы", - "num": 27, - "type": "Reading", - "subtype": "SysExt", - "id": "SysExt", - "widget": "", - "page": "", - "descr": "", - "int": 15 - }, - { - "name": "28. Датчик напряжения ADS1115", - "num": 28, - "type": "Reading", - "subtype": "Ads1115", - "id": "Ads3", - "widget": "anydataVlt", - "page": "Сенсоры", - "descr": "ADS_3", - - "pin": "0", - "mode": "volt", - "gain": "3/4x", - - "plus": 0, - "multiply": 1, - "round": 100, - "int": 10 - }, - { - "name": "29. Расширитель портов Mcp23017", - "num": 29, - "type": "Reading", - "subtype": "Mcp23017", - "id": "Mcp", - "widget": "", - "page": "", - "descr": "", - - "int": "0", - "addr": "0x20", - "index": 1 - }, - { - "name": "30. Переменная", - "num": 30, - "type": "Reading", - "subtype": "Variable", - "id": "var", - "widget": "", - "page": "", - "descr": "", - - "int": "0", - "val": "0" - }, - { - "header": "Исполнительные устройства" - }, - { - "name": "31. Кнопка управляющая пином (Реле с кнопкой)", - "num": 31, - "type": "Writing", - "subtype": "ButtonOut", - "id": "btn", - "widget": "toggle", - "page": "Кнопки", - "descr": "", - "int": 0, - - "inv": 0, - "pin": 2 } ] \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 54224f82..7c18b8ec 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,12 +1,28 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html +[env:esp8266_4mb] +lib_deps = + ${common_env_data.lib_deps_external} + ${env:esp8266_4mb_fromitems.lib_deps} +build_flags = -Desp8266_4mb="esp8266_4mb" +framework = arduino +board = nodemcuv2 +board_build.ldscript = eagle.flash.4m1m.ld +platform = espressif8266 @2.6.3 +monitor_filters = esp8266_exception_decoder +upload_speed = 921600 +monitor_speed = 115200 +board_build.filesystem = littlefs + +[env:esp32_4mb] +lib_deps = + ${common_env_data.lib_deps_external} + ${env:esp32_4mb_fromitems.lib_deps} +build_flags = -Desp32_4mb="esp32_4mb" +framework = arduino +board = esp32dev +platform = espressif32 @3.3.0 +monitor_filters = esp32_exception_decoder +upload_speed = 921600 +monitor_speed = 115200 [platformio] default_envs = esp8266_4mb @@ -19,51 +35,33 @@ lib_deps_external = Links2004/WebSockets knolleary/PubSubClient -[env:esp8266_4mb] -build_flags = -Desp8266_4mb="esp8266_4mb" -framework = arduino -board = nodemcuv2 -board_build.ldscript = eagle.flash.4m1m.ld -platform = espressif8266 @2.6.3 +[env:esp8266_4mb_fromitems] lib_deps = - ${common_env_data.lib_deps_external} - milesburton/DallasTemperature@^3.9.1 - robtillaart/SHT2x@^0.1.1 - beegee-tokyo/DHT sensor library for ESPx - adafruit/Adafruit BMP280 Library - adafruit/Adafruit BME280 Library - Adafruit AHTX0 - marcoschwartz/LiquidCrystal_I2C@^1.1.4 - me-no-dev/ESPAsyncUDP - ClosedCube HDC1080 - https://github.com/JonasGMorsch/GY-21.git - adafruit/Adafruit ADS1X15 @ ^2.3.0 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + adafruit/Adafruit ADS1X15 @ ^2.3.0 + Adafruit AHTX0 + adafruit/Adafruit BME280 Library + adafruit/Adafruit BMP280 Library + beegee-tokyo/DHT sensor library for ESPx + milesburton/DallasTemperature@^3.9.1 + https://github.com/JonasGMorsch/GY-21.git + ClosedCube HDC1080 Nova Fitness Sds dust sensors library@1.5.1 -monitor_filters = esp8266_exception_decoder -upload_speed = 921600 -monitor_speed = 115200 -board_build.filesystem = littlefs + robtillaart/SHT2x@^0.1.1 + marcoschwartz/LiquidCrystal_I2C@^1.1.4 -[env:esp32_4mb] -build_flags = -Desp32_4mb="esp32_4mb" -framework = arduino -board = esp32dev -platform = espressif32 @3.3.0 +[env:esp32_4mb_fromitems] lib_deps = - ${common_env_data.lib_deps_external} - milesburton/DallasTemperature@^3.9.1 - robtillaart/SHT2x@^0.1.1 - beegee-tokyo/DHT sensor library for ESPx - adafruit/Adafruit BMP280 Library - adafruit/Adafruit BME280 Library - Adafruit AHTX0 - marcoschwartz/LiquidCrystal_I2C@^1.1.4 - ClosedCube HDC1080 - https://github.com/JonasGMorsch/GY-21.git - adafruit/Adafruit ADS1X15 @ ^2.3.0 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + adafruit/Adafruit ADS1X15 @ ^2.3.0 + Adafruit AHTX0 + adafruit/Adafruit BME280 Library + adafruit/Adafruit BMP280 Library + beegee-tokyo/DHT sensor library for ESPx + milesburton/DallasTemperature@^3.9.1 + https://github.com/JonasGMorsch/GY-21.git + ClosedCube HDC1080 Nova Fitness Sds dust sensors library@1.5.1 -monitor_filters = esp32_exception_decoder -upload_speed = 921600 -monitor_speed = 115200 + robtillaart/SHT2x@^0.1.1 + marcoschwartz/LiquidCrystal_I2C@^1.1.4 + diff --git a/src/modules/ButtonOut.cpp b/src/modules/exec/ButtonOut/ButtonOut.cpp similarity index 100% rename from src/modules/ButtonOut.cpp rename to src/modules/exec/ButtonOut/ButtonOut.cpp diff --git a/src/modules/exec/ButtonOut/items.json b/src/modules/exec/ButtonOut/items.json new file mode 100644 index 00000000..2ab65d68 --- /dev/null +++ b/src/modules/exec/ButtonOut/items.json @@ -0,0 +1,16 @@ +[ + { + "name": "Кнопка управляющая пином (Реле с кнопкой)", + "num": 31, + "type": "Writing", + "subtype": "ButtonOut", + "id": "btn", + "widget": "toggle", + "page": "Кнопки", + "descr": "", + "int": 0, + + "inv": 0, + "pin": 2 + } +] \ No newline at end of file diff --git a/src/modules/exec/items.json b/src/modules/exec/items.json new file mode 100644 index 00000000..8cb113d8 --- /dev/null +++ b/src/modules/exec/items.json @@ -0,0 +1,5 @@ +[ + { + "header": "Модули управления" + } +] \ No newline at end of file diff --git a/src/modules/items.json b/src/modules/items.json new file mode 100644 index 00000000..a71a6cfd --- /dev/null +++ b/src/modules/items.json @@ -0,0 +1,6 @@ +[ + { + "name": "Выберите элемент", + "num": 0 + } +] \ No newline at end of file diff --git a/src/modules/Lcd2004.cpp b/src/modules/lcd/Lcd2004/Lcd2004.cpp similarity index 100% rename from src/modules/Lcd2004.cpp rename to src/modules/lcd/Lcd2004/Lcd2004.cpp diff --git a/src/modules/lcd/Lcd2004/items.json b/src/modules/lcd/Lcd2004/items.json new file mode 100644 index 00000000..81118ea4 --- /dev/null +++ b/src/modules/lcd/Lcd2004/items.json @@ -0,0 +1,32 @@ +[ + { + "name": "LCD экран 2004", + "num": 25, + "type": "Reading", + "subtype": "Lcd2004", + "id": "Lcd", + "widget": "", + "page": "", + "descr": "T", + "int": 15, + "addr": "0x27", + "size": "20,4", + "coord": "0,0", + "id2show": "id датчика" + }, + { + "name": "LCD экран 1602", + "num": 26, + "type": "Reading", + "subtype": "Lcd2004", + "id": "Lcd", + "widget": "", + "page": "", + "descr": "T", + "int": 15, + "addr": "0x27", + "size": "16,2", + "coord": "0,0", + "id2show": "id датчика" + } +] \ No newline at end of file diff --git a/src/modules/lcd/Lcd2004/platformio.ini b/src/modules/lcd/Lcd2004/platformio.ini new file mode 100644 index 00000000..bdecd531 --- /dev/null +++ b/src/modules/lcd/Lcd2004/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + marcoschwartz/LiquidCrystal_I2C@^1.1.4 + +[env:esp32_4mb] +lib_deps = + marcoschwartz/LiquidCrystal_I2C@^1.1.4 diff --git a/src/modules/lcd/items.json b/src/modules/lcd/items.json new file mode 100644 index 00000000..c0739a1d --- /dev/null +++ b/src/modules/lcd/items.json @@ -0,0 +1,5 @@ +[ + { + "header": "Экраны" + } +] \ No newline at end of file diff --git a/src/modules/Ads1115.cpp b/src/modules/sensors/Ads1115/Ads1115.cpp similarity index 100% rename from src/modules/Ads1115.cpp rename to src/modules/sensors/Ads1115/Ads1115.cpp diff --git a/src/modules/sensors/Ads1115/items.json b/src/modules/sensors/Ads1115/items.json new file mode 100644 index 00000000..9cfc0bcd --- /dev/null +++ b/src/modules/sensors/Ads1115/items.json @@ -0,0 +1,21 @@ +[ + { + "name": "Датчик напряжения ADS1115", + "num": 28, + "type": "Reading", + "subtype": "Ads1115", + "id": "Ads3", + "widget": "anydataVlt", + "page": "Сенсоры", + "descr": "ADS_3", + + "pin": "0", + "mode": "volt", + "gain": "3/4x", + + "plus": 0, + "multiply": 1, + "round": 100, + "int": 10 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Ads1115/platformio.ini b/src/modules/sensors/Ads1115/platformio.ini new file mode 100644 index 00000000..89446999 --- /dev/null +++ b/src/modules/sensors/Ads1115/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + adafruit/Adafruit ADS1X15 @ ^2.3.0 + +[env:esp32_4mb] +lib_deps = + adafruit/Adafruit ADS1X15 @ ^2.3.0 \ No newline at end of file diff --git a/src/modules/Aht20.cpp b/src/modules/sensors/Aht20/Aht20.cpp similarity index 100% rename from src/modules/Aht20.cpp rename to src/modules/sensors/Aht20/Aht20.cpp diff --git a/src/modules/sensors/Aht20/items.json b/src/modules/sensors/Aht20/items.json new file mode 100644 index 00000000..91fcef48 --- /dev/null +++ b/src/modules/sensors/Aht20/items.json @@ -0,0 +1,27 @@ +[{ + "name": "Cенсор температуры AHT20", + "num": 12, + "type": "Reading", + "subtype": "Aht20t", + "id": "Temp20", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "AHT20 Температура", + "int": 15, + "addr": "0x38", + "round": 1 +}, +{ + "name": "Cенсор влажности AHT20", + "num": 13, + "type": "Reading", + "subtype": "Aht20h", + "id": "Hum20", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "AHT20 Влажность", + "int": 15, + "addr": "0x38", + "round": 1 +} +] \ No newline at end of file diff --git a/src/modules/sensors/Aht20/platformio.ini b/src/modules/sensors/Aht20/platformio.ini new file mode 100644 index 00000000..5e37d73b --- /dev/null +++ b/src/modules/sensors/Aht20/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + Adafruit AHTX0 + +[env:esp32_4mb] +lib_deps = + Adafruit AHTX0 diff --git a/src/modules/AnalogAdc.cpp b/src/modules/sensors/AnalogAdc/AnalogAdc.cpp similarity index 100% rename from src/modules/AnalogAdc.cpp rename to src/modules/sensors/AnalogAdc/AnalogAdc.cpp diff --git a/src/modules/sensors/AnalogAdc/items.json b/src/modules/sensors/AnalogAdc/items.json new file mode 100644 index 00000000..df3eed30 --- /dev/null +++ b/src/modules/sensors/AnalogAdc/items.json @@ -0,0 +1,18 @@ +[ + { + "name": "Аналоговый сенсор", + "num": 1, + "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 + } +] \ No newline at end of file diff --git a/src/modules/Bme280.cpp b/src/modules/sensors/Bme280/Bme280.cpp similarity index 100% rename from src/modules/Bme280.cpp rename to src/modules/sensors/Bme280/Bme280.cpp diff --git a/src/modules/sensors/Bme280/items.json b/src/modules/sensors/Bme280/items.json new file mode 100644 index 00000000..c04bc9c4 --- /dev/null +++ b/src/modules/sensors/Bme280/items.json @@ -0,0 +1,41 @@ +[ + { + "name": "Cенсор температуры Bme280", + "num": 9, + "type": "Reading", + "subtype": "Bme280t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "addr": "0x77", + "round": 1 + }, + { + "name": "Cенсор давления Bme280", + "num": 10, + "type": "Reading", + "subtype": "Bme280p", + "id": "Press3", + "widget": "anydataMm", + "page": "Сенсоры", + "descr": "Давление", + "int": 15, + "addr": "0x77", + "round": 1 + }, + { + "name": "Cенсор влажности Bme280", + "num": 11, + "type": "Reading", + "subtype": "Bme280h", + "id": "Hum3", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "addr": "0x77", + "round": 1 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Bme280/platformio.ini b/src/modules/sensors/Bme280/platformio.ini new file mode 100644 index 00000000..b4c83133 --- /dev/null +++ b/src/modules/sensors/Bme280/platformio.ini @@ -0,0 +1,8 @@ +[env:esp8266_4mb] +lib_deps = + adafruit/Adafruit BME280 Library + +[env:esp32_4mb] +lib_deps = + adafruit/Adafruit BME280 Library + \ No newline at end of file diff --git a/src/modules/Bmp280.cpp b/src/modules/sensors/Bmp280/Bmp280.cpp similarity index 100% rename from src/modules/Bmp280.cpp rename to src/modules/sensors/Bmp280/Bmp280.cpp diff --git a/src/modules/sensors/Bmp280/items.json b/src/modules/sensors/Bmp280/items.json new file mode 100644 index 00000000..1d5b7636 --- /dev/null +++ b/src/modules/sensors/Bmp280/items.json @@ -0,0 +1,28 @@ +[ + { + "name": "Cенсор температуры Bmp280", + "num": 7, + "type": "Reading", + "subtype": "Bmp280t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "280 Температура", + "int": 15, + "addr": "0x77", + "round": 1 + }, + { + "name": "Cенсор давления Bmp280", + "num": 8, + "type": "Reading", + "subtype": "Bmp280p", + "id": "Press3", + "widget": "anydataMm", + "page": "Сенсоры", + "descr": "280 Давление", + "int": 15, + "addr": "0x77", + "round": 1 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Bmp280/platformio.ini b/src/modules/sensors/Bmp280/platformio.ini new file mode 100644 index 00000000..037efd48 --- /dev/null +++ b/src/modules/sensors/Bmp280/platformio.ini @@ -0,0 +1,8 @@ +[env:esp8266_4mb] +lib_deps = + adafruit/Adafruit BMP280 Library + +[env:esp32_4mb] +lib_deps = + adafruit/Adafruit BMP280 Library + \ No newline at end of file diff --git a/src/modules/Dht1122.cpp b/src/modules/sensors/Dht1122/Dht1122.cpp similarity index 100% rename from src/modules/Dht1122.cpp rename to src/modules/sensors/Dht1122/Dht1122.cpp diff --git a/src/modules/sensors/Dht1122/items.json b/src/modules/sensors/Dht1122/items.json new file mode 100644 index 00000000..e3a90111 --- /dev/null +++ b/src/modules/sensors/Dht1122/items.json @@ -0,0 +1,28 @@ +[ + { + "name": "Cенсор температуры dht11", + "num": 5, + "type": "Reading", + "subtype": "Dht1122t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "pin": 0, + "senstype": "dht11" + }, + { + "name": "Cенсор влажности dht11", + "num": 6, + "type": "Reading", + "subtype": "Dht1122h", + "id": "Hum3", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "pin": 0, + "senstype": "dht11" + } +] \ No newline at end of file diff --git a/src/modules/sensors/Dht1122/platformio.ini b/src/modules/sensors/Dht1122/platformio.ini new file mode 100644 index 00000000..34170b0f --- /dev/null +++ b/src/modules/sensors/Dht1122/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + beegee-tokyo/DHT sensor library for ESPx + +[env:esp32_4mb] +lib_deps = + beegee-tokyo/DHT sensor library for ESPx diff --git a/src/modules/Ds18b20.cpp b/src/modules/sensors/Ds18b20/Ds18b20.cpp similarity index 100% rename from src/modules/Ds18b20.cpp rename to src/modules/sensors/Ds18b20/Ds18b20.cpp diff --git a/src/modules/sensors/Ds18b20/items.json b/src/modules/sensors/Ds18b20/items.json new file mode 100644 index 00000000..f7214366 --- /dev/null +++ b/src/modules/sensors/Ds18b20/items.json @@ -0,0 +1,17 @@ +[ + { + "name": "Cенсор температуры ds18b20", + "num": 2, + "type": "Reading", + "subtype": "Ds18b20", + "id": "dstmp", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "DS Температура", + "int": 15, + "pin": 2, + "index": 0, + "addr": "", + "round": 1 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Ds18b20/platformio.ini b/src/modules/sensors/Ds18b20/platformio.ini new file mode 100644 index 00000000..3cedd5d7 --- /dev/null +++ b/src/modules/sensors/Ds18b20/platformio.ini @@ -0,0 +1,8 @@ +[env:esp8266_4mb] +lib_deps = + milesburton/DallasTemperature@^3.9.1 + +[env:esp32_4mb] +lib_deps = + milesburton/DallasTemperature@^3.9.1 + diff --git a/src/modules/GY-21.cpp b/src/modules/sensors/GY-21/GY-21.cpp similarity index 100% rename from src/modules/GY-21.cpp rename to src/modules/sensors/GY-21/GY-21.cpp diff --git a/src/modules/sensors/GY-21/items.json b/src/modules/sensors/GY-21/items.json new file mode 100644 index 00000000..4acf44a0 --- /dev/null +++ b/src/modules/sensors/GY-21/items.json @@ -0,0 +1,26 @@ +[ + { + "name": "Cенсор температуры GY21", + "num": 16, + "type": "Reading", + "subtype": "GY21t", + "id": "tmp4", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "round": 1, + "int": 15 + }, + { + "name": "Cенсор влажности GY21", + "num": 17, + "type": "Reading", + "subtype": "GY21h", + "id": "Hum4", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "round": 1, + "int": 15 + } +] \ No newline at end of file diff --git a/src/modules/sensors/GY-21/platformio.ini b/src/modules/sensors/GY-21/platformio.ini new file mode 100644 index 00000000..06635eda --- /dev/null +++ b/src/modules/sensors/GY-21/platformio.ini @@ -0,0 +1,8 @@ +[env:esp8266_4mb] +lib_deps = + https://github.com/JonasGMorsch/GY-21.git + +[env:esp32_4mb] +lib_deps = + https://github.com/JonasGMorsch/GY-21.git + \ No newline at end of file diff --git a/src/modules/Hdc1080.cpp b/src/modules/sensors/Hdc1080/Hdc1080.cpp similarity index 100% rename from src/modules/Hdc1080.cpp rename to src/modules/sensors/Hdc1080/Hdc1080.cpp diff --git a/src/modules/sensors/Hdc1080/items.json b/src/modules/sensors/Hdc1080/items.json new file mode 100644 index 00000000..71a0ad41 --- /dev/null +++ b/src/modules/sensors/Hdc1080/items.json @@ -0,0 +1,28 @@ +[ + { + "name": "Cенсор температуры HDC1080", + "num": 14, + "type": "Reading", + "subtype": "Hdc1080t", + "id": "Temp1080", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "1080 Температура", + "int": 15, + "addr": "0x40", + "round": 1 + }, + { + "name": "Cенсор влажности HDC1080", + "num": 15, + "type": "Reading", + "subtype": "Hdc1080h", + "id": "Hum1080", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "1080 Влажность", + "int": 15, + "addr": "0x40", + "round": 1 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Hdc1080/platformio.ini b/src/modules/sensors/Hdc1080/platformio.ini new file mode 100644 index 00000000..4bef7f3b --- /dev/null +++ b/src/modules/sensors/Hdc1080/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + ClosedCube HDC1080 + +[env:esp32_4mb] +lib_deps = + ClosedCube HDC1080 diff --git a/src/modules/Mhz19.cpp b/src/modules/sensors/Mhz19/Mhz19.cpp similarity index 100% rename from src/modules/Mhz19.cpp rename to src/modules/sensors/Mhz19/Mhz19.cpp diff --git a/src/modules/sensors/Mhz19/items.json b/src/modules/sensors/Mhz19/items.json new file mode 100644 index 00000000..327bba53 --- /dev/null +++ b/src/modules/sensors/Mhz19/items.json @@ -0,0 +1,86 @@ +[ + { + "name": "Датчик CO2 MHZ-19 UART", + "num": 20, + "type": "Reading", + "subtype": "Mhz19uart", + "id": "co2uart", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "CO2uart", + "plus": 0, + "multiply": 1, + "round": 1, + "pin": 0, + "rxPin": 14, + "txPin": 16, + "int": 15, + "range": 5000, + "ABC": 1 + }, + { + "name": "Датчик CO2 MHZ-19 PWM", + "num": 21, + "type": "Reading", + "subtype": "Mhz19pwm", + "id": "co2pwm", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "CO2pwm", + "plus": 0, + "multiply": 1, + "round": 1, + "pin": 16, + "int": 300 + }, + { + "name": "Cенсор температуры от MHZ-19 UART", + "num": 22, + "type": "Reading", + "subtype": "Mhz19temp", + "id": "Mhz19temp", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "plus": 0, + "multiply": 1, + "round": 1, + "rxPin": 14, + "txPin": 16, + "ABC": 1, + "int": 30 + }, + { + "name": "Рабочий диапазон от MHZ-19 UART", + "num": 23, + "type": "Reading", + "subtype": "Mhz19range", + "id": "Mhz19range", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "Диапазон", + "plus": 0, + "multiply": 1, + "round": 1, + "rxPin": 14, + "txPin": 16, + "range": 5000, + "ABC": 1, + "int": 30 + }, + { + "name": "Автокалибровка от MHZ-19 UART", + "num": 24, + "type": "Reading", + "subtype": "Mhz19ABC", + "id": "Mhz19ABC", + "widget": "anydataDef", + "page": "Сенсоры", + "descr": "ABC", + "rxPin": 14, + "txPin": 16, + "range": 5000, + "ABC": 1, + "int": 30 + } +] \ No newline at end of file diff --git a/src/modules/Sds011.cpp b/src/modules/sensors/Sds011/Sds011.cpp similarity index 100% rename from src/modules/Sds011.cpp rename to src/modules/sensors/Sds011/Sds011.cpp diff --git a/src/modules/sensors/Sds011/items.json b/src/modules/sensors/Sds011/items.json new file mode 100644 index 00000000..b0dc8d30 --- /dev/null +++ b/src/modules/sensors/Sds011/items.json @@ -0,0 +1,38 @@ +[ + { + "name": "Датчик пыли SDS011 PM25", + "num": 18, + "type": "Reading", + "subtype": "Sds011_25", + "id": "pmuart25", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "PM-2.5", + "plus": 0, + "multiply": 1, + "round": 10, + "rxPin": 13, + "txPin": 12, + "int": 15, + "warmUp": 30, + "period": 300 + }, + { + "name": "Датчик пыли SDS011 PM10", + "num": 19, + "type": "Reading", + "subtype": "Sds011_10", + "id": "pmuart10", + "widget": "anydataPpm", + "page": "Сенсоры", + "descr": "PM-10", + "plus": 0, + "multiply": 1, + "round": 10, + "rxPin": 13, + "txPin": 12, + "int": 15, + "warmUp": 30, + "period": 300 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Sds011/platformio.ini b/src/modules/sensors/Sds011/platformio.ini new file mode 100644 index 00000000..9cfb0c87 --- /dev/null +++ b/src/modules/sensors/Sds011/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + Nova Fitness Sds dust sensors library@1.5.1 + +[env:esp32_4mb] +lib_deps = + Nova Fitness Sds dust sensors library@1.5.1 diff --git a/src/modules/Sht20.cpp b/src/modules/sensors/Sht20/Sht20.cpp similarity index 100% rename from src/modules/Sht20.cpp rename to src/modules/sensors/Sht20/Sht20.cpp diff --git a/src/modules/sensors/Sht20/items.json b/src/modules/sensors/Sht20/items.json new file mode 100644 index 00000000..be83703c --- /dev/null +++ b/src/modules/sensors/Sht20/items.json @@ -0,0 +1,26 @@ +[ + { + "name": "Cенсор температуры Sht20", + "num": 3, + "type": "Reading", + "subtype": "Sht20t", + "id": "tmp2", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "round": 1 + }, + { + "name": "Cенсор влажности Sht20", + "num": 4, + "type": "Reading", + "subtype": "Sht20h", + "id": "Hum2", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "round": 1 + } +] \ No newline at end of file diff --git a/src/modules/sensors/Sht20/platformio.ini b/src/modules/sensors/Sht20/platformio.ini new file mode 100644 index 00000000..aeb22d50 --- /dev/null +++ b/src/modules/sensors/Sht20/platformio.ini @@ -0,0 +1,7 @@ +[env:esp8266_4mb] +lib_deps = + robtillaart/SHT2x@^0.1.1 + +[env:esp32_4mb] +lib_deps = + robtillaart/SHT2x@^0.1.1 diff --git a/src/modules/sensors/items.json b/src/modules/sensors/items.json new file mode 100644 index 00000000..601b4be8 --- /dev/null +++ b/src/modules/sensors/items.json @@ -0,0 +1,5 @@ +[ + { + "header": "Сенсоры" + } +] \ No newline at end of file diff --git a/src/modules/Mcp23017.cpp b/src/modules/system/Mcp23017/Mcp23017.cpp similarity index 100% rename from src/modules/Mcp23017.cpp rename to src/modules/system/Mcp23017/Mcp23017.cpp diff --git a/src/modules/system/Mcp23017/items.json b/src/modules/system/Mcp23017/items.json new file mode 100644 index 00000000..8c44661c --- /dev/null +++ b/src/modules/system/Mcp23017/items.json @@ -0,0 +1,16 @@ +[ + { + "name": "Расширитель портов Mcp23017", + "num": 29, + "type": "Reading", + "subtype": "Mcp23017", + "id": "Mcp", + "widget": "", + "page": "", + "descr": "", + + "int": "0", + "addr": "0x20", + "index": 1 + } +] \ No newline at end of file diff --git a/src/modules/system/Mcp23017/platformio.ini b/src/modules/system/Mcp23017/platformio.ini new file mode 100644 index 00000000..77357a41 --- /dev/null +++ b/src/modules/system/Mcp23017/platformio.ini @@ -0,0 +1,8 @@ +[env:esp8266_4mb] +lib_deps = + adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + +[env:esp32_4mb] +lib_deps = + adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 + diff --git a/src/modules/SysExt.cpp b/src/modules/system/SysExt/SysExt.cpp similarity index 100% rename from src/modules/SysExt.cpp rename to src/modules/system/SysExt/SysExt.cpp diff --git a/src/modules/system/SysExt/items.json b/src/modules/system/SysExt/items.json new file mode 100644 index 00000000..9ee6a261 --- /dev/null +++ b/src/modules/system/SysExt/items.json @@ -0,0 +1,13 @@ +[ + { + "name": "Доп. функции системы", + "num": 27, + "type": "Reading", + "subtype": "SysExt", + "id": "SysExt", + "widget": "", + "page": "", + "descr": "", + "int": 15 + } +] \ No newline at end of file diff --git a/src/modules/Variable.cpp b/src/modules/system/Variable/Variable.cpp similarity index 100% rename from src/modules/Variable.cpp rename to src/modules/system/Variable/Variable.cpp diff --git a/src/modules/system/Variable/items.json b/src/modules/system/Variable/items.json new file mode 100644 index 00000000..d86f6d58 --- /dev/null +++ b/src/modules/system/Variable/items.json @@ -0,0 +1,15 @@ +[ + { + "name": "Переменная", + "num": 30, + "type": "Reading", + "subtype": "Variable", + "id": "var", + "widget": "", + "page": "", + "descr": "", + + "int": "0", + "val": "0" + } +] \ No newline at end of file diff --git a/src/modules/system/items.json b/src/modules/system/items.json new file mode 100644 index 00000000..18bf3b6a --- /dev/null +++ b/src/modules/system/items.json @@ -0,0 +1,5 @@ +[ + { + "header": "Расширения" + } +] \ No newline at end of file From 75a96508b218e8eefa6d403382778e3469028659 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 7 Mar 2022 21:53:13 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D1=8F=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=98=D0=94=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20GY21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/API.cpp | 72 +++++++++---------- .../{GY-21/GY-21.cpp => GY21/GY21.cpp} | 0 .../sensors/{GY-21 => GY21}/items.json | 0 .../sensors/{GY-21 => GY21}/platformio.ini | 0 4 files changed, 32 insertions(+), 40 deletions(-) rename src/modules/sensors/{GY-21/GY-21.cpp => GY21/GY21.cpp} (100%) rename src/modules/sensors/{GY-21 => GY21}/items.json (100%) rename src/modules/sensors/{GY-21 => GY21}/platformio.ini (100%) diff --git a/src/modules/API.cpp b/src/modules/API.cpp index b08d148d..7101a3b0 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -1,48 +1,40 @@ #include "ESPConfiguration.h" -//============================================================================================ -//здесь скопируйте строку и вставьте ниже, заменив имя AnalogAdc на название вашего сенсора -void* getAPI_AnalogAdc(String subtype, String params); -void* getAPI_Ds18b20(String subtype, String params); -void* getAPI_Sht20(String subtype, String params); -void* getAPI_Dht1122(String subtype, String params); -void* getAPI_Bmp280(String subtype, String params); -void* getAPI_Bme280(String subtype, String params); -void* getAPI_Aht20(String subtype, String params); -void* getAPI_Hdc1080(String subtype, String params); -void* getAPI_GY21(String subtype, String params); -void* getAPI_Lcd2004(String subtype, String params); -void* getAPI_SysExt(String subtype, String params); -void* getAPI_Ads1115(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params); -void* getAPI_ButtonOut(String subtype, String params); +void* getAPI_SysExt(String subtype, String params); void* getAPI_Variable(String subtype, String params); -void* getAPI_Sds011(String subtype, String params); +void* getAPI_ButtonOut(String subtype, String params); +void* getAPI_Ads1115(String subtype, String params); +void* getAPI_Aht20(String subtype, String params); +void* getAPI_AnalogAdc(String subtype, String params); +void* getAPI_Bme280(String subtype, String params); +void* getAPI_Bmp280(String subtype, String params); +void* getAPI_Dht1122(String subtype, String params); +void* getAPI_Ds18b20(String subtype, String params); +void* getAPI_GY21(String subtype, String params); +void* getAPI_Hdc1080(String subtype, String params); void* getAPI_Mhz19(String subtype, String params); -//============================================================================================ +void* getAPI_Sds011(String subtype, String params); +void* getAPI_Sht20(String subtype, String params); +void* getAPI_Lcd2004(String subtype, String params); void* getAPI(String subtype, String params) { - void* tmpAPI; - //=============================================================================================================== - //здесь нужно скопировать строку еще раз и вставить ее ниже, переименовав AnalogAdc на название вашего сенсора - if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Sds011(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Mhz19(subtype, params)) != nullptr) return tmpAPI; - //================================================================================================================ - - return nullptr; +void* tmpAPI; +if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI; +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_GY21(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Mhz19(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sds011(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sht20(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/sensors/GY-21/GY-21.cpp b/src/modules/sensors/GY21/GY21.cpp similarity index 100% rename from src/modules/sensors/GY-21/GY-21.cpp rename to src/modules/sensors/GY21/GY21.cpp diff --git a/src/modules/sensors/GY-21/items.json b/src/modules/sensors/GY21/items.json similarity index 100% rename from src/modules/sensors/GY-21/items.json rename to src/modules/sensors/GY21/items.json diff --git a/src/modules/sensors/GY-21/platformio.ini b/src/modules/sensors/GY21/platformio.ini similarity index 100% rename from src/modules/sensors/GY-21/platformio.ini rename to src/modules/sensors/GY21/platformio.ini From 93b6014c55ec9e02a8e6fd1cb0fdc74d0414dabb Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 7 Mar 2022 21:56:15 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D1=80=D0=BE=D1=86?= =?UTF-8?q?=D0=B5=D1=81=D1=81=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=D0=B0=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accembleItems.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/accembleItems.py b/accembleItems.py index 6f19c5a7..fae42c91 100644 --- a/accembleItems.py +++ b/accembleItems.py @@ -5,8 +5,12 @@ import json, pprint config = configparser.ConfigParser() # создаём объекта парсера INI allLibs_esp8266_4mb = "" allLibs_esp32_4mb = "" + allMenuItems = json.loads('[]') -allMenuItemsCount = 1; +allMenuItemsCount = 1 + +allAPI_head = "" +allAPI_exec = "" def getDirs(path): @@ -40,6 +44,14 @@ def getMenuItems(patch): allMenuItems = allMenuItems + data +def getAPI(patch): + global allAPI_head, allAPI_exec + for dir in getDirs(patch): + print(patch + dir) + allAPI_head = allAPI_head + "\nvoid* getAPI_" + dir + "(String subtype, String params);" + allAPI_exec = allAPI_exec + "\nif ((tmpAPI = getAPI_" + dir + "(subtype, params)) != nullptr) return tmpAPI;" + + # читаем и запоминаем все либы мз каждого модуля getPIOLibs("src/modules/system/") @@ -69,4 +81,20 @@ getMenuItems("src/modules/lcd/") # сохраняем пункты меню в общий файл with open('data_svelte/items.json', 'w') as f: - json.dump(allMenuItems, f, ensure_ascii=False, indent=4, sort_keys=False) \ No newline at end of file + json.dump(allMenuItems, f, ensure_ascii=False, indent=4, sort_keys=False) + + +# собираем списки API для интеграции вызовов модулей +getAPI("src/modules/system/") +getAPI("src/modules/exec/") +getAPI("src/modules/sensors/") +getAPI("src/modules/lcd/") + +# сохраняем все API в API.cpp +apicpp = '#include "ESPConfiguration.h"\n' +apicpp = apicpp + allAPI_head +apicpp = apicpp + '\n\nvoid* getAPI(String subtype, String params) {\nvoid* tmpAPI;' +apicpp = apicpp + allAPI_exec +apicpp = apicpp + 'return nullptr;\n}' +with open('src/modules/API.cpp', 'w') as f: + f.write(apicpp) \ No newline at end of file