round real value with 2 decimal on server sync data json

This commit is contained in:
Phat Nguyen
2024-02-17 12:47:51 +07:00
parent 7c63af5ba9
commit 8c94cea764
5 changed files with 30 additions and 22 deletions

View File

@ -79,8 +79,8 @@ public:
/** Call handler */ /** Call handler */
handler(); handler();
Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", // Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n",
(unsigned int)handler, period); // (unsigned int)handler, period);
/** Update period time */ /** Update period time */
count = millis(); count = millis();
@ -613,7 +613,7 @@ static void sendDataToServer() {
root["pm02"] = pm25; root["pm02"] = pm25;
} }
if (temp >= 0) { if (temp >= 0) {
root["atmp"] = temp; root["atmp"] = ag.round2(temp);
} }
if (hum >= 0) { if (hum >= 0) {
root["rhum"] = hum; root["rhum"] = hum;
@ -667,9 +667,7 @@ static void updateWiFiConnect(void) {
} }
} }
static void showNr(void) { static void showNr(void) { Serial.println("Serial nr: " + getDevId()); }
Serial.println("Serial nr: " + getDevId());
}
String getNormalizedMac() { String getNormalizedMac() {
String mac = WiFi.macAddress(); String mac = WiFi.macAddress();

View File

@ -122,8 +122,8 @@ public:
/** Call handler */ /** Call handler */
handler(); handler();
Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", // Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n",
(unsigned int)handler, period); // (unsigned int)handler, period);
/** Update period time */ /** Update period time */
count = millis(); count = millis();
@ -648,9 +648,7 @@ static void co2Poll(void) {
Serial.printf("CO2 index: %d\r\n", co2Ppm); Serial.printf("CO2 index: %d\r\n", co2Ppm);
} }
static void showNr(void) { static void showNr(void) { Serial.println("Serial nr: " + getDevId()); }
Serial.println("Serial nr: " + getDevId());
}
static void sendPing() { static void sendPing() {
JSONVar root; JSONVar root;
@ -1500,7 +1498,7 @@ static void sendDataToServer(void) {
root["noxIndex"] = noxIndex; root["noxIndex"] = noxIndex;
} }
if (temp >= 0) { if (temp >= 0) {
root["atmp"] = temp; root["atmp"] = ag.round2(temp);
} }
if (hum >= 0) { if (hum >= 0) {
root["rhum"] = hum; root["rhum"] = hum;

View File

@ -121,8 +121,8 @@ public:
/** Call handler */ /** Call handler */
handler(); handler();
Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", // Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n",
(unsigned int)handler, period); // (unsigned int)handler, period);
/** Update period time */ /** Update period time */
count = millis(); count = millis();
@ -545,7 +545,7 @@ static void sendDataToServer(void) {
root["noxIndex"] = noxIndex; root["noxIndex"] = noxIndex;
} }
if (temp_1 >= 0) { if (temp_1 >= 0) {
root["atmp"] = temp_1; root["atmp"] = ag.round2(temp_1);
} }
if (hum_1 >= 0) { if (hum_1 >= 0) {
root["rhum"] = hum_1; root["rhum"] = hum_1;
@ -560,22 +560,22 @@ static void sendDataToServer(void) {
} }
if ((fw_mode == FW_MODE_PP) || (fw_mode == FW_MODE_PPT)) { if ((fw_mode == FW_MODE_PP) || (fw_mode == FW_MODE_PPT)) {
root["pm01"] = (int)((pm01_1 + pm01_2) / 2); root["pm01"] = ag.round2((pm01_1 + pm01_2) / 2.0);
root["pm02"] = (int)((pm25_1 + pm25_2) / 2); root["pm02"] = ag.round2((pm25_1 + pm25_2) / 2.0);
root["pm003_count"] = (int)((pm03PCount_1 + pm03PCount_2) / 2); root["pm003_count"] = ag.round2((pm03PCount_1 + pm03PCount_2) / 2.0);
root["atmp"] = (int)((temp_1 + temp_2) / 2); root["atmp"] = ag.round2((temp_1 + temp_2) / 2.0);
root["rhum"] = (int)((hum_1 + hum_2) / 2); root["rhum"] = ag.round2((hum_1 + hum_2) / 2.0);
root["channels"]["1"]["pm01"] = pm01_1; root["channels"]["1"]["pm01"] = pm01_1;
root["channels"]["1"]["pm02"] = pm25_1; root["channels"]["1"]["pm02"] = pm25_1;
root["channels"]["1"]["pm10"] = pm10_1; root["channels"]["1"]["pm10"] = pm10_1;
root["channels"]["1"]["pm003_count"] = pm03PCount_1; root["channels"]["1"]["pm003_count"] = pm03PCount_1;
root["channels"]["1"]["atmp"] = temp_1; root["channels"]["1"]["atmp"] = ag.round2(temp_1);
root["channels"]["1"]["rhum"] = hum_1; root["channels"]["1"]["rhum"] = hum_1;
root["channels"]["2"]["pm01"] = pm01_2; root["channels"]["2"]["pm01"] = pm01_2;
root["channels"]["2"]["pm02"] = pm25_2; root["channels"]["2"]["pm02"] = pm25_2;
root["channels"]["2"]["pm10"] = pm10_2; root["channels"]["2"]["pm10"] = pm10_2;
root["channels"]["2"]["pm003_count"] = pm03PCount_2; root["channels"]["2"]["pm003_count"] = pm03PCount_2;
root["channels"]["2"]["atmp"] = temp_2; root["channels"]["2"]["atmp"] = ag.round2(temp_2);
root["channels"]["2"]["rhum"] = hum_2; root["channels"]["2"]["rhum"] = hum_2;
} }

View File

@ -36,3 +36,7 @@ int AirGradient::getI2cSclPin(void) {
String AirGradient::getVersion(void) { return AG_LIB_VER; } String AirGradient::getVersion(void) { return AG_LIB_VER; }
BoardType AirGradient::getBoardType(void) { return boardType; } BoardType AirGradient::getBoardType(void) { return boardType; }
double AirGradient::round2(double value) {
return (int)(value * 100 + 0.5) / 100.0;
}

View File

@ -107,6 +107,14 @@ public:
*/ */
String getVersion(void); String getVersion(void);
/**
* @brief Round double value with for 2 decimal
*
* @param valuem Round value
* @return double
*/
double round2(double value);
private: private:
BoardType boardType; BoardType boardType;
}; };