mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Добавляем сенсор качества воздуха Sgp30
This commit is contained in:
89
src/modules/sensors/Sgp30/Sgp30.cpp
Normal file
89
src/modules/sensors/Sgp30/Sgp30.cpp
Normal file
@@ -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 <Wire.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
64
src/modules/sensors/Sgp30/modinfo.json
Normal file
64
src/modules/sensors/Sgp30/modinfo.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user