diff --git a/esp32/PlantControl.code-workspace b/esp32/PlantControl.code-workspace index a513b43..2fdda18 100644 --- a/esp32/PlantControl.code-workspace +++ b/esp32/PlantControl.code-workspace @@ -13,7 +13,8 @@ "limits": "cpp", "streambuf": "cpp", "functional": "cpp", - "string": "cpp" + "string": "cpp", + "typeinfo": "cpp" } } } diff --git a/esp32/include/HomieConfiguration.h b/esp32/include/HomieConfiguration.h new file mode 100644 index 0000000..f2fb950 --- /dev/null +++ b/esp32/include/HomieConfiguration.h @@ -0,0 +1,61 @@ +/** + * @file HomieConfiguration.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-10-16 + * + * @copyright Copyright (c) 2020 + * All Settings, configurable in Homie + */ +#ifndef HOMIE_PLANT_CONFIG_H +#define HOMIE_PLANT_CONFIG_H + +#include + +/** + *********************************** Attributes ******************************* + */ + +HomieNode plant0("plant0", "Plant 0", "Plant"); + +HomieNode plant1("plant1", "Plant 1", "Plant"); +HomieNode plant2("plant2", "Plant 2", "Plant"); +HomieNode plant3("plant3", "Plant 3", "Plant"); +HomieNode plant4("plant4", "Plant 4", "Plant"); +HomieNode plant5("plant5", "Plant 5", "Plant"); +HomieNode plant6("plant6", "Plant 6", "Plant"); + +HomieNode sensorLipo("lipo", "Battery Status", "Lipo"); +HomieNode sensorSolar("solar", "Solar Status", "Solarpanel"); +HomieNode sensorWater("water", "WaterSensor", "Water"); +HomieNode sensorTemp("temperature", "Temperature", "temperature"); +HomieNode stayAlive("stay", "alive", "alive"); + +/** + *********************************** Settings ******************************* + */ + +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 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"); + +/** Plant specific ones */ + +#define GENERATE_PLANT(plant) \ + HomieSetting mSensorDry##plant = HomieSetting("moistdry##plant", "Moist sensor dry threshold"); \ + HomieSetting mSensorWet##plant = HomieSetting("moistwet##plant", "Moist sensor wet threshold"); \ + HomieSetting mPumpAllowedHourRangeStart##plant = HomieSetting("rangehourstart##plant", "Range pump allowed hour start"); \ + HomieSetting mPumpAllowedHourRangeEnd##plant = HomieSetting("rangehourend##plant", "Range pump allowed hour end"); \ + HomieSetting mPumpOnlyWhenLowLight##plant = HomieSetting("onlyWhenLowLightZ##plant", "Enable the Pump only, when there is light but not enought to charge battery"); \ + HomieSetting mPumpCooldownInHours##plant = HomieSetting("cooldownpump##plant", "How long to wait until the pump is activated again"); + +GENERATE_PLANT(0); +GENERATE_PLANT(1); + +#endif /* HOMIE_PLANT_CONFIG_H */ \ No newline at end of file diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index e06a9f1..c31e7a5 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -16,8 +16,6 @@ Plant::Plant(int pinSensor, int pinPump,int plantId) { this->mPinSensor = pinSensor; this->mPinPump = pinPump; - char plantIdChar = plantId+'0'; - /* { char* name = "moistZdry"; diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 4fa8096..2b3fb9c 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -13,7 +13,7 @@ #include "DS18B20.h" #include #include "esp_sleep.h" - +#include "HomieConfiguration.h" const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */ @@ -42,42 +42,6 @@ bool mConfigured = false; RTC_DATA_ATTR int gBootCount = 0; RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant needs water) */ -#if (MAX_PLANTS >= 1) -HomieNode plant0("plant0", "Plant 0", "Plant"); -#endif -#if (MAX_PLANTS >= 2) -HomieNode plant1("plant1", "Plant 1", "Plant"); -#endif -#if (MAX_PLANTS >= 3) -HomieNode plant2("plant2", "Plant 2", "Plant"); -#endif -#if (MAX_PLANTS >= 4) -HomieNode plant3("plant3", "Plant 3", "Plant"); -#endif -#if (MAX_PLANTS >= 5) -HomieNode plant4("plant4", "Plant 4", "Plant"); -#endif -#if (MAX_PLANTS >= 6) -HomieNode plant5("plant5", "Plant 5", "Plant"); -#endif -#if (MAX_PLANTS >= 7) -HomieNode plant6("plant6", "Plant 6", "Plant"); -#endif - -HomieNode sensorLipo("lipo", "Battery Status", "Lipo"); -HomieNode sensorSolar("solar", "Solar Status", "Solarpanel"); -HomieNode sensorWater("water", "WaterSensor", "Water"); -HomieNode sensorTemp("temperature", "Temperature", "temperature"); -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 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"); Ds18B20 dallas(SENSOR_DS18B20);