From 8458912962dd2affc998eeb702dea4b3864956be Mon Sep 17 00:00:00 2001 From: c3ma Date: Fri, 16 Oct 2020 18:40:39 +0200 Subject: [PATCH] Configuration can be used with default values --- esp32/include/HomieConfiguration.h | 16 ++++++++-------- esp32/src/PlantCtrl.cpp | 6 +++--- esp32/src/main.cpp | 10 ++++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/esp32/include/HomieConfiguration.h b/esp32/include/HomieConfiguration.h index da632c2..c0d42b4 100644 --- a/esp32/include/HomieConfiguration.h +++ b/esp32/include/HomieConfiguration.h @@ -39,23 +39,23 @@ HomieNode stayAlive("stay", "alive", "alive"); */ HomieSetting deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)"); -HomieSetting deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)"); +HomieSetting deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 uses same setting: deepsleep at night, too)"); HomieSetting wateringDeepSleep("pumpdeepsleep", "time seconds to sleep, while a pump is running"); -HomieSetting waterLevelMax("watermaxlevel", "distance at maximum water level"); -HomieSetting waterLevelMin("waterminlevel", "distance at minimum water level (pumps still covered)"); -HomieSetting waterLevelWarn("waterlevelwarn", "warn if below this water level %"); -HomieSetting waterLevelVol("waterVolume", "ml between minimum and maximum"); +HomieSetting waterLevelMax("watermaxlevel", "distance (mm) at maximum water level"); +HomieSetting waterLevelMin("waterminlevel", "distance (mm) at minimum water level (pumps still covered)"); +HomieSetting waterLevelWarn("waterlevelwarn", "warn (mm) if below this water level %"); +HomieSetting waterLevelVol("waterVolume", "(ml) between minimum and maximum"); /** Plant specific ones */ #define GENERATE_PLANT(plant, strplant) \ HomieSetting mSensorDry##plant = HomieSetting("moistdry" strplant, "Plant " strplant "- Moist sensor dry threshold"); \ HomieSetting mSensorWet##plant = HomieSetting("moistwet" strplant, "Plant" strplant " - Moist sensor wet threshold"); \ - HomieSetting mPumpAllowedHourRangeStart##plant = HomieSetting("rangehourstart" strplant, "Plant" strplant " - Range pump allowed hour start"); \ - HomieSetting mPumpAllowedHourRangeEnd##plant = HomieSetting("rangehourend" strplant, "Plant" strplant " - Range pump allowed hour end"); \ + HomieSetting mPumpAllowedHourRangeStart##plant = HomieSetting("rangehourstart" strplant, "Plant" strplant " - Range pump allowed hour start (0-23)"); \ + HomieSetting mPumpAllowedHourRangeEnd##plant = HomieSetting("rangehourend" strplant, "Plant" strplant " - Range pump allowed hour end (0-23)"); \ HomieSetting mPumpOnlyWhenLowLight##plant = HomieSetting("onlyWhenLowLightZ" strplant, "Plant" strplant " - Enable the Pump only, when there is light but not enought to charge battery"); \ - HomieSetting mPumpCooldownInHours##plant = HomieSetting("cooldownpump" strplant, "Plant" strplant " - How long to wait until the pump is activated again"); \ + HomieSetting mPumpCooldownInHours##plant = HomieSetting("cooldownpump" strplant, "Plant" strplant " - How long to wait until the pump is activated again (minutes)"); \ PlantSettings_t mSetting##plant = { &mSensorDry##plant, &mSensorWet##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInHours##plant }; GENERATE_PLANT(0, "0"); diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index e8199fa..ef1ca71 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -28,16 +28,16 @@ void Plant::init(void) { this->mSetting->pSensorWet->setValidator([] (long candidate) { return ((candidate >= 0) && (candidate <= 4095) ); }); - this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8); + this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8); // start at 8:00 this->mSetting->pPumpAllowedHourRangeStart->setValidator([] (long candidate) { return ((candidate >= 0) && (candidate <= 23) ); }); - this->mSetting->pPumpAllowedHourRangeEnd->setDefaultValue(20); + this->mSetting->pPumpAllowedHourRangeEnd->setDefaultValue(20); // stop pumps at 20:00 this->mSetting->pPumpAllowedHourRangeEnd->setValidator([] (long candidate) { return ((candidate >= 0) && (candidate <= 23) ); }); this->mSetting->pPumpOnlyWhenLowLight->setDefaultValue(true); - this->mSetting->pPumpCooldownInHours->setDefaultValue(20); + this->mSetting->pPumpCooldownInHours->setDefaultValue(20); // minutes this->mSetting->pPumpCooldownInHours->setValidator([] (long candidate) { return ((candidate >= 0) && (candidate <= 1024) ); }); diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 212ad93..19822ee 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -342,9 +342,15 @@ void setup() { Homie.setLoopFunction(loopHandler); mConfigured = Homie.isConfigured(); - // Load the settings - deepSleepTime.setDefaultValue(0); + // Set default values + deepSleepTime.setDefaultValue(300000); /* 5 minutes in milliseconds */ deepSleepNightTime.setDefaultValue(0); + wateringDeepSleep.setDefaultValue(60000); /* 1 minute in milliseconds */ + + waterLevelMax.setDefaultValue(1000); /* 100cm in mm */ + waterLevelMin.setDefaultValue(50); /* 5cm in mm */ + waterLevelWarn.setDefaultValue(500); /* 50cm in mm */ + waterLevelVol.setDefaultValue(5000); /* 5l in ml */ if (mConfigured) { // Advertise topics