forked from airgradienthq/arduino
build CE payload include tvoc and nox index
If measures value invalid, set it to empty New schedule to print network signal
This commit is contained in:
+57
-42
@@ -3,6 +3,7 @@
|
||||
#include "AirGradient.h"
|
||||
#include "App/AppDef.h"
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#define json_prop_pmFirmware "firmware"
|
||||
#define json_prop_pm01Ae "pm01"
|
||||
@@ -733,90 +734,104 @@ Measurements::MeasurementCycle Measurements::getMeasurementCycle() {
|
||||
return mc;
|
||||
}
|
||||
|
||||
String Measurements::buildMeasurementPayload(MeasurementCycle &mc) {
|
||||
String result;
|
||||
|
||||
int co2 = utils::getInvalidCO2();
|
||||
float temp = utils::getInvalidTemperature();
|
||||
float hum = utils::getInvalidHumidity();
|
||||
float pm01 = utils::getInvalidPmValue();
|
||||
float pm25 = utils::getInvalidPmValue();
|
||||
float pm10 = utils::getInvalidPmValue();
|
||||
int nox = utils::getInvalidNOx();
|
||||
int pm003Count = utils::getInvalidPmValue();
|
||||
std::string Measurements::buildMeasurementPayload(MeasurementCycle &mc) {
|
||||
std::ostringstream oss;
|
||||
|
||||
// CO2
|
||||
if (utils::isValidCO2(mc.co2)) {
|
||||
co2 = std::round(mc.co2);
|
||||
oss << std::round(mc.co2);
|
||||
}
|
||||
|
||||
// NOx
|
||||
if (utils::isValidNOx(mc.nox)) {
|
||||
nox = std::round(mc.nox);
|
||||
}
|
||||
oss << ",";
|
||||
|
||||
/// Temperature
|
||||
// Temperature
|
||||
if (utils::isValidTemperature(mc.temperature[0]) && utils::isValidTemperature(mc.temperature[1])) {
|
||||
temp = ag->round2((mc.temperature[0] + mc.temperature[1]) / 2.0f);
|
||||
float temp = (mc.temperature[0] + mc.temperature[1]) / 2.0f;
|
||||
oss << std::round(temp * 10);
|
||||
} else if (utils::isValidTemperature(mc.temperature[0])) {
|
||||
temp = ag->round2(mc.temperature[0]);
|
||||
oss << std::round(mc.temperature[0] * 10);
|
||||
} else if (utils::isValidTemperature(mc.temperature[1])) {
|
||||
temp = ag->round2(mc.temperature[1]);
|
||||
oss << std::round(mc.temperature[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// Humidity
|
||||
if (utils::isValidHumidity(mc.humidity[0]) && utils::isValidHumidity(mc.humidity[1])) {
|
||||
hum = ag->round2((mc.humidity[0] + mc.humidity[1]) / 2.0f);
|
||||
float hum = (mc.humidity[0] + mc.humidity[1]) / 2.0f;
|
||||
oss << std::round(hum * 10);
|
||||
} else if (utils::isValidHumidity(mc.humidity[0])) {
|
||||
hum = ag->round2(mc.humidity[0]);
|
||||
oss << std::round(mc.humidity[0] * 10);
|
||||
} else if (utils::isValidHumidity(mc.humidity[1])) {
|
||||
hum = ag->round2(mc.humidity[1]);
|
||||
oss << std::round(mc.humidity[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM1.0 atmospheric environment
|
||||
if (utils::isValidPm(mc.pm_01[0]) && utils::isValidPm(mc.pm_01[1])) {
|
||||
pm01 = ag->round2((mc.pm_01[0] + mc.pm_01[1]) / 2.0f);
|
||||
float pm01 = (mc.pm_01[0] + mc.pm_01[1]) / 2.0f;
|
||||
oss << std::round(pm01 * 10);
|
||||
} else if (utils::isValidPm(mc.pm_01[0])) {
|
||||
pm01 = ag->round2(mc.pm_01[0]);
|
||||
oss << std::round(mc.pm_01[0] * 10);
|
||||
} else if (utils::isValidPm(mc.pm_01[1])) {
|
||||
pm01 = ag->round2(mc.pm_01[1]);
|
||||
oss << std::round(mc.pm_01[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM2.5 atmospheric environment
|
||||
if (utils::isValidPm(mc.pm_25[0]) && utils::isValidPm(mc.pm_25[1])) {
|
||||
pm25 = ag->round2((mc.pm_25[0] + mc.pm_25[1]) / 2.0f);
|
||||
float pm25 = (mc.pm_25[0] + mc.pm_25[1]) / 2.0f;
|
||||
oss << std::round(pm25 * 10);
|
||||
} else if (utils::isValidPm(mc.pm_25[0])) {
|
||||
pm25 = ag->round2(mc.pm_25[0]);
|
||||
oss << std::round(mc.pm_25[0] * 10);
|
||||
} else if (utils::isValidPm(mc.pm_25[1])) {
|
||||
pm25 = ag->round2(mc.pm_25[1]);
|
||||
oss << std::round(mc.pm_25[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM10 atmospheric environment
|
||||
if (utils::isValidPm(mc.pm_10[0]) && utils::isValidPm(mc.pm_10[1])) {
|
||||
pm10 = ag->round2((mc.pm_10[0] + mc.pm_10[1]) / 2.0f);
|
||||
float pm10 = (mc.pm_10[0] + mc.pm_10[1]) / 2.0f;
|
||||
oss << std::round(pm10 * 10);
|
||||
} else if (utils::isValidPm(mc.pm_10[0])) {
|
||||
pm10 = ag->round2(mc.pm_10[0]);
|
||||
oss << std::round(mc.pm_10[0] * 10);
|
||||
} else if (utils::isValidPm(mc.pm_10[1])) {
|
||||
pm10 = ag->round2(mc.pm_10[1]);
|
||||
oss << std::round(mc.pm_10[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// NOx
|
||||
if (utils::isValidNOx(mc.nox)) {
|
||||
oss << std::round(mc.nox);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// TVOC
|
||||
if (utils::isValidVOC(mc.tvoc)) {
|
||||
oss << std::round(mc.tvoc);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM 0.3 particle count
|
||||
if (utils::isValidPm03Count(mc.pm_03_pc[0]) && utils::isValidPm03Count(mc.pm_03_pc[1])) {
|
||||
pm003Count = std::round((mc.pm_03_pc[0] + mc.pm_03_pc[1]) / 2.0f);
|
||||
oss << std::round((mc.pm_03_pc[0] + mc.pm_03_pc[1]) / 2.0f);
|
||||
} else if (utils::isValidPm03Count(mc.pm_03_pc[0])) {
|
||||
pm003Count = std::round(mc.pm_03_pc[0]);
|
||||
oss << std::round(mc.pm_03_pc[0]);
|
||||
} else if (utils::isValidPm03Count(mc.pm_03_pc[1])) {
|
||||
pm003Count = std::round(mc.pm_03_pc[1]);
|
||||
oss << std::round(mc.pm_03_pc[1]);
|
||||
}
|
||||
|
||||
char datapoint[128] = {0};
|
||||
Serial.printf(datapoint, 128, "%d,%.0f,%.0f,%.0f,%.0f,%.0f,%d,%d\n", co2,
|
||||
temp * 10, hum * 10, pm01 * 10, pm25 * 10, pm10 * 10, nox,
|
||||
pm003Count);
|
||||
snprintf(datapoint, 128, "%d,%.0f,%.0f,%.0f,%.0f,%.0f,%d,%d", co2, temp * 10,
|
||||
hum * 10, pm01 * 10, pm25 * 10, pm10 * 10, nox, pm003Count);
|
||||
// char datapoint[128] = {0};
|
||||
// snprintf(datapoint, 128, "%d,%.0f,%.0f,%.0f,%.0f,%.0f,%d,%d,%d", co2, temp * 10,
|
||||
// hum * 10, pm01 * 10, pm25 * 10, pm10 * 10, tvoc, nox, pm003Count);
|
||||
|
||||
return String(datapoint);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user