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();
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 chipTemp = battery.getTemperature();
@ -1048,15 +1048,20 @@ void plantcontrol()
if (aliveWasRead())
{
float remaining = waterLevelMax.get() - waterRawSensor.getAverage();
/* Publish water values, if available */
if (waterRawSensor.getCount() > 0)
{
float remaining = (waterLevelMax.get() - waterRawSensor.getAverage());
if (!isnan(remaining))
{
sensorWater.setProperty("remaining").send(String(remaining));
/* measuring the distance from top -> smaller value means more water: */
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("volt").send(String(batteryVoltage));
sensorLipo.setProperty("current").send(String(battery.getCurrent()));