mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-26 23:17:16 +02:00
Apply temphum correction
This commit is contained in:
@ -137,11 +137,15 @@ String OpenMetrics::getPayload(void) {
|
|||||||
|
|
||||||
/** Get temperature and humidity compensated */
|
/** Get temperature and humidity compensated */
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
atmpCompensated = _temp;
|
atmpCompensated = round(measure.getCorrectedTempHum(Measurements::Temperature));
|
||||||
ahumCompensated = _hum;
|
ahumCompensated = round(measure.getCorrectedTempHum(Measurements::Humidity));
|
||||||
} else {
|
} else {
|
||||||
atmpCompensated = ag->pms5003t_1.compensateTemp(_temp);
|
atmpCompensated = round((measure.getCorrectedTempHum(Measurements::Temperature, 1) +
|
||||||
ahumCompensated = ag->pms5003t_1.compensateHum(_hum);
|
measure.getCorrectedTempHum(Measurements::Temperature, 2)) /
|
||||||
|
2.0f);
|
||||||
|
ahumCompensated = round((measure.getCorrectedTempHum(Measurements::Humidity, 1) +
|
||||||
|
measure.getCorrectedTempHum(Measurements::Humidity, 2)) /
|
||||||
|
2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add measurements that valid to the metrics
|
// Add measurements that valid to the metrics
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
|
void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
|
||||||
/** Temperature */
|
/** Temperature */
|
||||||
float temp = value.getAverage(Measurements::Temperature);
|
float temp = value.getCorrectedTempHum(Measurements::Temperature, 1);
|
||||||
if (utils::isValidTemperature(temp)) {
|
if (utils::isValidTemperature(temp)) {
|
||||||
float t = 0.0f;
|
float t = 0.0f;
|
||||||
if (config.isTemperatureUnitInF()) {
|
if (config.isTemperatureUnitInF()) {
|
||||||
@ -44,7 +44,7 @@ void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
|
|||||||
DISP()->drawUTF8(1, 10, buf);
|
DISP()->drawUTF8(1, 10, buf);
|
||||||
|
|
||||||
/** Show humidity */
|
/** Show humidity */
|
||||||
int rhum = round(value.getAverage(Measurements::Humidity));
|
int rhum = round(value.getCorrectedTempHum(Measurements::Humidity, 1));
|
||||||
if (utils::isValidHumidity(rhum)) {
|
if (utils::isValidHumidity(rhum)) {
|
||||||
snprintf(buf, buf_size, "%d%%", rhum);
|
snprintf(buf, buf_size, "%d%%", rhum);
|
||||||
} else {
|
} else {
|
||||||
@ -389,7 +389,7 @@ void OledDisplay::showDashboard(const char *status) {
|
|||||||
ag->display.setText(strBuf);
|
ag->display.setText(strBuf);
|
||||||
|
|
||||||
/** Set temperature and humidity */
|
/** Set temperature and humidity */
|
||||||
float temp = value.getAverage(Measurements::Temperature);
|
float temp = value.getCorrectedTempHum(Measurements::Temperature, 1);
|
||||||
if (utils::isValidTemperature(temp)) {
|
if (utils::isValidTemperature(temp)) {
|
||||||
if (config.isTemperatureUnitInF()) {
|
if (config.isTemperatureUnitInF()) {
|
||||||
snprintf(strBuf, sizeof(strBuf), "T:%0.1f F", utils::degreeC_To_F(temp));
|
snprintf(strBuf, sizeof(strBuf), "T:%0.1f F", utils::degreeC_To_F(temp));
|
||||||
@ -407,7 +407,7 @@ void OledDisplay::showDashboard(const char *status) {
|
|||||||
ag->display.setCursor(0, 24);
|
ag->display.setCursor(0, 24);
|
||||||
ag->display.setText(strBuf);
|
ag->display.setText(strBuf);
|
||||||
|
|
||||||
int rhum = round(value.getAverage(Measurements::Humidity));
|
int rhum = round(value.getCorrectedTempHum(Measurements::Humidity, 1));
|
||||||
if (utils::isValidHumidity(rhum)) {
|
if (utils::isValidHumidity(rhum)) {
|
||||||
snprintf(strBuf, sizeof(strBuf), "H:%d %%", rhum);
|
snprintf(strBuf, sizeof(strBuf), "H:%d %%", rhum);
|
||||||
} else {
|
} else {
|
||||||
|
@ -551,9 +551,12 @@ float Measurements::getCorrectedTempHum(MeasurementType type, int ch, bool force
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case Temperature: {
|
case Temperature: {
|
||||||
rawValue = _temperature[ch].update.avg;
|
rawValue = _temperature[ch].update.avg;
|
||||||
|
|
||||||
Configuration::TempHumCorrection tmp = config.getTempCorrection();
|
Configuration::TempHumCorrection tmp = config.getTempCorrection();
|
||||||
if (tmp.algorithm == TempHumCorrectionAlgorithm::CA_TH_AG_PMS5003T_2024 || forceCorrection) {
|
|
||||||
|
// Apply 'standard' correction if its defined or correction forced
|
||||||
|
if (tmp.algorithm == TempHumCorrectionAlgorithm::CA_TH_AG_PMS5003T_2024) {
|
||||||
|
return ag->pms5003t_1.compensateTemp(rawValue);
|
||||||
|
} else if (tmp.algorithm == TempHumCorrectionAlgorithm::CA_TH_NONE && forceCorrection) {
|
||||||
return ag->pms5003t_1.compensateTemp(rawValue);
|
return ag->pms5003t_1.compensateTemp(rawValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,9 +567,12 @@ float Measurements::getCorrectedTempHum(MeasurementType type, int ch, bool force
|
|||||||
}
|
}
|
||||||
case Humidity: {
|
case Humidity: {
|
||||||
rawValue = _humidity[ch].update.avg;
|
rawValue = _humidity[ch].update.avg;
|
||||||
|
|
||||||
Configuration::TempHumCorrection tmp = config.getHumCorrection();
|
Configuration::TempHumCorrection tmp = config.getHumCorrection();
|
||||||
if (tmp.algorithm == TempHumCorrectionAlgorithm::CA_TH_AG_PMS5003T_2024 || forceCorrection) {
|
|
||||||
|
// Apply 'standard' correction if its defined or correction forced
|
||||||
|
if (tmp.algorithm == TempHumCorrectionAlgorithm::CA_TH_AG_PMS5003T_2024) {
|
||||||
|
return ag->pms5003t_1.compensateHum(rawValue);
|
||||||
|
} else if (tmp.algorithm == TempHumCorrectionAlgorithm::CA_TH_NONE && forceCorrection) {
|
||||||
return ag->pms5003t_1.compensateHum(rawValue);
|
return ag->pms5003t_1.compensateHum(rawValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,6 +595,7 @@ float Measurements::getCorrectedTempHum(MeasurementType type, int ch, bool force
|
|||||||
|
|
||||||
// Custom correction constants
|
// Custom correction constants
|
||||||
float corrected = (rawValue * correction.scalingFactor) + correction.intercept;
|
float corrected = (rawValue * correction.scalingFactor) + correction.intercept;
|
||||||
|
Serial.println("Custom correction applied");
|
||||||
|
|
||||||
return corrected;
|
return corrected;
|
||||||
}
|
}
|
||||||
@ -747,14 +754,14 @@ JSONVar Measurements::buildIndoor(bool localServer) {
|
|||||||
if (utils::isValidTemperature(_temperature[0].update.avg)) {
|
if (utils::isValidTemperature(_temperature[0].update.avg)) {
|
||||||
indoor[json_prop_temp] = ag->round2(_temperature[0].update.avg);
|
indoor[json_prop_temp] = ag->round2(_temperature[0].update.avg);
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
indoor[json_prop_tempCompensated] = ag->round2(_temperature[0].update.avg);
|
indoor[json_prop_tempCompensated] = ag->round2(getCorrectedTempHum(Temperature));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add humidity
|
// Add humidity
|
||||||
if (utils::isValidHumidity(_humidity[0].update.avg)) {
|
if (utils::isValidHumidity(_humidity[0].update.avg)) {
|
||||||
indoor[json_prop_rhum] = ag->round2(_humidity[0].update.avg);
|
indoor[json_prop_rhum] = ag->round2(_humidity[0].update.avg);
|
||||||
if (localServer) {
|
if (localServer) {
|
||||||
indoor[json_prop_rhumCompensated] = ag->round2(_humidity[0].update.avg);
|
indoor[json_prop_rhumCompensated] = ag->round2(getCorrectedTempHum(Humidity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -834,7 +841,7 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
pms[json_prop_temp] = ag->round2(_temperature[ch].update.avg);
|
pms[json_prop_temp] = ag->round2(_temperature[ch].update.avg);
|
||||||
// Compensate temperature when flag is set
|
// Compensate temperature when flag is set
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
_vc = ag->pms5003t_1.compensateTemp(_temperature[ch].update.avg);
|
_vc = getCorrectedTempHum(Temperature, ch, true);
|
||||||
if (utils::isValidTemperature(_vc)) {
|
if (utils::isValidTemperature(_vc)) {
|
||||||
pms[json_prop_tempCompensated] = ag->round2(_vc);
|
pms[json_prop_tempCompensated] = ag->round2(_vc);
|
||||||
}
|
}
|
||||||
@ -845,8 +852,8 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
pms[json_prop_rhum] = ag->round2(_humidity[ch].update.avg);
|
pms[json_prop_rhum] = ag->round2(_humidity[ch].update.avg);
|
||||||
// Compensate relative humidity when flag is set
|
// Compensate relative humidity when flag is set
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
_vc = ag->pms5003t_1.compensateHum(_humidity[ch].update.avg);
|
_vc = getCorrectedTempHum(Humidity, ch, true);
|
||||||
if (utils::isValidTemperature(_vc)) {
|
if (utils::isValidHumidity(_vc)) {
|
||||||
pms[json_prop_rhumCompensated] = ag->round2(_vc);
|
pms[json_prop_rhumCompensated] = ag->round2(_vc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1031,10 +1038,10 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
|
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
// Compensate both temperature channel
|
// Compensate both temperature channel
|
||||||
float temp = ag->pms5003t_1.compensateTemp(temperature);
|
float temp1 = getCorrectedTempHum(Temperature, 1, true);
|
||||||
float temp1 = ag->pms5003t_1.compensateTemp(_temperature[0].update.avg);
|
float temp2 = getCorrectedTempHum(Temperature, 2, true);
|
||||||
float temp2 = ag->pms5003t_2.compensateTemp(_temperature[1].update.avg);
|
float tempAverage = (temp1 + temp2) / 2.0f;
|
||||||
pms[json_prop_tempCompensated] = ag->round2(temp);
|
pms[json_prop_tempCompensated] = ag->round2(tempAverage);
|
||||||
pms["channels"]["1"][json_prop_tempCompensated] = ag->round2(temp1);
|
pms["channels"]["1"][json_prop_tempCompensated] = ag->round2(temp1);
|
||||||
pms["channels"]["2"][json_prop_tempCompensated] = ag->round2(temp2);
|
pms["channels"]["2"][json_prop_tempCompensated] = ag->round2(temp2);
|
||||||
}
|
}
|
||||||
@ -1045,7 +1052,7 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
|
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
// Compensate channel 1
|
// Compensate channel 1
|
||||||
float temp1 = ag->pms5003t_1.compensateTemp(_temperature[0].update.avg);
|
float temp1 = getCorrectedTempHum(Temperature, 1, true);
|
||||||
pms[json_prop_tempCompensated] = ag->round2(temp1);
|
pms[json_prop_tempCompensated] = ag->round2(temp1);
|
||||||
pms["channels"]["1"][json_prop_tempCompensated] = ag->round2(temp1);
|
pms["channels"]["1"][json_prop_tempCompensated] = ag->round2(temp1);
|
||||||
}
|
}
|
||||||
@ -1056,7 +1063,7 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
|
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
// Compensate channel 2
|
// Compensate channel 2
|
||||||
float temp2 = ag->pms5003t_2.compensateTemp(_temperature[1].update.avg);
|
float temp2 = getCorrectedTempHum(Temperature, 2, true);
|
||||||
pms[json_prop_tempCompensated] = ag->round2(temp2);
|
pms[json_prop_tempCompensated] = ag->round2(temp2);
|
||||||
pms["channels"]["2"][json_prop_tempCompensated] = ag->round2(temp2);
|
pms["channels"]["2"][json_prop_tempCompensated] = ag->round2(temp2);
|
||||||
}
|
}
|
||||||
@ -1072,10 +1079,10 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
|
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
// Compensate both humidity channel
|
// Compensate both humidity channel
|
||||||
float hum = ag->pms5003t_1.compensateHum(humidity);
|
float hum1 = getCorrectedTempHum(Humidity, 1, true);
|
||||||
float hum1 = ag->pms5003t_1.compensateHum(_humidity[0].update.avg);
|
float hum2 = getCorrectedTempHum(Humidity, 2, true);
|
||||||
float hum2 = ag->pms5003t_2.compensateHum(_humidity[1].update.avg);
|
float humAverage = (hum1 + hum2) / 2.0f;
|
||||||
pms[json_prop_rhumCompensated] = ag->round2(hum);
|
pms[json_prop_rhumCompensated] = ag->round2(humAverage);
|
||||||
pms["channels"]["1"][json_prop_rhumCompensated] = ag->round2(hum1);
|
pms["channels"]["1"][json_prop_rhumCompensated] = ag->round2(hum1);
|
||||||
pms["channels"]["2"][json_prop_rhumCompensated] = ag->round2(hum2);
|
pms["channels"]["2"][json_prop_rhumCompensated] = ag->round2(hum2);
|
||||||
}
|
}
|
||||||
@ -1086,7 +1093,7 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
|
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
// Compensate humidity channel 1
|
// Compensate humidity channel 1
|
||||||
float hum1 = ag->pms5003t_1.compensateHum(_humidity[0].update.avg);
|
float hum1 = getCorrectedTempHum(Humidity, 1, true);
|
||||||
pms[json_prop_rhumCompensated] = ag->round2(hum1);
|
pms[json_prop_rhumCompensated] = ag->round2(hum1);
|
||||||
pms["channels"]["1"][json_prop_rhumCompensated] = ag->round2(hum1);
|
pms["channels"]["1"][json_prop_rhumCompensated] = ag->round2(hum1);
|
||||||
}
|
}
|
||||||
@ -1097,7 +1104,7 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
|||||||
|
|
||||||
if (compensate) {
|
if (compensate) {
|
||||||
// Compensate humidity channel 2
|
// Compensate humidity channel 2
|
||||||
float hum2 = ag->pms5003t_2.compensateHum(_humidity[1].update.avg);
|
float hum2 = getCorrectedTempHum(Humidity, 2, true);
|
||||||
pms[json_prop_rhumCompensated] = ag->round2(hum2);
|
pms[json_prop_rhumCompensated] = ag->round2(hum2);
|
||||||
pms["channels"]["2"][json_prop_rhumCompensated] = ag->round2(hum2);
|
pms["channels"]["2"][json_prop_rhumCompensated] = ag->round2(hum2);
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
float getAverage(MeasurementType type, int ch = 1);
|
float getAverage(MeasurementType type, int ch = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get Temperature or Humidity correction value
|
||||||
|
* Only if correction is applied from configuration or forceCorrection is True
|
||||||
|
*
|
||||||
|
* @param type measurement type either Temperature or Humidity
|
||||||
|
* @param ch target type value channel
|
||||||
|
* @param forceCorrection force using correction even though config correction is not applied, but
|
||||||
|
* not for CUSTOM
|
||||||
|
* @return correction value
|
||||||
|
*/
|
||||||
float getCorrectedTempHum(MeasurementType type, int ch = 1, bool forceCorrection = false);
|
float getCorrectedTempHum(MeasurementType type, int ch = 1, bool forceCorrection = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user