diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index e58c320..93718e0 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -1067,9 +1067,21 @@ void plantcontrol() if (!isnan(waterRawSensor.getAverage())) { /* measuring the distance from top -> smaller value means more water: */ - sensorWater.setProperty("remaining").send(String(100.0 * (waterRawSensor.getAverage()/ESP_ADC_MAX))); + long averageWater = waterRawSensor.getAverage(); + if (averageWater < ESP_ADC_MAX) { + long percentage = (averageWater * averageWater); + percentage = percentage / 570000; + /* Add offset */ + if (percentage > 0) + { + percentage += 4; + } + sensorWater.setProperty("remaining").send(String(percentage)); + } else { + sensorWater.setProperty("remaining").send(String("100")); + } - sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage())); + sensorWater.setProperty("raw").send(String(waterRawSensor.getAverage())); } } sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT));