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