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 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..4627711a --- /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": false, + + "usedLibs": { + "esp32_4mb": [ + "GyverHX711@1.2" + ], + "esp8266_4mb": [ + "GyverHX711@1.2" + ] + } +} \ No newline at end of file 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 diff --git a/src/modules/virtual/Cron/Cron.cpp b/src/modules/virtual/Cron/Cron.cpp index 2c24eb59..55eb933a 100644 --- a/src/modules/virtual/Cron/Cron.cpp +++ b/src/modules/virtual/Cron/Cron.cpp @@ -13,11 +13,12 @@ class Cron : public IoTItem { String _format = ""; cron_expr _expr; time_t _nextAlarm = 0; + bool _isInit = false; public: Cron(String parameters): IoTItem(parameters) { jsonRead(parameters, F("formatNextAlarm"), _format); - initCron(); + if (_time_isTrust) initCron(); } void initCron() { @@ -39,6 +40,7 @@ class Cron : public IoTItem { if (forced || (_nextAlarm <= gmtTimeToLocal(unixTime))) { // update alarm if next trigger is not yet in the future _nextAlarm = cron_next(&_expr, gmtTimeToLocal(unixTime)); + _isInit = true; } } } @@ -58,6 +60,8 @@ class Cron : public IoTItem { } void setValue(const IoTValue& Value, bool genEvent) { + if (!_time_isTrust) return; + value = Value; _pause = false; initCron(); @@ -74,6 +78,7 @@ class Cron : public IoTItem { } void doByInterval() { + if (!_isInit && _time_isTrust) initCron(); if (!_pause && _time_isTrust && (gmtTimeToLocal(unixTime) >= _nextAlarm)) { updateNextAlarm(true); bool _needSaveBak = _needSave;