From ade0a8b8125d9459a27246bfdb9333b85302fd33 Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 11 Nov 2020 21:09:38 +0100 Subject: [PATCH] only read temperature multiple times, if it differs significantly to last measurement --- esp32/src/main.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 8f9e072..8090b06 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -382,7 +382,8 @@ bool readSensors() delay(200); /* Required to read the temperature once */ - for (int i = 0; i < 5; i++) + int readAgain = 5; + while (readAgain > 0) { int sensors = dallas.readAllTemperatures(pFloat, 2); if (sensors > 0) @@ -395,17 +396,23 @@ bool readSensors() Serial << "t2: " << String(temp[1]) << endl; temp2.add(temp[1]); } + if ((temp1.getAverage() - rtcLastTemp1 > TEMPERATURE_DELTA_TRIGGER_IN_C) || + (rtcLastTemp1 - temp1.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) { + leaveMode1 = true; + } + if ((temp2.getAverage() - rtcLastTemp2 > TEMPERATURE_DELTA_TRIGGER_IN_C) || + (rtcLastTemp2 - temp2.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) { + leaveMode1 = true; + } + if(!leaveMode1){ + readAgain = 0; + } + + readAgain--; delay(50); } - if ((temp1.getAverage() - rtcLastTemp1 > TEMPERATURE_DELTA_TRIGGER_IN_C) || - (rtcLastTemp1 - temp1.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) { - leaveMode1 = true; - } - if ((temp2.getAverage() - rtcLastTemp2 > TEMPERATURE_DELTA_TRIGGER_IN_C) || - (rtcLastTemp2 - temp2.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) { - leaveMode1 = true; - } + rtcLastTemp1 = temp1.getAverage(); rtcLastTemp2 = temp2.getAverage();