From c448960415e8f196b3950911b06c9b7851304c52 Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 14 Jul 2021 21:14:03 +0200 Subject: [PATCH] Check values before publishing water stuff --- esp32/src/PlantCtrl.cpp | 1 - esp32/src/main.cpp | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index 3ea76ee..91fbab4 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -69,7 +69,6 @@ void Plant::clearMoisture(void){ void Plant::addSenseValue(void) { int raw = analogRead(this->mPinSensor); - Serial << "plant bla " << raw << endl; if(raw < MOIST_SENSOR_MAX_ADC && raw > MOIST_SENSOR_MIN_ADC){ this->moistureRaw.add(raw); } diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 30093f7..26eda84 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -636,7 +636,6 @@ void setup() waterSensorAddr.setDefaultValue(""); Homie.setLoopFunction(homieLoop); Homie.onEvent(onHomieEvent); - //Homie.disableLogging(); Homie.setup(); @@ -814,8 +813,13 @@ void plantcontrol() if (mAliveWasRead) { - sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - waterRawSensor.getAverage())); - sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage())); + float remaining = waterLevelMax.get() - waterRawSensor.getAverage(); + if (! isnan(remaining)) { + sensorWater.setProperty("remaining").send(String(remaining)); + } + if (! isnan(waterRawSensor.getAverage())) { + sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage())); + } sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT)); sensorLipo.setProperty("volt").send(String(batteryVoltage)); sensorLipo.setProperty("current").send(String(battery.getCurrent()));