mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
ccs811 полная интеграция
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
#include "BufferExecute.h"
|
||||
|
||||
#include "Global.h"
|
||||
#include "SoftUART.h"
|
||||
//
|
||||
#include "items/vSensorUptime.h"
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "items/vButtonOut.h"
|
||||
#include "items/vPwmOut.h"
|
||||
#include "items/vCountDown.h"
|
||||
#include "items/vImpulsOut.h"
|
||||
#include "items/vInOutput.h"
|
||||
#include "items/vLogging.h"
|
||||
#include "items/vImpulsOut.h"
|
||||
#include "items/vCountDown.h"
|
||||
#include "items/vPwmOut.h"
|
||||
#include "items/vSensorAnalog.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorBme280.h"
|
||||
#include "items/vSensorBmp280.h"
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "items/vSensorUptime.h"
|
||||
#include "items/vSensorCcs811.h"
|
||||
|
||||
void loopCmdAdd(const String& cmdStr) {
|
||||
if (cmdStr.endsWith(",")) {
|
||||
orderBuf += cmdStr;
|
||||
#ifdef uartEnable
|
||||
#ifdef uartEnable
|
||||
if (jsonReadBool(configSetupJson, "uart")) {
|
||||
if (jsonReadBool(configSetupJson, "uartEvents")) {
|
||||
if (myUART) {
|
||||
@@ -51,7 +53,7 @@ void csvCmdExecute(String& cmdStr) {
|
||||
count++;
|
||||
if (count > 1) {
|
||||
SerialPrint("I", "Items", buf);
|
||||
String order = selectToMarker(buf, " "); //отсечка самой команды
|
||||
String order = selectToMarker(buf, " "); //отсечка самой команды
|
||||
|
||||
if (order == F("button-out")) {
|
||||
sCmd.addCommand(order.c_str(), buttonOut);
|
||||
@@ -63,17 +65,13 @@ void csvCmdExecute(String& cmdStr) {
|
||||
#endif
|
||||
else if (order == F("button-in")) {
|
||||
sCmd.addCommand(order.c_str(), buttonIn);
|
||||
}
|
||||
else if (order == F("inoutput")) {
|
||||
} else if (order == F("inoutput")) {
|
||||
sCmd.addCommand(order.c_str(), inOutput);
|
||||
}
|
||||
else if (order == F("analog-adc")) {
|
||||
} else if (order == F("analog-adc")) {
|
||||
sCmd.addCommand(order.c_str(), analogAdc);
|
||||
}
|
||||
else if (order == F("ultrasonic-cm")) {
|
||||
} else if (order == F("ultrasonic-cm")) {
|
||||
sCmd.addCommand(order.c_str(), ultrasonic);
|
||||
}
|
||||
else if (order == F("dallas-temp")) {
|
||||
} else if (order == F("dallas-temp")) {
|
||||
sCmd.addCommand(order.c_str(), dallas);
|
||||
}
|
||||
#ifdef SensorDhtEnabled
|
||||
@@ -86,21 +84,18 @@ void csvCmdExecute(String& cmdStr) {
|
||||
sCmd.addCommand(order.c_str(), bme280Sensor);
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorBmp280Enabled
|
||||
else if (order == F("ccs811")) {
|
||||
sCmd.addCommand(order.c_str(), ccs811Sensor);
|
||||
}
|
||||
else if (order == F("bmp280")) {
|
||||
sCmd.addCommand(order.c_str(), bmp280Sensor);
|
||||
}
|
||||
#endif
|
||||
else if (order == F("uptime")) {
|
||||
} else if (order == F("uptime")) {
|
||||
sCmd.addCommand(order.c_str(), uptimeSensor);
|
||||
}
|
||||
else if (order == F("logging")) {
|
||||
} else if (order == F("logging")) {
|
||||
sCmd.addCommand(order.c_str(), logging);
|
||||
}
|
||||
else if (order == F("impuls-out")) {
|
||||
} else if (order == F("impuls-out")) {
|
||||
sCmd.addCommand(order.c_str(), impuls);
|
||||
}
|
||||
else if (order == F("count-down")) {
|
||||
} else if (order == F("count-down")) {
|
||||
sCmd.addCommand(order.c_str(), countDown);
|
||||
}
|
||||
|
||||
@@ -154,14 +149,11 @@ String getValue(String& key) {
|
||||
String store = jsonReadStr(configStoreJson, key);
|
||||
if (live != nullptr) {
|
||||
return live;
|
||||
}
|
||||
else if (store != nullptr) {
|
||||
} else if (store != nullptr) {
|
||||
return store;
|
||||
}
|
||||
else if (store == nullptr && live == nullptr) {
|
||||
} else if (store == nullptr && live == nullptr) {
|
||||
return "no value";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return "data error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
SensorCcs811::SensorCcs811(const paramsCcs811& paramsCo2, const paramsCcs811& paramsPpm) {
|
||||
_paramsCo2 = paramsCcs811(paramsCo2);
|
||||
SensorCcs811::SensorCcs811(const paramsCcs811& paramsPpm, const paramsCcs811& paramsPpb) {
|
||||
_paramsPpm = paramsCcs811(paramsPpm);
|
||||
_paramsPpb = paramsCcs811(paramsPpb);
|
||||
|
||||
ccs811 = new Adafruit_CCS811();
|
||||
|
||||
@@ -19,7 +19,7 @@ SensorCcs811::~SensorCcs811() {}
|
||||
|
||||
void SensorCcs811::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsPpm.interval) {
|
||||
if (difference >= _paramsPpb.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
@@ -33,18 +33,18 @@ void SensorCcs811::read() {
|
||||
co2 = ccs811->geteCO2();
|
||||
ppm = ccs811->getTVOC();
|
||||
|
||||
co2 = co2 * _paramsCo2.c;
|
||||
ppm = ppm * _paramsPpm.c;
|
||||
co2 = co2 * _paramsPpm.c;
|
||||
ppm = ppm * _paramsPpb.c;
|
||||
|
||||
eventGen2(_paramsCo2.key, String(co2));
|
||||
jsonWriteStr(configLiveJson, _paramsCo2.key, String(co2));
|
||||
publishStatus(_paramsCo2.key, String(co2));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsCo2.key + "' data: " + String(co2));
|
||||
eventGen2(_paramsPpm.key, String(co2));
|
||||
jsonWriteStr(configLiveJson, _paramsPpm.key, String(co2));
|
||||
publishStatus(_paramsPpm.key, String(co2));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpm.key + "' data: " + String(co2));
|
||||
|
||||
eventGen2(_paramsPpm.key, String(ppm));
|
||||
jsonWriteStr(configLiveJson, _paramsPpm.key, String(ppm));
|
||||
publishStatus(_paramsPpm.key, String(ppm));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpm.key + "' data: " + String(ppm));
|
||||
eventGen2(_paramsPpb.key, String(ppm));
|
||||
jsonWriteStr(configLiveJson, _paramsPpb.key, String(ppm));
|
||||
publishStatus(_paramsPpb.key, String(ppm));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpb.key + "' data: " + String(ppm));
|
||||
} else {
|
||||
SerialPrint("E", "Sensor CCS", "Error");
|
||||
}
|
||||
@@ -64,25 +64,25 @@ void ccs811Sensor() {
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsCcs811 paramsCo2;
|
||||
static paramsCcs811 paramsPpm;
|
||||
static paramsCcs811 paramsPpb;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsCo2.key = key;
|
||||
paramsCo2.interval = interval.toInt() * 1000;
|
||||
paramsCo2.c = c.toFloat();
|
||||
paramsPpm.key = key;
|
||||
paramsPpm.interval = interval.toInt() * 1000;
|
||||
paramsPpm.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsPpm.key = key;
|
||||
paramsPpm.addr = addr;
|
||||
paramsPpm.interval = interval.toInt() * 1000;
|
||||
paramsPpm.c = c.toFloat();
|
||||
paramsPpb.key = key;
|
||||
paramsPpb.addr = addr;
|
||||
paramsPpb.interval = interval.toInt() * 1000;
|
||||
paramsPpb.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorCcs811 = new MySensorCcs811Vector();
|
||||
firstTime = false;
|
||||
mySensorCcs811->push_back(SensorCcs811(paramsCo2, paramsPpm));
|
||||
mySensorCcs811->push_back(SensorCcs811(paramsPpm, paramsPpb));
|
||||
|
||||
enterCnt = -1;
|
||||
}
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -29,6 +29,7 @@
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "items/vSensorCcs811.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -154,9 +155,14 @@ void loop() {
|
||||
mySensorBmp280->at(i).loop();
|
||||
}
|
||||
}
|
||||
if (mySensorUptime != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorUptime->size(); i++) {
|
||||
mySensorUptime->at(i).loop();
|
||||
if (mySensorBmp280 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorBmp280->size(); i++) {
|
||||
mySensorBmp280->at(i).loop();
|
||||
}
|
||||
}
|
||||
if (mySensorCcs811 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorCcs811->size(); i++) {
|
||||
mySensorCcs811->at(i).loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user