mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-17 02:32:09 +02:00
Merge branch 'develop' of https://github.com/airgradienthq/arduino into develop
This commit is contained in:
@ -78,7 +78,8 @@ static AirGradient *ag;
|
|||||||
static OledDisplay oledDisplay(configuration, measurements, Serial);
|
static OledDisplay oledDisplay(configuration, measurements, Serial);
|
||||||
static StateMachine stateMachine(oledDisplay, Serial, measurements,
|
static StateMachine stateMachine(oledDisplay, Serial, measurements,
|
||||||
configuration);
|
configuration);
|
||||||
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine, configuration);
|
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine,
|
||||||
|
configuration);
|
||||||
static OpenMetrics openMetrics(measurements, configuration, wifiConnector,
|
static OpenMetrics openMetrics(measurements, configuration, wifiConnector,
|
||||||
apiClient);
|
apiClient);
|
||||||
static OtaHandler otaHandler;
|
static OtaHandler otaHandler;
|
||||||
@ -110,6 +111,7 @@ static void initMqtt(void);
|
|||||||
static void factoryConfigReset(void);
|
static void factoryConfigReset(void);
|
||||||
static void wdgFeedUpdate(void);
|
static void wdgFeedUpdate(void);
|
||||||
static void ledBarEnabledUpdate(void);
|
static void ledBarEnabledUpdate(void);
|
||||||
|
static bool sgp41Init(void);
|
||||||
|
|
||||||
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, oledDisplayLedBarSchedule);
|
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, oledDisplayLedBarSchedule);
|
||||||
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
||||||
@ -308,7 +310,7 @@ static void createMqttTask(void) {
|
|||||||
/** Send data */
|
/** Send data */
|
||||||
if (mqttClient.isConnected()) {
|
if (mqttClient.isConnected()) {
|
||||||
String payload = measurements.toString(
|
String payload = measurements.toString(
|
||||||
false, fwMode, wifiConnector.RSSI(), ag, &configuration);
|
true, fwMode, wifiConnector.RSSI(), ag, &configuration);
|
||||||
String topic = "airgradient/readings/" + ag->deviceId();
|
String topic = "airgradient/readings/" + ag->deviceId();
|
||||||
|
|
||||||
if (mqttClient.publish(topic.c_str(), payload.c_str(),
|
if (mqttClient.publish(topic.c_str(), payload.c_str(),
|
||||||
@ -416,6 +418,20 @@ static void ledBarEnabledUpdate(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool sgp41Init(void) {
|
||||||
|
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||||
|
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||||
|
if (ag->sgp41.begin(Wire)) {
|
||||||
|
Serial.println("Init SGP41 success");
|
||||||
|
configuration.hasSensorSGP = true;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Serial.println("Init SGP41 failuire");
|
||||||
|
configuration.hasSensorSGP = false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void sendDataToAg() {
|
static void sendDataToAg() {
|
||||||
/** Change oledDisplay and led state */
|
/** Change oledDisplay and led state */
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
@ -484,11 +500,7 @@ static void oneIndoorInit(void) {
|
|||||||
ag->watchdog.begin();
|
ag->watchdog.begin();
|
||||||
|
|
||||||
/** Init sensor SGP41 */
|
/** Init sensor SGP41 */
|
||||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
if (sgp41Init() == false) {
|
||||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
|
||||||
if (ag->sgp41.begin(Wire) == false) {
|
|
||||||
Serial.println("SGP41 sensor not found");
|
|
||||||
configuration.hasSensorSGP = false;
|
|
||||||
dispSensorNotFound("SGP41");
|
dispSensorNotFound("SGP41");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,10 +582,7 @@ static void openAirInit(void) {
|
|||||||
serial1Available = false;
|
serial1Available = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
if (sgp41Init() == false) {
|
||||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
|
||||||
if (ag->sgp41.begin(Wire) == false) {
|
|
||||||
configuration.hasSensorSGP = false;
|
|
||||||
Serial.println("SGP sensor not found");
|
Serial.println("SGP sensor not found");
|
||||||
|
|
||||||
if (configuration.hasSensorS8 == false) {
|
if (configuration.hasSensorS8 == false) {
|
||||||
@ -648,6 +657,16 @@ static void boardInit(void) {
|
|||||||
} else {
|
} else {
|
||||||
openAirInit();
|
openAirInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set S8 CO2 abc days period */
|
||||||
|
if (configuration.hasSensorS8) {
|
||||||
|
if (ag->s8.setAbcPeriod(configuration.getCO2CalibrationAbcDays() * 24)) {
|
||||||
|
Serial.println("Set S8 AbcDays successful");
|
||||||
|
} else {
|
||||||
|
Serial.println("Set S8 AbcDays failure");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
localServer.setFwMode(fwMode);
|
localServer.setFwMode(fwMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,17 +701,23 @@ static void configUpdateHandle() {
|
|||||||
if (configuration.noxLearnOffsetChanged() ||
|
if (configuration.noxLearnOffsetChanged() ||
|
||||||
configuration.tvocLearnOffsetChanged()) {
|
configuration.tvocLearnOffsetChanged()) {
|
||||||
ag->sgp41.end();
|
ag->sgp41.end();
|
||||||
Serial.println("nox/tvoc learning offset changed");
|
|
||||||
Serial.println("noxLearningOffset: " + String(configuration.getNoxLearningOffset()));
|
int oldTvocOffset = ag->sgp41.getTvocLearningOffset();
|
||||||
Serial.println("tvocLearningOffset: " + String(configuration.getTvocLearningOffset()));
|
int oldNoxOffset = ag->sgp41.getNoxLearningOffset();
|
||||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
bool result = sgp41Init();
|
||||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
const char *resultStr = "successful";
|
||||||
if (ag->sgp41.begin(Wire)) {
|
if (!result) {
|
||||||
Serial.println("Init SGP41 success");
|
resultStr = "failure";
|
||||||
configuration.hasSensorSGP = true;
|
}
|
||||||
} else {
|
if (oldTvocOffset != configuration.getTvocLearningOffset()) {
|
||||||
Serial.println("Init SGP41 failuire");
|
Serial.printf("Setting tvocLearningOffset from %d to %d hours %s\r\n",
|
||||||
configuration.hasSensorSGP = false;
|
oldTvocOffset, configuration.getTvocLearningOffset(),
|
||||||
|
resultStr);
|
||||||
|
}
|
||||||
|
if (oldNoxOffset != configuration.getNoxLearningOffset()) {
|
||||||
|
Serial.printf("Setting noxLearningOffset from %d to %d hours %s\r\n",
|
||||||
|
oldNoxOffset, configuration.getNoxLearningOffset(),
|
||||||
|
resultStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,6 +820,10 @@ static void updatePm(void) {
|
|||||||
Serial.printf("[1] PM3.0 Count: %d\r\n", measurements.pm03PCount_1);
|
Serial.printf("[1] PM3.0 Count: %d\r\n", measurements.pm03PCount_1);
|
||||||
Serial.printf("[1] Temperature in C: %0.2f\r\n", measurements.temp_1);
|
Serial.printf("[1] Temperature in C: %0.2f\r\n", measurements.temp_1);
|
||||||
Serial.printf("[1] Relative Humidity: %d\r\n", measurements.hum_1);
|
Serial.printf("[1] Relative Humidity: %d\r\n", measurements.hum_1);
|
||||||
|
Serial.printf("[1] Temperature compensated in C: %0.2f\r\n",
|
||||||
|
ag->pms5003t_1.temperatureCompensated(measurements.temp_1));
|
||||||
|
Serial.printf("[1] Relative Humidity compensated: %d\r\n",
|
||||||
|
ag->pms5003t_1.humidityCompensated(measurements.hum_1));
|
||||||
} else {
|
} else {
|
||||||
measurements.pm01_1 = -1;
|
measurements.pm01_1 = -1;
|
||||||
measurements.pm25_1 = -1;
|
measurements.pm25_1 = -1;
|
||||||
@ -821,6 +850,10 @@ static void updatePm(void) {
|
|||||||
Serial.printf("[2] PM3.0 Count: %d\r\n", measurements.pm03PCount_2);
|
Serial.printf("[2] PM3.0 Count: %d\r\n", measurements.pm03PCount_2);
|
||||||
Serial.printf("[2] Temperature in C: %0.2f\r\n", measurements.temp_2);
|
Serial.printf("[2] Temperature in C: %0.2f\r\n", measurements.temp_2);
|
||||||
Serial.printf("[2] Relative Humidity: %d\r\n", measurements.hum_2);
|
Serial.printf("[2] Relative Humidity: %d\r\n", measurements.hum_2);
|
||||||
|
Serial.printf("[2] Temperature compensated in C: %0.2f\r\n",
|
||||||
|
ag->pms5003t_1.temperatureCompensated(measurements.temp_2));
|
||||||
|
Serial.printf("[2] Relative Humidity compensated: %d\r\n",
|
||||||
|
ag->pms5003t_1.humidityCompensated(measurements.hum_2));
|
||||||
} else {
|
} else {
|
||||||
measurements.pm01_2 = -1;
|
measurements.pm01_2 = -1;
|
||||||
measurements.pm25_2 = -1;
|
measurements.pm25_2 = -1;
|
||||||
@ -947,6 +980,10 @@ static void tempHumUpdate(void) {
|
|||||||
|
|
||||||
Serial.printf("Temperature in C: %0.2f\r\n", measurements.Temperature);
|
Serial.printf("Temperature in C: %0.2f\r\n", measurements.Temperature);
|
||||||
Serial.printf("Relative Humidity: %d\r\n", measurements.Humidity);
|
Serial.printf("Relative Humidity: %d\r\n", measurements.Humidity);
|
||||||
|
Serial.printf("Temperature compensated in C: %0.2f\r\n",
|
||||||
|
measurements.Temperature);
|
||||||
|
Serial.printf("Relative Humidity compensated: %d\r\n",
|
||||||
|
measurements.Humidity);
|
||||||
|
|
||||||
// Update compensation temperature and humidity for SGP41
|
// Update compensation temperature and humidity for SGP41
|
||||||
if (configuration.hasSensorSGP) {
|
if (configuration.hasSensorSGP) {
|
||||||
|
@ -179,7 +179,7 @@ String OpenMetrics::getPayload(void) {
|
|||||||
|
|
||||||
if (_temp > -1001) {
|
if (_temp > -1001) {
|
||||||
add_metric("temperature",
|
add_metric("temperature",
|
||||||
"The ambient temperature as measured by the AirGradient SHT "
|
"The ambient temperature as measured by the AirGradient SHT / PMS "
|
||||||
"sensor, in degrees Celsius",
|
"sensor, in degrees Celsius",
|
||||||
"gauge", "celsius");
|
"gauge", "celsius");
|
||||||
add_metric_point("", String(_temp));
|
add_metric_point("", String(_temp));
|
||||||
@ -187,21 +187,22 @@ String OpenMetrics::getPayload(void) {
|
|||||||
if (atmpCompensated > -1001) {
|
if (atmpCompensated > -1001) {
|
||||||
add_metric(
|
add_metric(
|
||||||
"temperature_compensated",
|
"temperature_compensated",
|
||||||
"The ambient temperature as measured by the AirGradient SHT / PMS",
|
"The compensated ambient temperature as measured by the AirGradient SHT / PMS "
|
||||||
|
"sensor, in degrees Celsius",
|
||||||
"gauge", "celsius");
|
"gauge", "celsius");
|
||||||
add_metric_point("", String(atmpCompensated));
|
add_metric_point("", String(atmpCompensated));
|
||||||
}
|
}
|
||||||
if (_hum >= 0) {
|
if (_hum >= 0) {
|
||||||
add_metric(
|
add_metric(
|
||||||
"humidity",
|
"humidity",
|
||||||
"The relative humidity as measured by the AirGradient SHT sensor",
|
"The relative humidity as measured by the AirGradient SHT sensor"
|
||||||
"gauge", "percent");
|
"gauge", "percent");
|
||||||
add_metric_point("", String(_hum));
|
add_metric_point("", String(_hum));
|
||||||
}
|
}
|
||||||
if (ahumCompensated >= 0) {
|
if (ahumCompensated >= 0) {
|
||||||
add_metric(
|
add_metric(
|
||||||
"humidity_compensated",
|
"humidity_compensated",
|
||||||
"The relative humidity as measured by the AirGradient SHT / PMS sensor",
|
"The compensated relative humidity as measured by the AirGradient SHT / PMS sensor",
|
||||||
"gauge", "percent");
|
"gauge", "percent");
|
||||||
add_metric_point("", String(ahumCompensated));
|
add_metric_point("", String(ahumCompensated));
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ void Configuration::loadConfig(void) {
|
|||||||
logError("Configure validate invalid");
|
logError("Configure validate invalid");
|
||||||
defaultConfig();
|
defaultConfig();
|
||||||
} else {
|
} else {
|
||||||
|
/** Correct configuration parameter value. */
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
if ((config.temperatureUnit != 'c') && (config.temperatureUnit != 'f')) {
|
if ((config.temperatureUnit != 'c') && (config.temperatureUnit != 'f')) {
|
||||||
config.temperatureUnit = 'c';
|
config.temperatureUnit = 'c';
|
||||||
@ -126,7 +127,7 @@ void Configuration::defaultConfig(void) {
|
|||||||
config.postDataToAirGradient = true;
|
config.postDataToAirGradient = true;
|
||||||
config.displayMode = true;
|
config.displayMode = true;
|
||||||
config.useRGBLedBar = LedBarMode::LedBarModeCO2;
|
config.useRGBLedBar = LedBarMode::LedBarModeCO2;
|
||||||
config.abcDays = 7;
|
config.abcDays = 8;
|
||||||
config.tvocLearningOffset = 12;
|
config.tvocLearningOffset = 12;
|
||||||
config.noxLearningOffset = 12;
|
config.noxLearningOffset = 12;
|
||||||
config.temperatureUnit = 'c';
|
config.temperatureUnit = 'c';
|
||||||
@ -178,6 +179,8 @@ bool Configuration::begin(void) {
|
|||||||
* @return false Failure
|
* @return false Failure
|
||||||
*/
|
*/
|
||||||
bool Configuration::parse(String data, bool isLocal) {
|
bool Configuration::parse(String data, bool isLocal) {
|
||||||
|
logInfo("Parse configure: " + data);
|
||||||
|
|
||||||
JSONVar root = JSON.parse(data);
|
JSONVar root = JSON.parse(data);
|
||||||
failedMessage = "";
|
failedMessage = "";
|
||||||
if (JSON.typeof_(root) == "undefined") {
|
if (JSON.typeof_(root) == "undefined") {
|
||||||
@ -192,32 +195,37 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
|
|
||||||
/** Get ConfigurationControl */
|
/** Get ConfigurationControl */
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
|
uint8_t configurationControl = config.configurationControl;
|
||||||
if (JSON.typeof_(root["configurationControl"]) == "string") {
|
if (JSON.typeof_(root["configurationControl"]) == "string") {
|
||||||
String configurationControl = root["configurationControl"];
|
String configurationControl = root["configurationControl"];
|
||||||
if (configurationControl ==
|
if (configurationControl !=
|
||||||
String(CONFIGURATION_CONTROL_NAME
|
String(CONFIGURATION_CONTROL_NAME[config.configurationControl])) {
|
||||||
[ConfigurationControl::ConfigurationControlLocal])) {
|
if (configurationControl ==
|
||||||
config.configurationControl =
|
String(CONFIGURATION_CONTROL_NAME
|
||||||
(uint8_t)ConfigurationControl::ConfigurationControlLocal;
|
[ConfigurationControl::ConfigurationControlLocal])) {
|
||||||
changed = true;
|
config.configurationControl =
|
||||||
} else if (configurationControl ==
|
(uint8_t)ConfigurationControl::ConfigurationControlLocal;
|
||||||
String(
|
changed = true;
|
||||||
CONFIGURATION_CONTROL_NAME
|
} else if (configurationControl ==
|
||||||
[ConfigurationControl::ConfigurationControlCloud])) {
|
String(
|
||||||
config.configurationControl =
|
CONFIGURATION_CONTROL_NAME
|
||||||
(uint8_t)ConfigurationControl::ConfigurationControlCloud;
|
[ConfigurationControl::ConfigurationControlCloud])) {
|
||||||
changed = true;
|
config.configurationControl =
|
||||||
} else if (configurationControl ==
|
(uint8_t)ConfigurationControl::ConfigurationControlCloud;
|
||||||
String(CONFIGURATION_CONTROL_NAME
|
changed = true;
|
||||||
[ConfigurationControl::ConfigurationControlBoth])) {
|
} else if (configurationControl ==
|
||||||
config.configurationControl =
|
String(
|
||||||
(uint8_t)ConfigurationControl::ConfigurationControlBoth;
|
CONFIGURATION_CONTROL_NAME
|
||||||
changed = true;
|
[ConfigurationControl::ConfigurationControlBoth])) {
|
||||||
} else {
|
config.configurationControl =
|
||||||
failedMessage = jsonValueInvalidMessage("configurationControl",
|
(uint8_t)ConfigurationControl::ConfigurationControlBoth;
|
||||||
configurationControl);
|
changed = true;
|
||||||
jsonInvalid();
|
} else {
|
||||||
return false;
|
failedMessage = jsonValueInvalidMessage("configurationControl",
|
||||||
|
configurationControl);
|
||||||
|
jsonInvalid();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["configurationControl"], "string")) {
|
if (jsonTypeInvalid(root["configurationControl"], "string")) {
|
||||||
@ -228,6 +236,15 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
changed = false;
|
||||||
|
saveConfig();
|
||||||
|
configLogInfo(
|
||||||
|
"configurationControl",
|
||||||
|
String(CONFIGURATION_CONTROL_NAME[configurationControl]),
|
||||||
|
String(CONFIGURATION_CONTROL_NAME[config.configurationControl]));
|
||||||
|
}
|
||||||
|
|
||||||
if ((config.configurationControl ==
|
if ((config.configurationControl ==
|
||||||
(byte)ConfigurationControl::ConfigurationControlCloud)) {
|
(byte)ConfigurationControl::ConfigurationControlCloud)) {
|
||||||
failedMessage = "Local configure ignored";
|
failedMessage = "Local configure ignored";
|
||||||
@ -249,17 +266,8 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (country.length() == 2) {
|
if (country.length() == 2) {
|
||||||
if (country != String(config.country)) {
|
if (country != String(config.country)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
configLogInfo("country", String(config.country), country);
|
||||||
snprintf(config.country, sizeof(config.country), country.c_str());
|
snprintf(config.country, sizeof(config.country), country.c_str());
|
||||||
logInfo(String("Set country: " + country).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update temperature unit if get configuration from server
|
|
||||||
if (isLocal == false) {
|
|
||||||
if (country == "US") {
|
|
||||||
temperatureUnit = 'f';
|
|
||||||
} else {
|
|
||||||
temperatureUnit = 'c';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
failedMessage = "Country name " + country +
|
failedMessage = "Country name " + country +
|
||||||
@ -279,9 +287,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (JSON.typeof_(root["pmStandard"]) == "string") {
|
if (JSON.typeof_(root["pmStandard"]) == "string") {
|
||||||
String pmStandard = root["pmStandard"];
|
String pmStandard = root["pmStandard"];
|
||||||
bool inUSAQI = true;
|
bool inUSAQI = true;
|
||||||
if (pmStandard == "ugm3") {
|
if (pmStandard == getPMStandardString(false)) {
|
||||||
inUSAQI = false;
|
inUSAQI = false;
|
||||||
} else if (pmStandard == "us-aqi") {
|
} else if (pmStandard == getPMStandardString(true)) {
|
||||||
inUSAQI = true;
|
inUSAQI = true;
|
||||||
} else {
|
} else {
|
||||||
failedMessage = jsonValueInvalidMessage("pmStandard", pmStandard);
|
failedMessage = jsonValueInvalidMessage("pmStandard", pmStandard);
|
||||||
@ -290,9 +298,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inUSAQI != config.inUSAQI) {
|
if (inUSAQI != config.inUSAQI) {
|
||||||
|
configLogInfo("pmStandard", getPMStandardString(config.inUSAQI), pmStandard);
|
||||||
config.inUSAQI = inUSAQI;
|
config.inUSAQI = inUSAQI;
|
||||||
changed = true;
|
changed = true;
|
||||||
logInfo("Set PM standard: " + pmStandard);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["pmStandard"], "string")) {
|
if (jsonTypeInvalid(root["pmStandard"], "string")) {
|
||||||
@ -304,7 +312,10 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
|
|
||||||
if (JSON.typeof_(root["co2CalibrationRequested"]) == "boolean") {
|
if (JSON.typeof_(root["co2CalibrationRequested"]) == "boolean") {
|
||||||
co2CalibrationRequested = root["co2CalibrationRequested"];
|
co2CalibrationRequested = root["co2CalibrationRequested"];
|
||||||
logInfo("Set co2CalibrationRequested: " + String(co2CalibrationRequested));
|
if(co2CalibrationRequested) {
|
||||||
|
logInfo("co2CalibrationRequested: " +
|
||||||
|
String(co2CalibrationRequested ? "True" : "False"));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["co2CalibrationRequested"], "boolean")) {
|
if (jsonTypeInvalid(root["co2CalibrationRequested"], "boolean")) {
|
||||||
failedMessage =
|
failedMessage =
|
||||||
@ -316,7 +327,10 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
|
|
||||||
if (JSON.typeof_(root["ledBarTestRequested"]) == "boolean") {
|
if (JSON.typeof_(root["ledBarTestRequested"]) == "boolean") {
|
||||||
ledBarTestRequested = root["ledBarTestRequested"];
|
ledBarTestRequested = root["ledBarTestRequested"];
|
||||||
logInfo("Set ledBarTestRequested: " + String(ledBarTestRequested));
|
if(ledBarTestRequested){
|
||||||
|
logInfo("ledBarTestRequested: " +
|
||||||
|
String(ledBarTestRequested ? "True" : "False"));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["ledBarTestRequested"], "boolean")) {
|
if (jsonTypeInvalid(root["ledBarTestRequested"], "boolean")) {
|
||||||
failedMessage = jsonTypeInvalidMessage("ledBarTestRequested", "boolean");
|
failedMessage = jsonTypeInvalidMessage("ledBarTestRequested", "boolean");
|
||||||
@ -341,9 +355,11 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ledBarMode != config.useRGBLedBar) {
|
if (ledBarMode != config.useRGBLedBar) {
|
||||||
|
configLogInfo("useRGBLedBar",
|
||||||
|
String(LED_BAR_MODE_NAMES[config.useRGBLedBar]),
|
||||||
|
String(LED_BAR_MODE_NAMES[ledBarMode]));
|
||||||
config.useRGBLedBar = ledBarMode;
|
config.useRGBLedBar = ledBarMode;
|
||||||
changed = true;
|
changed = true;
|
||||||
logInfo("Set ledBarMode: " + mode);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["ledBarMode"], "string")) {
|
if (jsonTypeInvalid(root["ledBarMode"], "string")) {
|
||||||
@ -356,9 +372,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (JSON.typeof_(root["displayMode"]) == "string") {
|
if (JSON.typeof_(root["displayMode"]) == "string") {
|
||||||
String mode = root["displayMode"];
|
String mode = root["displayMode"];
|
||||||
bool displayMode = false;
|
bool displayMode = false;
|
||||||
if (mode == "on") {
|
if (mode == getDisplayModeString(true)) {
|
||||||
displayMode = true;
|
displayMode = true;
|
||||||
} else if (mode == "off") {
|
} else if (mode == getDisplayModeString(false)) {
|
||||||
displayMode = false;
|
displayMode = false;
|
||||||
} else {
|
} else {
|
||||||
failedMessage = jsonTypeInvalidMessage("displayMode", mode);
|
failedMessage = jsonTypeInvalidMessage("displayMode", mode);
|
||||||
@ -368,8 +384,8 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
|
|
||||||
if (displayMode != config.displayMode) {
|
if (displayMode != config.displayMode) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
configLogInfo("displayMode", getDisplayModeString(config.displayMode), mode);
|
||||||
config.displayMode = displayMode;
|
config.displayMode = displayMode;
|
||||||
logInfo("Set displayMode: " + mode);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["displayMode"], "string")) {
|
if (jsonTypeInvalid(root["displayMode"], "string")) {
|
||||||
@ -382,14 +398,14 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (JSON.typeof_(root["abcDays"]) == "number") {
|
if (JSON.typeof_(root["abcDays"]) == "number") {
|
||||||
int abcDays = root["abcDays"];
|
int abcDays = root["abcDays"];
|
||||||
if (abcDays <= 0) {
|
if (abcDays <= 0) {
|
||||||
failedMessage = jsonTypeInvalidMessage("abcDaysabcDays", String(abcDays));
|
abcDays = 0;
|
||||||
jsonInvalid();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (abcDays != config.abcDays) {
|
if (abcDays != config.abcDays) {
|
||||||
|
logInfo("Set abcDays: " + String(abcDays));
|
||||||
|
configLogInfo("abcDays", getAbcDayString(config.abcDays),
|
||||||
|
String(getAbcDayString(abcDays)));
|
||||||
config.abcDays = abcDays;
|
config.abcDays = abcDays;
|
||||||
changed = true;
|
changed = true;
|
||||||
logInfo("Set abcDays: " + String(abcDays));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["abcDays"], "number")) {
|
if (jsonTypeInvalid(root["abcDays"], "number")) {
|
||||||
@ -399,13 +415,15 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tvocLearningOffsetChanged = false;
|
||||||
if (JSON.typeof_(root["tvocLearningOffset"]) == "number") {
|
if (JSON.typeof_(root["tvocLearningOffset"]) == "number") {
|
||||||
int tvocLearningOffset = root["tvocLearningOffset"];
|
int tvocLearningOffset = root["tvocLearningOffset"];
|
||||||
if (tvocLearningOffset != config.tvocLearningOffset) {
|
if (tvocLearningOffset != config.tvocLearningOffset) {
|
||||||
changed = true;
|
changed = true;
|
||||||
_tvocLearningOffsetChanged = true;
|
_tvocLearningOffsetChanged = true;
|
||||||
|
configLogInfo("tvocLearningOffset", String(config.tvocLearningOffset),
|
||||||
|
String(tvocLearningOffset));
|
||||||
config.tvocLearningOffset = tvocLearningOffset;
|
config.tvocLearningOffset = tvocLearningOffset;
|
||||||
logInfo("Set tvocLearningOffset: " + String(tvocLearningOffset));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["tvocLearningOffset"], "number")) {
|
if (jsonTypeInvalid(root["tvocLearningOffset"], "number")) {
|
||||||
@ -415,13 +433,15 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_noxLearnOffsetChanged = false;
|
||||||
if (JSON.typeof_(root["noxLearningOffset"]) == "number") {
|
if (JSON.typeof_(root["noxLearningOffset"]) == "number") {
|
||||||
int noxLearningOffset = root["noxLearningOffset"];
|
int noxLearningOffset = root["noxLearningOffset"];
|
||||||
if (noxLearningOffset != config.noxLearningOffset) {
|
if (noxLearningOffset != config.noxLearningOffset) {
|
||||||
changed = true;
|
changed = true;
|
||||||
_noxLearnOffsetChanged = true;
|
_noxLearnOffsetChanged = true;
|
||||||
|
configLogInfo("noxLearningOffset", String(config.noxLearningOffset),
|
||||||
|
String(noxLearningOffset));
|
||||||
config.noxLearningOffset = noxLearningOffset;
|
config.noxLearningOffset = noxLearningOffset;
|
||||||
logInfo("Set noxLearningOffset: " + String(noxLearningOffset));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (jsonTypeInvalid(root["noxLearningOffset"], "number")) {
|
if (jsonTypeInvalid(root["noxLearningOffset"], "number")) {
|
||||||
@ -436,8 +456,8 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (broker.length() < sizeof(config.mqttBroker)) {
|
if (broker.length() < sizeof(config.mqttBroker)) {
|
||||||
if (broker != String(config.mqttBroker)) {
|
if (broker != String(config.mqttBroker)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
configLogInfo("mqttBrokerUrl", String(config.mqttBroker), broker);
|
||||||
snprintf(config.mqttBroker, sizeof(config.mqttBroker), broker.c_str());
|
snprintf(config.mqttBroker, sizeof(config.mqttBroker), broker.c_str());
|
||||||
logInfo("Set mqttBrokerUrl: " + broker);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
failedMessage =
|
failedMessage =
|
||||||
@ -456,9 +476,9 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (JSON.typeof_(root["temperatureUnit"]) == "string") {
|
if (JSON.typeof_(root["temperatureUnit"]) == "string") {
|
||||||
String unit = root["temperatureUnit"];
|
String unit = root["temperatureUnit"];
|
||||||
unit.toLowerCase();
|
unit.toLowerCase();
|
||||||
if (unit == "c") {
|
if ((unit == "c") || (unit == "celsius")) {
|
||||||
temperatureUnit = 'c';
|
temperatureUnit = 'c';
|
||||||
} else if (unit == "f") {
|
} else if ((unit == "f") || (unit == "fahrenheit")) {
|
||||||
temperatureUnit = 'f';
|
temperatureUnit = 'f';
|
||||||
} else {
|
} else {
|
||||||
failedMessage = "'temperatureUnit' value '" + unit + "' invalid";
|
failedMessage = "'temperatureUnit' value '" + unit + "' invalid";
|
||||||
@ -475,23 +495,28 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
|
|
||||||
if (temperatureUnit != 0 && temperatureUnit != config.temperatureUnit) {
|
if (temperatureUnit != 0 && temperatureUnit != config.temperatureUnit) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
configLogInfo("temperatureUnit", String(config.temperatureUnit),
|
||||||
|
String(temperatureUnit));
|
||||||
config.temperatureUnit = temperatureUnit;
|
config.temperatureUnit = temperatureUnit;
|
||||||
logInfo("set temperatureUnit: " + String(temperatureUnit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JSON.typeof_(root["postDataToAirGradient"]) == "boolean") {
|
if (isLocal) {
|
||||||
bool post = root["postDataToAirGradient"];
|
if (JSON.typeof_(root["postDataToAirGradient"]) == "boolean") {
|
||||||
if (post != config.postDataToAirGradient) {
|
bool post = root["postDataToAirGradient"];
|
||||||
changed = true;
|
if (post != config.postDataToAirGradient) {
|
||||||
config.postDataToAirGradient = post;
|
changed = true;
|
||||||
logInfo("Set postDataToAirGradient: " + String(post));
|
configLogInfo("postDataToAirGradient",
|
||||||
}
|
String(config.postDataToAirGradient ? "true" : "false"),
|
||||||
} else {
|
String(post ? "true" : "false"));
|
||||||
if (jsonTypeInvalid(root["postDataToAirGradient"], "boolean")) {
|
config.postDataToAirGradient = post;
|
||||||
failedMessage =
|
}
|
||||||
jsonTypeInvalidMessage("postDataToAirGradient", "boolean");
|
} else {
|
||||||
jsonInvalid();
|
if (jsonTypeInvalid(root["postDataToAirGradient"], "boolean")) {
|
||||||
return false;
|
failedMessage =
|
||||||
|
jsonTypeInvalidMessage("postDataToAirGradient", "boolean");
|
||||||
|
jsonInvalid();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,6 +527,7 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (model.length() < sizeof(config.model)) {
|
if (model.length() < sizeof(config.model)) {
|
||||||
if (model != String(config.model)) {
|
if (model != String(config.model)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
configLogInfo("model", String(config.model), model);
|
||||||
snprintf(config.model, sizeof(config.model), model.c_str());
|
snprintf(config.model, sizeof(config.model), model.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -522,8 +548,13 @@ bool Configuration::parse(String data, bool isLocal) {
|
|||||||
if (changed) {
|
if (changed) {
|
||||||
udpated = true;
|
udpated = true;
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
printConfig();
|
||||||
|
} else {
|
||||||
|
logInfo("Nothing changed ignore udpate");
|
||||||
|
if (ledBarTestRequested || co2CalibrationRequested) {
|
||||||
|
udpated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printConfig();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,11 +570,7 @@ String Configuration::toString(void) {
|
|||||||
root["country"] = String(config.country);
|
root["country"] = String(config.country);
|
||||||
|
|
||||||
/** "pmStandard" */
|
/** "pmStandard" */
|
||||||
if (config.inUSAQI) {
|
root["pmStandard"] = getPMStandardString(config.inUSAQI);
|
||||||
root["pmStandard"] = "us-aqi";
|
|
||||||
} else {
|
|
||||||
root["pmStandard"] = "ugm3";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** co2CalibrationRequested */
|
/** co2CalibrationRequested */
|
||||||
/** ledBarTestRequested */
|
/** ledBarTestRequested */
|
||||||
@ -730,6 +757,33 @@ void Configuration::jsonInvalid(void) {
|
|||||||
logError(failedMessage);
|
logError(failedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Configuration::configLogInfo(String name, String fromValue,
|
||||||
|
String toValue) {
|
||||||
|
logInfo(String("Setting '") + name + String("' from '") + fromValue +
|
||||||
|
String("' to '") + toValue + String("'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
String Configuration::getPMStandardString(bool usaqi) {
|
||||||
|
if (usaqi) {
|
||||||
|
return "us-aqi";
|
||||||
|
}
|
||||||
|
return "ugm3";
|
||||||
|
}
|
||||||
|
|
||||||
|
String Configuration::getDisplayModeString(bool dispMode) {
|
||||||
|
if(dispMode){
|
||||||
|
return String("on");
|
||||||
|
}
|
||||||
|
return String("off");
|
||||||
|
}
|
||||||
|
|
||||||
|
String Configuration::getAbcDayString(int value) {
|
||||||
|
if(value <= 0){
|
||||||
|
return String("off");
|
||||||
|
}
|
||||||
|
return String(value);
|
||||||
|
}
|
||||||
|
|
||||||
String Configuration::getFailedMesage(void) { return failedMessage; }
|
String Configuration::getFailedMesage(void) { return failedMessage; }
|
||||||
|
|
||||||
void Configuration::setPostToAirGradient(bool enable) {
|
void Configuration::setPostToAirGradient(bool enable) {
|
||||||
|
@ -44,6 +44,10 @@ private:
|
|||||||
String jsonTypeInvalidMessage(String name, String type);
|
String jsonTypeInvalidMessage(String name, String type);
|
||||||
String jsonValueInvalidMessage(String name, String value);
|
String jsonValueInvalidMessage(String name, String value);
|
||||||
void jsonInvalid(void);
|
void jsonInvalid(void);
|
||||||
|
void configLogInfo(String name, String fromValue, String toValue);
|
||||||
|
String getPMStandardString(bool usaqi);
|
||||||
|
String getDisplayModeString(bool dispMode);
|
||||||
|
String getAbcDayString(int value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Configuration(Stream &debugLog);
|
Configuration(Stream &debugLog);
|
||||||
|
@ -276,22 +276,24 @@ void StateMachine::co2Calibration(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.getCO2CalibrationAbcDays() > 0 && config.hasSensorS8) {
|
if (config.getCO2CalibrationAbcDays() >= 0 && config.hasSensorS8) {
|
||||||
int newHour = config.getCO2CalibrationAbcDays() * 24;
|
int newHour = config.getCO2CalibrationAbcDays() * 24;
|
||||||
logInfo("Requested abcDays setting: " +
|
|
||||||
String(config.getCO2CalibrationAbcDays()) + "days (" +
|
|
||||||
String(newHour) + "hours)");
|
|
||||||
int curHour = ag->s8.getAbcPeriod();
|
int curHour = ag->s8.getAbcPeriod();
|
||||||
logInfo("Current S8 abcDays setting: " + String(curHour) + "(hours)");
|
if (curHour != newHour) {
|
||||||
if (curHour == newHour) {
|
String resultStr = "failure";
|
||||||
logInfo("'abcDays' unchanged");
|
if (ag->s8.setAbcPeriod(config.getCO2CalibrationAbcDays() * 24)) {
|
||||||
} else {
|
resultStr = "successful";
|
||||||
if (ag->s8.setAbcPeriod(config.getCO2CalibrationAbcDays() * 24) ==
|
|
||||||
false) {
|
|
||||||
logError("Set S8 abcDays period failed");
|
|
||||||
} else {
|
|
||||||
logInfo("Set S8 abcDays period success");
|
|
||||||
}
|
}
|
||||||
|
String fromStr = String(curHour/24) + " days";
|
||||||
|
if(curHour == 0){
|
||||||
|
fromStr = "off";
|
||||||
|
}
|
||||||
|
String toStr = String(config.getCO2CalibrationAbcDays()) + " days";
|
||||||
|
if(config.getCO2CalibrationAbcDays() == 0) {
|
||||||
|
toStr = "off";
|
||||||
|
}
|
||||||
|
String msg = "Setting S8 from " + fromStr + " to " + toStr + " " + resultStr;
|
||||||
|
logInfo(msg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logWarning("CO2 S8 not available, set 'abcDays' ignored");
|
logWarning("CO2 S8 not available, set 'abcDays' ignored");
|
||||||
|
@ -46,6 +46,7 @@ bool WifiConnector::connect(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WIFI()->setConfigPortalBlocking(false);
|
WIFI()->setConfigPortalBlocking(false);
|
||||||
|
WIFI()->setConnectTimeout(15);
|
||||||
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
@ -148,9 +149,15 @@ bool WifiConnector::connect(void) {
|
|||||||
hasConfig = true;
|
hasConfig = true;
|
||||||
logInfo("WiFi Connected: " + WiFi.SSID() + " IP: " + localIpStr());
|
logInfo("WiFi Connected: " + WiFi.SSID() + " IP: " + localIpStr());
|
||||||
|
|
||||||
String result = String(postToAg.getValue());
|
if (hasPortalConfig) {
|
||||||
logInfo("Post to AirGradient Configure: " + result);
|
String result = String(postToAg.getValue());
|
||||||
config.setPostToAirGradient(result != "T");
|
logInfo("Setting postToAirGradient set from " +
|
||||||
|
String(config.isPostDataToAirGradient() ? "True" : "False") +
|
||||||
|
String(" to ") + String(result != "T" ? "True" : "False") +
|
||||||
|
String(" successful"));
|
||||||
|
config.setPostToAirGradient(result != "T");
|
||||||
|
}
|
||||||
|
hasPortalConfig = false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
_wifiProcess();
|
_wifiProcess();
|
||||||
@ -226,6 +233,7 @@ void WifiConnector::_wifiSaveParamCallback(void) {
|
|||||||
sm.ledAnimationInit();
|
sm.ledAnimationInit();
|
||||||
sm.handleLeds(AgStateMachineWiFiManagerStaConnecting);
|
sm.handleLeds(AgStateMachineWiFiManagerStaConnecting);
|
||||||
sm.setDisplayState(AgStateMachineWiFiManagerStaConnecting);
|
sm.setDisplayState(AgStateMachineWiFiManagerStaConnecting);
|
||||||
|
hasPortalConfig = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,7 @@ private:
|
|||||||
void *wifi = NULL;
|
void *wifi = NULL;
|
||||||
bool hasConfig;
|
bool hasConfig;
|
||||||
uint32_t lastRetry;
|
uint32_t lastRetry;
|
||||||
|
bool hasPortalConfig = false;
|
||||||
|
|
||||||
bool wifiClientConnected(void);
|
bool wifiClientConnected(void);
|
||||||
|
|
||||||
|
@ -202,18 +202,3 @@ void PMS5003T::handle(void) { pms.handle(); }
|
|||||||
*/
|
*/
|
||||||
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
|
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
|
||||||
|
|
||||||
float PMS5003T::temperatureCompensated(float temp) {
|
|
||||||
if (temp < 10.0f) {
|
|
||||||
return temp * 1.327f - 6.738f;
|
|
||||||
}
|
|
||||||
return temp * 1.181f - 5.113f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float PMS5003T::humidityCompensated(float hum) {
|
|
||||||
hum = hum * 1.259f + 7.34f;
|
|
||||||
|
|
||||||
if (hum > 100.0f) {
|
|
||||||
hum = 100.0f;
|
|
||||||
}
|
|
||||||
return hum;
|
|
||||||
}
|
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
#include "../Main/BoardDef.h"
|
#include "../Main/BoardDef.h"
|
||||||
#include "PMS.h"
|
#include "PMS.h"
|
||||||
|
#include "PMS5003TBase.h"
|
||||||
#include "Stream.h"
|
#include "Stream.h"
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The class define how to handle PMS5003T sensor bas on @ref PMS class
|
* @brief The class define how to handle PMS5003T sensor bas on @ref PMS class
|
||||||
*/
|
*/
|
||||||
class PMS5003T {
|
class PMS5003T: public PMS5003TBase {
|
||||||
public:
|
public:
|
||||||
PMS5003T(BoardType def);
|
PMS5003T(BoardType def);
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@ -28,8 +29,6 @@ public:
|
|||||||
int convertPm25ToUsAqi(int pm25);
|
int convertPm25ToUsAqi(int pm25);
|
||||||
float getTemperature(void);
|
float getTemperature(void);
|
||||||
float getRelativeHumidity(void);
|
float getRelativeHumidity(void);
|
||||||
float temperatureCompensated(float temp);
|
|
||||||
float humidityCompensated(float hum);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isBegin = false;
|
bool _isBegin = false;
|
||||||
|
21
src/PMS/PMS5003TBase.cpp
Normal file
21
src/PMS/PMS5003TBase.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "PMS5003TBase.h"
|
||||||
|
|
||||||
|
PMS5003TBase::PMS5003TBase() {}
|
||||||
|
|
||||||
|
PMS5003TBase::~PMS5003TBase() {}
|
||||||
|
|
||||||
|
float PMS5003TBase::temperatureCompensated(float temp) {
|
||||||
|
if (temp < 10.0f) {
|
||||||
|
return temp * 1.327f - 6.738f;
|
||||||
|
}
|
||||||
|
return temp * 1.181f - 5.113f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float PMS5003TBase::humidityCompensated(float hum) {
|
||||||
|
hum = hum * 1.259f + 7.34f;
|
||||||
|
|
||||||
|
if (hum > 100.0f) {
|
||||||
|
hum = 100.0f;
|
||||||
|
}
|
||||||
|
return hum;
|
||||||
|
}
|
15
src/PMS/PMS5003TBase.h
Normal file
15
src/PMS/PMS5003TBase.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef _PMS5003T_BASE_H_
|
||||||
|
#define _PMS5003T_BASE_H_
|
||||||
|
|
||||||
|
class PMS5003TBase
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
public:
|
||||||
|
PMS5003TBase();
|
||||||
|
~PMS5003TBase();
|
||||||
|
float temperatureCompensated(float temp);
|
||||||
|
float humidityCompensated(float hum);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -293,3 +293,7 @@ void Sgp41::setNoxLearningOffset(int offset) {
|
|||||||
void Sgp41::setTvocLearningOffset(int offset) {
|
void Sgp41::setTvocLearningOffset(int offset) {
|
||||||
tvocLearnOffset = offset;
|
tvocLearnOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Sgp41::getNoxLearningOffset(void) { return noxLearnOffset; }
|
||||||
|
|
||||||
|
int Sgp41::getTvocLearningOffset(void) { return tvocLearnOffset; }
|
||||||
|
@ -28,6 +28,8 @@ public:
|
|||||||
void setCompensationTemperatureHumidity(float temp, float hum);
|
void setCompensationTemperatureHumidity(float temp, float hum);
|
||||||
void setNoxLearningOffset(int offset);
|
void setNoxLearningOffset(int offset);
|
||||||
void setTvocLearningOffset(int offset);
|
void setTvocLearningOffset(int offset);
|
||||||
|
int getNoxLearningOffset(void);
|
||||||
|
int getTvocLearningOffset(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool onConditioning = true;
|
bool onConditioning = true;
|
||||||
|
Reference in New Issue
Block a user