diff --git a/examples/BASIC_v4/BASIC_v4.ino b/examples/BASIC_v4/BASIC_v4.ino index 35f47b3..281fa62 100644 --- a/examples/BASIC_v4/BASIC_v4.ino +++ b/examples/BASIC_v4/BASIC_v4.ino @@ -79,8 +79,8 @@ public: /** Call handler */ handler(); - Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", - (unsigned int)handler, period); + // Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", + // (unsigned int)handler, period); /** Update period time */ count = millis(); @@ -613,7 +613,7 @@ static void sendDataToServer() { root["pm02"] = pm25; } if (temp >= 0) { - root["atmp"] = temp; + root["atmp"] = ag.round2(temp); } if (hum >= 0) { root["rhum"] = hum; @@ -667,9 +667,7 @@ static void updateWiFiConnect(void) { } } -static void showNr(void) { - Serial.println("Serial nr: " + getDevId()); -} +static void showNr(void) { Serial.println("Serial nr: " + getDevId()); } String getNormalizedMac() { String mac = WiFi.macAddress(); diff --git a/examples/ONE_I-9PSL/ONE_I-9PSL.ino b/examples/ONE_I-9PSL/ONE_I-9PSL.ino index 7860e34..096f261 100644 --- a/examples/ONE_I-9PSL/ONE_I-9PSL.ino +++ b/examples/ONE_I-9PSL/ONE_I-9PSL.ino @@ -122,8 +122,8 @@ public: /** Call handler */ handler(); - Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", - (unsigned int)handler, period); + // Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", + // (unsigned int)handler, period); /** Update period time */ count = millis(); @@ -648,9 +648,7 @@ static void co2Poll(void) { Serial.printf("CO2 index: %d\r\n", co2Ppm); } -static void showNr(void) { - Serial.println("Serial nr: " + getDevId()); -} +static void showNr(void) { Serial.println("Serial nr: " + getDevId()); } static void sendPing() { JSONVar root; @@ -1500,7 +1498,7 @@ static void sendDataToServer(void) { root["noxIndex"] = noxIndex; } if (temp >= 0) { - root["atmp"] = temp; + root["atmp"] = ag.round2(temp); } if (hum >= 0) { root["rhum"] = hum; diff --git a/examples/Open_Air/Open_Air.ino b/examples/Open_Air/Open_Air.ino index 33f8eb3..3a43cc2 100644 --- a/examples/Open_Air/Open_Air.ino +++ b/examples/Open_Air/Open_Air.ino @@ -121,8 +121,8 @@ public: /** Call handler */ handler(); - Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", - (unsigned int)handler, period); + // Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n", + // (unsigned int)handler, period); /** Update period time */ count = millis(); @@ -545,7 +545,7 @@ static void sendDataToServer(void) { root["noxIndex"] = noxIndex; } if (temp_1 >= 0) { - root["atmp"] = temp_1; + root["atmp"] = ag.round2(temp_1); } if (hum_1 >= 0) { root["rhum"] = hum_1; @@ -560,22 +560,22 @@ static void sendDataToServer(void) { } if ((fw_mode == FW_MODE_PP) || (fw_mode == FW_MODE_PPT)) { - root["pm01"] = (int)((pm01_1 + pm01_2) / 2); - root["pm02"] = (int)((pm25_1 + pm25_2) / 2); - root["pm003_count"] = (int)((pm03PCount_1 + pm03PCount_2) / 2); - root["atmp"] = (int)((temp_1 + temp_2) / 2); - root["rhum"] = (int)((hum_1 + hum_2) / 2); + root["pm01"] = ag.round2((pm01_1 + pm01_2) / 2.0); + root["pm02"] = ag.round2((pm25_1 + pm25_2) / 2.0); + root["pm003_count"] = ag.round2((pm03PCount_1 + pm03PCount_2) / 2.0); + root["atmp"] = ag.round2((temp_1 + temp_2) / 2.0); + root["rhum"] = ag.round2((hum_1 + hum_2) / 2.0); root["channels"]["1"]["pm01"] = pm01_1; root["channels"]["1"]["pm02"] = pm25_1; root["channels"]["1"]["pm10"] = pm10_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"]["2"]["pm01"] = pm01_2; root["channels"]["2"]["pm02"] = pm25_2; root["channels"]["2"]["pm10"] = pm10_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; } diff --git a/src/AirGradient.cpp b/src/AirGradient.cpp index 8246876..c725bfc 100644 --- a/src/AirGradient.cpp +++ b/src/AirGradient.cpp @@ -36,3 +36,7 @@ int AirGradient::getI2cSclPin(void) { String AirGradient::getVersion(void) { return AG_LIB_VER; } BoardType AirGradient::getBoardType(void) { return boardType; } + +double AirGradient::round2(double value) { + return (int)(value * 100 + 0.5) / 100.0; +} diff --git a/src/AirGradient.h b/src/AirGradient.h index 2a1c102..49b4a71 100644 --- a/src/AirGradient.h +++ b/src/AirGradient.h @@ -107,6 +107,14 @@ public: */ String getVersion(void); + /** + * @brief Round double value with for 2 decimal + * + * @param valuem Round value + * @return double + */ + double round2(double value); + private: BoardType boardType; };