Controller is runing again
This commit is contained in:
		| @@ -55,6 +55,6 @@ | |||||||
| #define SENSOR_SR04_ECHO    17   /**< GPIO 17 - Echo */ | #define SENSOR_SR04_ECHO    17   /**< GPIO 17 - Echo */ | ||||||
| #define SENSOR_SR04_TRIG    23   /**< GPIO 23 - Trigger */ | #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 | #endif | ||||||
|   | |||||||
| @@ -11,7 +11,9 @@ | |||||||
| #ifndef HOMIE_PLANT_CONFIG_H | #ifndef HOMIE_PLANT_CONFIG_H | ||||||
| #define HOMIE_PLANT_CONFIG_H | #define HOMIE_PLANT_CONFIG_H | ||||||
|  |  | ||||||
| #include <Homie.h> | #include "HomieTypes.h" | ||||||
|  |  | ||||||
|  | #define MAX_PLANTS 7 | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  *********************************** Attributes ******************************* |  *********************************** Attributes ******************************* | ||||||
| @@ -53,9 +55,17 @@ HomieSetting<long> waterLevelVol("waterVolume", "ml between minimum and maximum" | |||||||
|         HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("rangehourstart##plant", "Range pump allowed hour start"); \ |         HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("rangehourstart##plant", "Range pump allowed hour start"); \ | ||||||
|         HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("rangehourend##plant", "Range pump allowed hour end"); \ |         HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("rangehourend##plant", "Range pump allowed hour end"); \ | ||||||
|         HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ##plant", "Enable the Pump only, when there is light but not enought to charge battery"); \ |         HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ##plant", "Enable the Pump only, when there is light but not enought to charge battery"); \ | ||||||
|         HomieSetting<long> mPumpCooldownInHours##plant = HomieSetting<long>("cooldownpump##plant", "How long to wait until the pump is activated again"); |         HomieSetting<long> mPumpCooldownInHours##plant = HomieSetting<long>("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(0); | ||||||
| GENERATE_PLANT(1); | GENERATE_PLANT(1); | ||||||
|  | GENERATE_PLANT(2); | ||||||
|  | GENERATE_PLANT(3); | ||||||
|  | GENERATE_PLANT(4); | ||||||
|  | GENERATE_PLANT(5); | ||||||
|  | GENERATE_PLANT(6); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif /* HOMIE_PLANT_CONFIG_H */ | #endif /* HOMIE_PLANT_CONFIG_H */ | ||||||
| @@ -12,8 +12,7 @@ | |||||||
| #ifndef PLANT_CTRL_H | #ifndef PLANT_CTRL_H | ||||||
| #define PLANT_CTRL_H | #define PLANT_CTRL_H | ||||||
|  |  | ||||||
| #include <HomieSetting.hpp> | #include "HomieTypes.h" | ||||||
| #include <SendingPromise.hpp> |  | ||||||
|  |  | ||||||
| class Plant { | class Plant { | ||||||
|  |  | ||||||
| @@ -25,12 +24,7 @@ private: | |||||||
|  |  | ||||||
|     int mAnalogValue=0; /**< moist sensor values, used for a calculation */ |     int mAnalogValue=0; /**< moist sensor values, used for a calculation */ | ||||||
|     HomieNode *mPlant = NULL; |     HomieNode *mPlant = NULL; | ||||||
|     HomieSetting<long> *mSensorDry; |     PlantSettings_t mSetting; | ||||||
|     HomieSetting<long> *mSensorWet; |  | ||||||
|     HomieSetting<long> *mPumpAllowedHourRangeStart; |  | ||||||
|     HomieSetting<long> *mPumpAllowedHourRangeEnd; |  | ||||||
|     HomieSetting<bool> *mPumpOnlyWhenLowLight; |  | ||||||
|     HomieSetting<long> *mPumpCooldownInHours; |  | ||||||
|  |  | ||||||
| public: | public: | ||||||
|  |  | ||||||
| @@ -41,7 +35,9 @@ public: | |||||||
|      * @param pinPump   Pin of the Pump to use |      * @param pinPump   Pin of the Pump to use | ||||||
|      */ |      */ | ||||||
|     Plant(int pinSensor, int pinPump, |     Plant(int pinSensor, int pinPump, | ||||||
|             int plantId); |             int plantId,  | ||||||
|  |             HomieNode* plant, | ||||||
|  |             PlantSettings_t* setting); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @brief Add a value, to be measured |      * @brief Add a value, to be measured | ||||||
| @@ -81,7 +77,7 @@ public: | |||||||
|      * @return false  |      * @return false  | ||||||
|      */ |      */ | ||||||
|     bool isPumpRequired() { |     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 { |     HomieInternals::SendingPromise& setProperty(const String& property) const { | ||||||
|   | |||||||
| @@ -12,62 +12,33 @@ | |||||||
|  |  | ||||||
| #include "PlantCtrl.h" | #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->mPinSensor = pinSensor; | ||||||
|     this->mPinPump = pinPump; |     this->mPinPump = pinPump; | ||||||
|  |     this->mPlant = plant; | ||||||
|     /* |     /* | ||||||
|     { |     this->mSetting = mSetting;     | ||||||
|         char* name = "moistZdry"; |     this->mSetting.pSensorDry->setDefaultValue(4095); | ||||||
|         name[5]= plantIdChar; |     this->mSetting.pSensorDry->setValidator([] (long candidate) { | ||||||
|         mSensorDry = new HomieSetting<long>(name, "Moist sensor dry threshold"); |  | ||||||
|         mSensorDry->setDefaultValue(4095); |  | ||||||
|         mSensorDry->setValidator([] (long candidate) { |  | ||||||
|         return ((candidate >= 0) && (candidate <= 4095) ); |         return ((candidate >= 0) && (candidate <= 4095) ); | ||||||
|     }); |     }); | ||||||
|     } |     this->mSetting.pSensorWet->setDefaultValue(0); | ||||||
|     { |     this->mSetting.pSensorWet->setValidator([] (long candidate) { | ||||||
|         char* name = "moistZwet"; |  | ||||||
|         name[6]= plantIdChar; |  | ||||||
|         mSensorWet = new HomieSetting<long>(name, "Moist sensor wet threshold"); |  | ||||||
|         mSensorWet->setDefaultValue(0); |  | ||||||
|         mSensorWet->setValidator([] (long candidate) { |  | ||||||
|         return ((candidate >= 0) && (candidate <= 4095) ); |         return ((candidate >= 0) && (candidate <= 4095) ); | ||||||
|     }); |     }); | ||||||
|     } |     this->mSetting.pPumpAllowedHourRangeStart->setDefaultValue(8); | ||||||
|     { |     this->mSetting.pPumpAllowedHourRangeStart->setValidator([] (long candidate) { | ||||||
|         char* name = "rangeZhourstart"; |  | ||||||
|         name[6]= plantIdChar; |  | ||||||
|         mPumpAllowedHourRangeStart = new HomieSetting<long>(name, "Range pump allowed hour start"); |  | ||||||
|         mPumpAllowedHourRangeStart->setDefaultValue(8); |  | ||||||
|         mPumpAllowedHourRangeStart->setValidator([] (long candidate) { |  | ||||||
|         return ((candidate >= 0) && (candidate <= 23) ); |         return ((candidate >= 0) && (candidate <= 23) ); | ||||||
|     }); |     }); | ||||||
|     } |     this->mSetting.pPumpAllowedHourRangeEnd->setDefaultValue(20); | ||||||
|     { |     this->mSetting.pPumpAllowedHourRangeEnd->setValidator([] (long candidate) { | ||||||
|         char* name = "rangeZhourend"; |  | ||||||
|         name[6]= plantIdChar; |  | ||||||
|         mPumpAllowedHourRangeEnd = new HomieSetting<long>(name, "Range pump allowed hour end"); |  | ||||||
|         mPumpAllowedHourRangeEnd->setDefaultValue(20); |  | ||||||
|         mPumpAllowedHourRangeEnd->setValidator([] (long candidate) { |  | ||||||
|         return ((candidate >= 0) && (candidate <= 23) ); |         return ((candidate >= 0) && (candidate <= 23) ); | ||||||
|     }); |     }); | ||||||
|     } |     this->mSetting.pPumpOnlyWhenLowLight->setDefaultValue(true); | ||||||
|     { |     this->mSetting.pPumpCooldownInHours->setDefaultValue(20); | ||||||
|         char* name = "onlyWhenLowLightZ"; |     this->mSetting.pPumpCooldownInHours->setValidator([] (long candidate) { | ||||||
|         name[16]= plantIdChar; |  | ||||||
|         mPumpOnlyWhenLowLight = new HomieSetting<bool>(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<long>(name, "How long to wait until the pump is activated again"); |  | ||||||
|         mPumpCooldownInHours->setDefaultValue(20); |  | ||||||
|         mPumpCooldownInHours->setValidator([] (long candidate) { |  | ||||||
|         return ((candidate >= 0) && (candidate <= 1024) ); |         return ((candidate >= 0) && (candidate <= 1024) ); | ||||||
|     }); |     }); | ||||||
|     } |  | ||||||
|     */ |     */ | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,10 +10,10 @@ | |||||||
|  */ |  */ | ||||||
| #include "PlantCtrl.h" | #include "PlantCtrl.h" | ||||||
| #include "ControllerConfiguration.h" | #include "ControllerConfiguration.h" | ||||||
|  | #include "HomieConfiguration.h" | ||||||
| #include "DS18B20.h" | #include "DS18B20.h" | ||||||
| #include <Homie.h> | #include <Homie.h> | ||||||
| #include "esp_sleep.h" | #include "esp_sleep.h" | ||||||
| #include "HomieConfiguration.h" |  | ||||||
|  |  | ||||||
| const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */ | 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); | Ds18B20 dallas(SENSOR_DS18B20); | ||||||
|  |  | ||||||
| Plant mPlants[MAX_PLANTS] = {  | Plant mPlants[MAX_PLANTS] = {  | ||||||
|         Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0),  |         Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0, &plant0, &mSetting0),  | ||||||
|         Plant(SENSOR_PLANT1, OUTPUT_PUMP1, 1),  |         Plant(SENSOR_PLANT1, OUTPUT_PUMP1, 1, &plant1, &mSetting1),  | ||||||
|         Plant(SENSOR_PLANT2, OUTPUT_PUMP2, 2),  |         Plant(SENSOR_PLANT2, OUTPUT_PUMP2, 2, &plant2, &mSetting2),  | ||||||
|         Plant(SENSOR_PLANT3, OUTPUT_PUMP3, 3),  |         Plant(SENSOR_PLANT3, OUTPUT_PUMP3, 3, &plant3, &mSetting3),  | ||||||
|         Plant(SENSOR_PLANT4, OUTPUT_PUMP4, 4),  |         Plant(SENSOR_PLANT4, OUTPUT_PUMP4, 4, &plant4, &mSetting4),  | ||||||
|         Plant(SENSOR_PLANT5, OUTPUT_PUMP5, 5),  |         Plant(SENSOR_PLANT5, OUTPUT_PUMP5, 5, &plant5, &mSetting5),  | ||||||
|         Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6)  |         Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6, &plant6, &mSetting6)  | ||||||
|       }; |       }; | ||||||
|  |  | ||||||
| void readAnalogValues() { | void readAnalogValues() { | ||||||
| @@ -330,7 +330,7 @@ void setup() { | |||||||
|   if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { |   if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { | ||||||
|     Serial << "HOMIE | Settings: " << HomieInternals::MAX_CONFIG_SETTING_SIZE << "/" << MAX_CONFIG_SETTING_ITEMS << endl; |     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_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); |   Homie_setFirmware("PlantControl", FIRMWARE_VERSION); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user