add atmp_compensated and rhum_compensated to sync data

This commit is contained in:
Phat Nguyen
2024-04-13 20:39:05 +07:00
parent 25ef1ced9e
commit e1115659e2
4 changed files with 44 additions and 2 deletions

View File

@ -631,6 +631,7 @@ static void boardInit(void) {
} else {
openAirInit();
}
localServer.setFwMode(fwMode);
}
static void failedHandler(String msg) {

View File

@ -42,9 +42,11 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
if (config->hasSensorSHT) {
if (this->Temperature > -1001) {
root["atmp"] = ag->round2(this->Temperature);
root["atmp_compensated"] = ag->round2(this->Temperature);
}
if (this->Humidity >= 0) {
root["rhum"] = this->Humidity;
root["rhum_compensated"] = this->Humidity;
}
}
@ -60,8 +62,13 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["pm003_count"] =
ag->round2((this->pm03PCount_1 + this->pm03PCount_2) / 2.0);
}
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0);
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0);
root["atmp"] = ag->round2((this->temp_1 + this->temp_2) / 2.0f);
root["rhum"] = ag->round2((this->hum_1 + this->hum_2) / 2.0f);
root["atmp_compensated"] =
ag->round2(ag->pms5003t_2.temperatureCompensated(
(this->temp_1 + this->temp_2) / 2.0f));
root["rhum_compensated"] = (int)ag->pms5003t_2.humidityCompensated(
(this->hum_1 + this->hum_2) / 2.0f);
}
if (fwMode == FW_MDOE_O_1PS || fwMode == FW_MODE_O_1PST) {
@ -76,6 +83,10 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
}
root["atmp"] = ag->round2(this->temp_1);
root["rhum"] = this->hum_1;
root["atmp_compensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
root["rhum_compensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_1);
}
if (config->hasSensorPMS2) {
root["pm01"] = this->pm01_2;
@ -88,6 +99,10 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
}
root["atmp"] = ag->round2(this->temp_2);
root["rhum"] = this->hum_2;
root["atmp_compensated"] =
ag->round2(ag->pms5003t_2.temperatureCompensated(this->temp_2));
root["rhum_compensated"] =
(int)ag->pms5003t_2.humidityCompensated(this->hum_2);
}
} else {
if (config->hasSensorPMS1) {
@ -101,6 +116,10 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
}
root["channels"]["1"]["atmp"] = ag->round2(this->temp_1);
root["channels"]["1"]["rhum"] = this->hum_1;
root["channels"]["1"]["atmp_compensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_1));
root["channels"]["1"]["rhum_compensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_1);
}
if (config->hasSensorPMS2) {
root["channels"]["2"]["pm01"] = this->pm01_2;
@ -113,6 +132,10 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
}
root["channels"]["2"]["atmp"] = ag->round2(this->temp_2);
root["channels"]["2"]["rhum"] = this->hum_2;
root["channels"]["2"]["atmp_compensated"] =
ag->round2(ag->pms5003t_1.temperatureCompensated(this->temp_2));
root["channels"]["2"]["rhum_compensated"] =
(int)ag->pms5003t_1.humidityCompensated(this->hum_2);
}
}
}

View File

@ -201,3 +201,19 @@ void PMS5003T::handle(void) { pms.handle(); }
* @return false Communication timeout or sensor has removed
*/
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;
}

View File

@ -28,6 +28,8 @@ public:
int convertPm25ToUsAqi(int pm25);
float getTemperature(void);
float getRelativeHumidity(void);
float temperatureCompensated(float temp);
float humidityCompensated(float hum);
private:
bool _isBegin = false;