Calculate water percentage below 30 percent
This commit is contained in:
parent
4f7e57988b
commit
f8629586f8
@ -1067,9 +1067,21 @@ void plantcontrol()
|
|||||||
if (!isnan(waterRawSensor.getAverage()))
|
if (!isnan(waterRawSensor.getAverage()))
|
||||||
{
|
{
|
||||||
/* measuring the distance from top -> smaller value means more water: */
|
/* 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));
|
sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT));
|
||||||
|
Loading…
Reference in New Issue
Block a user