From ce498bc7f86d1603a5fddf84f3a2c832bd924060 Mon Sep 17 00:00:00 2001 From: c3ma Date: Fri, 16 Oct 2020 16:22:48 +0200 Subject: [PATCH] Controller is runing again --- esp32/include/ControllerConfiguration.h | 2 +- esp32/include/HomieConfiguration.h | 14 ++++- esp32/include/PlantCtrl.h | 16 ++--- esp32/src/PlantCtrl.cpp | 79 ++++++++----------------- esp32/src/main.cpp | 18 +++--- 5 files changed, 53 insertions(+), 76 deletions(-) diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index e099349..960d826 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -55,6 +55,6 @@ #define SENSOR_SR04_ECHO 17 /**< GPIO 17 - Echo */ #define SENSOR_SR04_TRIG 23 /**< GPIO 23 - Trigger */ -#define MAX_CONFIG_SETTING_ITEMS 30 /**< Parameter, that can be configured in Homie */ +#define MAX_CONFIG_SETTING_ITEMS 50 /**< Parameter, that can be configured in Homie */ #endif diff --git a/esp32/include/HomieConfiguration.h b/esp32/include/HomieConfiguration.h index f2fb950..ac5d6cb 100644 --- a/esp32/include/HomieConfiguration.h +++ b/esp32/include/HomieConfiguration.h @@ -11,7 +11,9 @@ #ifndef HOMIE_PLANT_CONFIG_H #define HOMIE_PLANT_CONFIG_H -#include +#include "HomieTypes.h" + +#define MAX_PLANTS 7 /** *********************************** Attributes ******************************* @@ -53,9 +55,17 @@ HomieSetting waterLevelVol("waterVolume", "ml between minimum and maximum" 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"); + HomieSetting mPumpCooldownInHours##plant = HomieSetting("cooldownpump##plant", "How long to wait until the pump is activated again"); \ + PlantSettings_t mSetting##plant = { &mSensorDry##plant, &mSensorWet##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInHours##plant }; GENERATE_PLANT(0); GENERATE_PLANT(1); +GENERATE_PLANT(2); +GENERATE_PLANT(3); +GENERATE_PLANT(4); +GENERATE_PLANT(5); +GENERATE_PLANT(6); + + #endif /* HOMIE_PLANT_CONFIG_H */ \ No newline at end of file diff --git a/esp32/include/PlantCtrl.h b/esp32/include/PlantCtrl.h index df1a914..c737e7a 100644 --- a/esp32/include/PlantCtrl.h +++ b/esp32/include/PlantCtrl.h @@ -12,8 +12,7 @@ #ifndef PLANT_CTRL_H #define PLANT_CTRL_H -#include -#include +#include "HomieTypes.h" class Plant { @@ -25,12 +24,7 @@ private: int mAnalogValue=0; /**< moist sensor values, used for a calculation */ HomieNode *mPlant = NULL; - HomieSetting *mSensorDry; - HomieSetting *mSensorWet; - HomieSetting *mPumpAllowedHourRangeStart; - HomieSetting *mPumpAllowedHourRangeEnd; - HomieSetting *mPumpOnlyWhenLowLight; - HomieSetting *mPumpCooldownInHours; + PlantSettings_t mSetting; public: @@ -41,7 +35,9 @@ public: * @param pinPump Pin of the Pump to use */ Plant(int pinSensor, int pinPump, - int plantId); + int plantId, + HomieNode* plant, + PlantSettings_t* setting); /** * @brief Add a value, to be measured @@ -81,7 +77,7 @@ public: * @return false */ bool isPumpRequired() { - return (this->mSensorWet != NULL) && (this->mValue < this->mSensorWet->get()); + return (this->mSetting.pSensorWet != NULL) && (this->mValue < this->mSetting.pSensorWet->get()); } HomieInternals::SendingPromise& setProperty(const String& property) const { diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index c31e7a5..5e77a9f 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -12,63 +12,34 @@ #include "PlantCtrl.h" -Plant::Plant(int pinSensor, int pinPump,int plantId) { +Plant::Plant(int pinSensor, int pinPump,int plantId, HomieNode *plant, PlantSettings_t* setting) { this->mPinSensor = pinSensor; this->mPinPump = pinPump; - + this->mPlant = plant; /* - { - char* name = "moistZdry"; - name[5]= plantIdChar; - mSensorDry = new HomieSetting(name, "Moist sensor dry threshold"); - mSensorDry->setDefaultValue(4095); - mSensorDry->setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 4095) ); - }); - } - { - char* name = "moistZwet"; - name[6]= plantIdChar; - mSensorWet = new HomieSetting(name, "Moist sensor wet threshold"); - mSensorWet->setDefaultValue(0); - mSensorWet->setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 4095) ); - }); - } - { - char* name = "rangeZhourstart"; - name[6]= plantIdChar; - mPumpAllowedHourRangeStart = new HomieSetting(name, "Range pump allowed hour start"); - mPumpAllowedHourRangeStart->setDefaultValue(8); - mPumpAllowedHourRangeStart->setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 23) ); - }); - } - { - char* name = "rangeZhourend"; - name[6]= plantIdChar; - mPumpAllowedHourRangeEnd = new HomieSetting(name, "Range pump allowed hour end"); - mPumpAllowedHourRangeEnd->setDefaultValue(20); - mPumpAllowedHourRangeEnd->setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 23) ); - }); - } - { - char* name = "onlyWhenLowLightZ"; - name[16]= plantIdChar; - mPumpOnlyWhenLowLight = new HomieSetting(name, "Enable the Pump only, when there is light but not enought to charge battery"); - mPumpOnlyWhenLowLight->setDefaultValue(true); - } - { - char* name = "cooldownpumpZ"; - name[12]= plantIdChar; - mPumpCooldownInHours = new HomieSetting(name, "How long to wait until the pump is activated again"); - mPumpCooldownInHours->setDefaultValue(20); - mPumpCooldownInHours->setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 1024) ); - }); - } -*/ + this->mSetting = mSetting; + this->mSetting.pSensorDry->setDefaultValue(4095); + this->mSetting.pSensorDry->setValidator([] (long candidate) { + return ((candidate >= 0) && (candidate <= 4095) ); + }); + this->mSetting.pSensorWet->setDefaultValue(0); + this->mSetting.pSensorWet->setValidator([] (long candidate) { + return ((candidate >= 0) && (candidate <= 4095) ); + }); + this->mSetting.pPumpAllowedHourRangeStart->setDefaultValue(8); + this->mSetting.pPumpAllowedHourRangeStart->setValidator([] (long candidate) { + return ((candidate >= 0) && (candidate <= 23) ); + }); + this->mSetting.pPumpAllowedHourRangeEnd->setDefaultValue(20); + this->mSetting.pPumpAllowedHourRangeEnd->setValidator([] (long candidate) { + return ((candidate >= 0) && (candidate <= 23) ); + }); + this->mSetting.pPumpOnlyWhenLowLight->setDefaultValue(true); + this->mSetting.pPumpCooldownInHours->setDefaultValue(20); + this->mSetting.pPumpCooldownInHours->setValidator([] (long candidate) { + return ((candidate >= 0) && (candidate <= 1024) ); + }); + */ } void Plant::addSenseValue(int analog) { diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 2b3fb9c..499a618 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -10,10 +10,10 @@ */ #include "PlantCtrl.h" #include "ControllerConfiguration.h" +#include "HomieConfiguration.h" #include "DS18B20.h" #include #include "esp_sleep.h" -#include "HomieConfiguration.h" const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */ @@ -46,13 +46,13 @@ RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant need Ds18B20 dallas(SENSOR_DS18B20); Plant mPlants[MAX_PLANTS] = { - Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0), - Plant(SENSOR_PLANT1, OUTPUT_PUMP1, 1), - Plant(SENSOR_PLANT2, OUTPUT_PUMP2, 2), - Plant(SENSOR_PLANT3, OUTPUT_PUMP3, 3), - Plant(SENSOR_PLANT4, OUTPUT_PUMP4, 4), - Plant(SENSOR_PLANT5, OUTPUT_PUMP5, 5), - Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6) + Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0, &plant0, &mSetting0), + Plant(SENSOR_PLANT1, OUTPUT_PUMP1, 1, &plant1, &mSetting1), + Plant(SENSOR_PLANT2, OUTPUT_PUMP2, 2, &plant2, &mSetting2), + Plant(SENSOR_PLANT3, OUTPUT_PUMP3, 3, &plant3, &mSetting3), + Plant(SENSOR_PLANT4, OUTPUT_PUMP4, 4, &plant4, &mSetting4), + Plant(SENSOR_PLANT5, OUTPUT_PUMP5, 5, &plant5, &mSetting5), + Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6, &plant6, &mSetting6) }; void readAnalogValues() { @@ -330,7 +330,7 @@ void setup() { if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { Serial << "HOMIE | Settings: " << HomieInternals::MAX_CONFIG_SETTING_SIZE << "/" << MAX_CONFIG_SETTING_ITEMS << endl; Serial << " | Update Limits.hpp : MAX_CONFIG_SETTING_SIZE to " << MAX_CONFIG_SETTING_ITEMS << endl; - Serial << " | Update Limits.hpp : MAX_JSON_CONFIG_FILE_SIZE to 3000" << endl; + Serial << " | Update Limits.hpp : MAX_JSON_CONFIG_FILE_SIZE to 5000" << endl; } Homie_setFirmware("PlantControl", FIRMWARE_VERSION);