Fixed water distance and publish percentage

This commit is contained in:
Ollo 2023-03-24 18:06:21 +01:00
parent 90f2d821a7
commit 704684d437

View File

@ -1040,7 +1040,7 @@ void plantcontrol()
readOneWireSensors(); readOneWireSensors();
Serial << "W : " << waterRawSensor.getAverage() << " cm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << "%)" << endl; Serial << "W : " << waterRawSensor.getAverage() << " mm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << " mm left)" << endl;
float batteryVoltage = battery.getVoltage(BATTSENSOR_INDEX_BATTERY); float batteryVoltage = battery.getVoltage(BATTSENSOR_INDEX_BATTERY);
float chipTemp = battery.getTemperature(); float chipTemp = battery.getTemperature();
@ -1048,14 +1048,19 @@ void plantcontrol()
if (aliveWasRead()) if (aliveWasRead())
{ {
float remaining = waterLevelMax.get() - waterRawSensor.getAverage(); /* Publish water values, if available */
if (!isnan(remaining)) if (waterRawSensor.getCount() > 0)
{ {
sensorWater.setProperty("remaining").send(String(remaining)); float remaining = (waterLevelMax.get() - waterRawSensor.getAverage());
} if (!isnan(remaining))
if (!isnan(waterRawSensor.getAverage())) {
{ /* measuring the distance from top -> smaller value means more water: */
sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage())); sensorWater.setProperty("remaining").send(String(100.0 - (remaining/100)));
}
if (!isnan(waterRawSensor.getAverage()))
{
sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage()));
}
} }
sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT)); sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT));
sensorLipo.setProperty("volt").send(String(batteryVoltage)); sensorLipo.setProperty("volt").send(String(batteryVoltage));