Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix print log message number format #223

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,9 @@ static void updatePm(void) {
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] Temperature compensated in C: %0.2f\r\n",
ag->pms5003t_1.temperatureCompensated(measurements.temp_1));
Serial.printf("[1] Relative Humidity compensated: %f\r\n",
ag->pms5003t_1.humidityCompensated(measurements.hum_1));
ag->pms5003t_1.compensateTemp(measurements.temp_1));
Serial.printf("[1] Relative Humidity compensated: %0.2f\r\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods below should be renamed to compensateTemp / compensateHum and also documented. I mean we need to explain what the formula is, maybe link to some external document

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;
}

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;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods below should be renamed to compensateTemp / compensateHum and also documented. I mean we need to explain what the formula is, maybe link to some external document

@nick-4711 OK

@airgradienthq Can you provide the link document for the formula.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ag->pms5003t_1.compensateHum(measurements.hum_1));

ag->pms5003t_1.resetFailCount();
} else {
Expand Down Expand Up @@ -1097,9 +1097,9 @@ static void updatePm(void) {
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] Temperature compensated in C: %0.2f\r\n",
ag->pms5003t_2.temperatureCompensated(measurements.temp_2));
Serial.printf("[2] Relative Humidity compensated: %d\r\n",
ag->pms5003t_2.humidityCompensated(measurements.hum_2));
ag->pms5003t_1.compensateTemp(measurements.temp_2));
Serial.printf("[2] Relative Humidity compensated: %0.2f\r\n",
ag->pms5003t_1.compensateHum(measurements.hum_2));

ag->pms5003t_2.resetFailCount();
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/OneOpenAir/OpenMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ String OpenMetrics::getPayload(void) {
atmpCompensated = _temp;
ahumCompensated = _hum;
} else {
atmpCompensated = ag->pms5003t_1.temperatureCompensated(_temp);
ahumCompensated = ag->pms5003t_1.humidityCompensated(_hum);
atmpCompensated = ag->pms5003t_1.compensateTemp(_temp);
ahumCompensated = ag->pms5003t_1.compensateHum(_hum);
}

if (config.hasSensorPMS1 || config.hasSensorPMS2) {
Expand Down
28 changes: 14 additions & 14 deletions src/AgValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (utils::isValidTemperature(this->temp_1) && utils::isValidTemperature(this->temp_1)) {
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
if (localServer) {
val = ag->pms5003t_2.temperatureCompensated((this->temp_1 + this->temp_2) / 2.0f);
val = ag->pms5003t_2.compensateTemp((this->temp_1 + this->temp_2) / 2.0f);
if (utils::isValidTemperature(val)) {
root["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -85,7 +85,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (utils::isValidHumidity(this->hum_1) && utils::isValidHumidity(this->hum_1)) {
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
if (localServer) {
val = ag->pms5003t_2.humidityCompensated((this->hum_1 + this->hum_2) / 2.0f);
val = ag->pms5003t_2.compensateHum((this->hum_1 + this->hum_2) / 2.0f);
if (utils::isValidHumidity(val)) {
root["rhumCompensated"] = (int)val;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["atmp"] = ag->round2(this->temp_1);

if (localServer) {
val = ag->pms5003t_1.temperatureCompensated(this->temp_1);
val = ag->pms5003t_1.compensateTemp(this->temp_1);
if (utils::isValidTemperature(val)) {
root["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -127,7 +127,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["rhum"] = this->hum_1;

if (localServer) {
val = ag->pms5003t_1.humidityCompensated(this->hum_1);
val = ag->pms5003t_1.compensateHum(this->hum_1);
if (utils::isValidHumidity(val)) {
root["rhumCompensated"] = (int)val;
}
Expand All @@ -154,7 +154,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["atmp"] = ag->round2(this->temp_2);

if (localServer) {
val = ag->pms5003t_2.temperatureCompensated(this->temp_2);
val = ag->pms5003t_2.compensateTemp(this->temp_2);
if (utils::isValidTemperature(val)) {
root["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -164,7 +164,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["rhum"] = this->hum_2;

if (localServer) {
val = ag->pms5003t_2.humidityCompensated(this->hum_2);
val = ag->pms5003t_2.compensateHum(this->hum_2);
if (utils::isValidHumidity(val)) {
root["rhumCompensated"] = (int)val;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["atmp"] = ag->round2(this->temp_1);

if (localServer) {
val = ag->pms5003t_1.temperatureCompensated(this->temp_1);
val = ag->pms5003t_1.compensateTemp(this->temp_1);
if (utils::isValidTemperature(val)) {
root["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -201,7 +201,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (utils::isValidHumidity(this->hum_1)) {
root["rhum"] = this->hum_1;
if(localServer) {
val = ag->pms5003t_1.humidityCompensated(this->hum_1);
val = ag->pms5003t_1.compensateHum(this->hum_1);
if(utils::isValidHumidity(val)) {
root["rhumCompensated"] = (int)val;
}
Expand All @@ -225,7 +225,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["atmp"] = ag->round2(this->temp_2);
if (localServer) {

val = ag->pms5003t_1.temperatureCompensated(this->temp_2);
val = ag->pms5003t_1.compensateTemp(this->temp_2);
if (utils::isValidTemperature(val)) {
root["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -235,7 +235,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["rhum"] = this->hum_2;

if(localServer) {
val = ag->pms5003t_1.humidityCompensated(this->hum_2);
val = ag->pms5003t_1.compensateHum(this->hum_2);
if(utils::isValidHumidity(val)) {
root["rhumCompensated"] = (int)val;
}
Expand All @@ -262,7 +262,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);

if (localServer) {
val = ag->pms5003t_1.temperatureCompensated(this->temp_1);
val = ag->pms5003t_1.compensateTemp(this->temp_1);
if (utils::isValidTemperature(val)) {
root["channels"]["1"]["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -272,7 +272,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["channels"]["1"]["rhum"] = this->hum_1;

if (localServer) {
val = ag->pms5003t_1.humidityCompensated(this->hum_1);
val = ag->pms5003t_1.compensateHum(this->hum_1);
if (utils::isValidHumidity(val)) {
root["channels"]["1"]["rhumCompensated"] = (int)val;
}
Expand All @@ -298,7 +298,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);

if (localServer) {
val = ag->pms5003t_1.temperatureCompensated(this->temp_2);
val = ag->pms5003t_1.compensateTemp(this->temp_2);
if (utils::isValidTemperature(val)) {
root["channels"]["2"]["atmpCompensated"] = ag->round2(val);
}
Expand All @@ -308,7 +308,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["channels"]["2"]["rhum"] = this->hum_2;

if (localServer) {
val = ag->pms5003t_1.humidityCompensated(this->hum_2);
val = ag->pms5003t_1.compensateHum(this->hum_2);
if (utils::isValidHumidity(val)) {
root["channels"]["2"]["rhumCompensated"] = (int)val;
}
Expand Down
20 changes: 18 additions & 2 deletions src/PMS/PMS5003TBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ PMS5003TBase::PMS5003TBase() {}

PMS5003TBase::~PMS5003TBase() {}

float PMS5003TBase::temperatureCompensated(float temp) {
/**
* @brief Compensate the temperature
*
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
*
* @param temp
* @return * float
*/
float PMS5003TBase::compensateTemp(float temp) {
if (temp < 10.0f) {
return temp * 1.327f - 6.738f;
}
return temp * 1.181f - 5.113f;
}

float PMS5003TBase::humidityCompensated(float hum) {
/**
* @brief Compensate the humidity
*
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
*
* @param temp
* @return * float
*/
float PMS5003TBase::compensateHum(float hum) {
hum = hum * 1.259f + 7.34f;

if (hum > 100.0f) {
Expand Down
4 changes: 2 additions & 2 deletions src/PMS/PMS5003TBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class PMS5003TBase
public:
PMS5003TBase();
~PMS5003TBase();
float temperatureCompensated(float temp);
float humidityCompensated(float hum);
float compensateTemp(float temp);
float compensateHum(float hum);
};

#endif