From 4dba35d08e7cfaee8ad66127f8ddfef85683fdfb Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 21 Nov 2022 21:14:52 +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=20=D0=B2=D0=B5=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Hx711/Hx711.cpp | 56 ++++++++++++++++++++ src/modules/sensors/Hx711/modinfo.json | 71 ++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 src/modules/sensors/Hx711/Hx711.cpp create mode 100644 src/modules/sensors/Hx711/modinfo.json diff --git a/src/modules/sensors/Hx711/Hx711.cpp b/src/modules/sensors/Hx711/Hx711.cpp new file mode 100644 index 00000000..9e08c3e4 --- /dev/null +++ b/src/modules/sensors/Hx711/Hx711.cpp @@ -0,0 +1,56 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include + + +class GyverHX711g : public IoTItem { + + private: + GyverHX711* _thermocouple = nullptr; + + public: + GyverHX711g(String parameters) : IoTItem(parameters) { + int data, clock, chan; + jsonRead(parameters, "data", data); + jsonRead(parameters, "clock", clock); + jsonRead(parameters, "chan", chan); + _thermocouple = new GyverHX711(data, clock, chan); + + _thermocouple->tare(); // калибровка нуля + } + + void doByInterval() { + if (!_thermocouple->available()) return; + + value.valD = _thermocouple->read(); + regEvent(value.valD, "Hx711"); + } + + IoTValue execute(String command, std::vector ¶m) { + if (command == "tare") { + _thermocouple->tare(); + } else if (command == "sleepMode") { + if (param.size() == 1) { + _thermocouple->sleepMode(param[0].valD); + } + } else if (command == "read") { + value.valD = _thermocouple->read(); + regEvent(value.valD, "Hx711"); + return value; + } + return {}; + } + + ~GyverHX711g() { + if (_thermocouple) delete _thermocouple; + }; +}; + +void* getAPI_Hx711(String subtype, String param) { + if (subtype == F("Hx711")) { + return new GyverHX711g(param); + } else { + return nullptr; + } +} diff --git a/src/modules/sensors/Hx711/modinfo.json b/src/modules/sensors/Hx711/modinfo.json new file mode 100644 index 00000000..6e9ef872 --- /dev/null +++ b/src/modules/sensors/Hx711/modinfo.json @@ -0,0 +1,71 @@ +{ + "menuSection": "Сенсоры", + + "configItem": [{ + "name": "HX711 Cенсор весов", + "type": "Reading", + "subtype": "Hx711", + "id": "hx", + "widget": "anydataDef", + "page": "Весы", + "descr": "HX вес", + "int": 15, + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 1, + "data": 3, + "clock": 2, + "chan": 2 + }], + + "about": { + "authorName": "Serghei Crasnicov", + "authorContact": "https://t.me/Serghei63", + "authorGit": "https://github.com/Serghei63", + "specialThanks": "", + "moduleName": "Hx711", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "HX711 Cенсор весов", + "moduleDesc": "Позволяет получить вес в килограммах с датчика Hx711", + "propInfo": { + "clock": "GPIO шины данных", + "data": "GPIO шины данных", + "chan": "Канал и усиление: =0 (HX_GAIN128_A) - канал А усиление 128, =1 (HX_GAIN32_B) - канал B усиление 32, =2 (HX_GAIN64_A) - канал А усиление 64", + "int": "Количество секунд между опросами датчика." + }, + "retInfo": "Содержит RAW значение датчика, необходима калибровка", + "funcInfo": [ + { + "name": "tare", + "descr": "Авто установка нуля", + "params": [] + }, + { + "name": "sleepMode", + "descr": "Перевести в режим сна", + "params": ["=1 режим сна, =0 проснуться"] + }, + { + "name": "read", + "descr": "Прочитать текущее значение. Полезно использовать при Int=0 и считывать вес по событию.", + "params": [] + } + ] + }, + + "defActive": true, + + "usedLibs": { + "esp32_4mb": [ + "GyverHX711@1.2" + ], + "esp8266_4mb": [ + "GyverHX711@1.2" + ] + } +} \ No newline at end of file From 267408fc7718594f44c2717c570a1947e4271609 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 21 Nov 2022 21:39:38 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=92=D1=8B=D0=BA=D0=BB=D1=8E=D1=87=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B2=D0=B5=D1=81=D1=8B=20=D0=BF=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=B5=D1=84=D0=BE=D0=BB=D1=82=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Hx711/modinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sensors/Hx711/modinfo.json b/src/modules/sensors/Hx711/modinfo.json index 6e9ef872..4627711a 100644 --- a/src/modules/sensors/Hx711/modinfo.json +++ b/src/modules/sensors/Hx711/modinfo.json @@ -58,7 +58,7 @@ ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32_4mb": [ From f53943521614742f49031720cc0668e4f4dd3f59 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 21 Nov 2022 21:40:20 +0300 Subject: [PATCH 3/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=20=D0=B4=D0=B0=D1=82=D1=87=D0=B8=D0=BA=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20Hx710?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Hx710/Hx710.cpp | 48 +++++++++++++++++++++ src/modules/sensors/Hx710/modinfo.json | 58 ++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/modules/sensors/Hx710/Hx710.cpp create mode 100644 src/modules/sensors/Hx710/modinfo.json diff --git a/src/modules/sensors/Hx710/Hx710.cpp b/src/modules/sensors/Hx710/Hx710.cpp new file mode 100644 index 00000000..210cef75 --- /dev/null +++ b/src/modules/sensors/Hx710/Hx710.cpp @@ -0,0 +1,48 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include "HX710B.h" + + +class HX710b : public IoTItem { + + private: + HX710B pressure_sensor; + + public: + HX710b(String parameters) : IoTItem(parameters) { + int data, clock; + jsonRead(parameters, "data", data); + jsonRead(parameters, "clock", clock); + + pressure_sensor.begin(data, clock); + pressure_sensor.tare(); + } + + void doByInterval() { + if (!pressure_sensor.is_ready()) return; + value.valD = pressure_sensor.mmHg(); + + regEvent(value.valD, "Hx710"); + } + + IoTValue execute(String command, std::vector ¶m) { + if (command == "tare") { + pressure_sensor.tare(); + } else if (command == "read") { + value.valD = pressure_sensor.read(); + return value; + } + return {}; + } + + ~HX710b() {}; +}; + +void* getAPI_Hx710(String subtype, String param) { + if (subtype == F("Hx710")) { + return new HX710b(param); + } else { + return nullptr; + } +} diff --git a/src/modules/sensors/Hx710/modinfo.json b/src/modules/sensors/Hx710/modinfo.json new file mode 100644 index 00000000..985c4457 --- /dev/null +++ b/src/modules/sensors/Hx710/modinfo.json @@ -0,0 +1,58 @@ +{ + "menuSection": "Сенсоры", + + "configItem": [{ + "name": "HX710 Cенсор давления", + "type": "Reading", + "subtype": "Hx710", + "id": "hxp", + "widget": "anydataDef", + "page": "Давление", + "descr": "HX press", + "int": 15, + "plus": 0, + "multiply": 1, + "round": 1, + "data": 14, + "clock": 15 + }], + + "about": { + "authorName": "Serghei Crasnicov", + "authorContact": "https://t.me/Serghei63", + "authorGit": "https://github.com/Serghei63", + "specialThanks": "", + "moduleName": "Hx710", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "HX710 Cенсор давления", + "moduleDesc": "Позволяет получить давление с датчика Hx710", + "propInfo": { + "clock": "GPIO шины данных", + "data": "GPIO шины данных", + "int": "Количество секунд между опросами датчика." + }, + "retInfo": "Содержит mmHg значение датчика, необходима калибровка", + "funcInfo": [ + { + "name": "read", + "descr": "Прочитать текущее значение. Полезно использовать при Int=0 и считывать RAW-data по событию.", + "params": [] + } + ] + }, + + "defActive": false, + + "usedLibs": { + "esp32_4mb": [ + "https://github.com/kurimawxx00/hx710B_pressure_sensor" + ], + "esp8266_4mb": [ + "https://github.com/kurimawxx00/hx710B_pressure_sensor" + ] + } +} \ No newline at end of file From 2dd9cf8720003c299940abea378544f453f62f55 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Nov 2022 18:35:00 +0300 Subject: [PATCH 4/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=20=D1=81=D0=B5=D0=BD=D1=81=D0=BE=D1=80=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D1=83=D1=85=D0=B0=20Sgp30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Sgp30/Sgp30.cpp | 89 ++++++++++++++++++++++++++ src/modules/sensors/Sgp30/modinfo.json | 64 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/modules/sensors/Sgp30/Sgp30.cpp create mode 100644 src/modules/sensors/Sgp30/modinfo.json diff --git a/src/modules/sensors/Sgp30/Sgp30.cpp b/src/modules/sensors/Sgp30/Sgp30.cpp new file mode 100644 index 00000000..fc4050e8 --- /dev/null +++ b/src/modules/sensors/Sgp30/Sgp30.cpp @@ -0,0 +1,89 @@ +#include "Global.h" +#include "classes/IoTItem.h" + + +extern IoTGpio IoTgpio; + +#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30 +#include + +SGP30* mySensor = nullptr; //create an object of the SGP30 class + + +class Sgp30t : public IoTItem { + public: + Sgp30t(String parameters): IoTItem(parameters) { + if (!mySensor) mySensor = new SGP30(); + mySensor->begin(); + + Wire.begin(); + //Initialize sensor + if (mySensor->begin() == false) { + Serial.println("No SGP30 Detected. Check connections."); + //while (1); + } + //Initializes sensor for air quality readings + //measureAirQuality should be called in one second increments after a call to initAirQuality + mySensor->initAirQuality(); + } + + void doByInterval() { + mySensor->measureAirQuality(); + value.valD = mySensor->CO2; + + if (value.valD > -46.85F) regEvent(value.valD, "Sgp30t"); + else SerialPrint("E", "Sensor Sgp30t", "Error"); + } + + ~Sgp30t() {}; +}; + +class Sgp30e : public IoTItem { + public: + Sgp30e(String parameters): IoTItem(parameters) { + + if (!mySensor) mySensor = new SGP30(); + mySensor->begin(); + + + Wire.begin(); + //Initialize sensor + if (mySensor->begin() == false) { + Serial.println("No SGP30 Detected. Check connections."); + while (1); + } + //Initializes sensor for air quality readings + //measureAirQuality should be called in one second increments after a call to initAirQuality + mySensor->initAirQuality(); + + } + + void doByInterval() { + mySensor->measureAirQuality(); + + value.valD = mySensor->TVOC; + + if (value.valD != -6) regEvent(value.valD, "Sgp30e"); + else SerialPrint("E", "Sensor Sgp30e", "Error"); + + } + + ~Sgp30e() {}; +}; + + +void* getAPI_Sgp30(String subtype, String param) { + if (subtype == F("Sgp30t")) { + + // mySensor.begin() ; + // mySensor.initAirQuality(); + + return new Sgp30t(param); + } else if (subtype == F("Sgp30e")) { + // mySensor.begin() ; + // mySensor.initAirQuality(); + return new Sgp30e(param); + } else { + return nullptr; + } +} \ No newline at end of file diff --git a/src/modules/sensors/Sgp30/modinfo.json b/src/modules/sensors/Sgp30/modinfo.json new file mode 100644 index 00000000..8465be52 --- /dev/null +++ b/src/modules/sensors/Sgp30/modinfo.json @@ -0,0 +1,64 @@ +{ + "menuSection": "Сенсоры", + "configItem": [ + { + "global": 0, + "name": "SGP30 Cенсор качества воздуха", + "num": 3, + "type": "Reading", + "subtype": "Sgp30t", + "id": "sgp30t", + "widget": "anydatappm", + "page": "Сенсоры", + "descr": "TVOC", + "int": 30, + "round": 1 + }, + { + "global": 0, + "name": "SGP30 Cенсор газа", + "num": 4, + "type": "Reading", + "subtype": "Sgp30e", + "id": "sgp30e", + "widget": "anydatappm", + "page": "Сенсоры", + "descr": "eCO2", + "int": 30, + "round": 1 + } + ], + "about": { + "authorName": "Serghei Crasnicov", + "authorContact": "https://t.me/Serghei63", + "authorGit": "https://github.com/Serghei63", + "specialThanks": "Ilya Belyakov", + "moduleName": "Sgp30", + "moduleVersion": "1.0", + "usedRam": 15, + "subTypes": [ + "Sgp30t", + "Sgp30e" + ], + "title": "Датчик качества воздуха SGP30", + "moduleDesc": "Измеряет параметвы воздуха.", + "propInfo": { + "int": "Количество секунд между опросами датчика." + } + }, + "defActive": false, + "usedLibs": { + "esp32_4mb": [ + "sparkfun/SparkFun SGP30 Arduino Library@^1.0.5" + ], + "esp8266_4mb": [ + "sparkfun/SparkFun SGP30 Arduino Library@^1.0.5" + ], + "esp8266_1mb": [ + "sparkfun/SparkFun SGP30 Arduino Library@^1.0.5" + ], + "esp8266_1mb_ota": [ + "sparkfun/SparkFun SGP30 Arduino Library@^1.0.5" + ] + } +} \ No newline at end of file