Read settings and store into non volatile memory
This commit is contained in:
parent
6cf9771dcb
commit
b9ca98904d
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include <Homie.h>
|
#include <Homie.h>
|
||||||
|
|
||||||
|
#define DEACTIVATED_PLANT 5000
|
||||||
|
|
||||||
typedef struct PlantSettings_t {
|
typedef struct PlantSettings_t {
|
||||||
HomieSetting<long>* pSensorDry;
|
HomieSetting<long>* pSensorDry;
|
||||||
HomieSetting<long>* pSensorWet;
|
HomieSetting<long>* pSensorWet;
|
||||||
|
@ -24,9 +24,9 @@ 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;
|
||||||
|
PlantSettings_t* mSetting;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlantSettings_t* mSetting;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Plant object
|
* @brief Construct a new Plant object
|
||||||
@ -85,6 +85,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
|
|
||||||
|
long getSettingSensorDry() {
|
||||||
|
return this->mSetting->pSensorDry->get();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,9 +20,9 @@ Plant::Plant(int pinSensor, int pinPump,int plantId, HomieNode* plant, PlantSett
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Plant::init(void) {
|
void Plant::init(void) {
|
||||||
this->mSetting->pSensorDry->setDefaultValue(4095);
|
this->mSetting->pSensorDry->setDefaultValue(DEACTIVATED_PLANT);
|
||||||
this->mSetting->pSensorDry->setValidator([] (long candidate) {
|
this->mSetting->pSensorDry->setValidator([] (long candidate) {
|
||||||
return ((candidate >= 0) && (candidate <= 4095) );
|
return (((candidate >= 0) && (candidate <= 4095) ) || candidate == DEACTIVATED_PLANT);
|
||||||
});
|
});
|
||||||
this->mSetting->pSensorWet->setDefaultValue(0);
|
this->mSetting->pSensorWet->setDefaultValue(0);
|
||||||
this->mSetting->pSensorWet->setValidator([] (long candidate) {
|
this->mSetting->pSensorWet->setValidator([] (long candidate) {
|
||||||
|
@ -24,7 +24,18 @@ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minut
|
|||||||
#define TEMP_INIT_VALUE -999.0f
|
#define TEMP_INIT_VALUE -999.0f
|
||||||
#define TEMP_MAX_VALUE 85.0f
|
#define TEMP_MAX_VALUE 85.0f
|
||||||
|
|
||||||
|
/********************* non volatile enable after deepsleep *******************************/
|
||||||
|
|
||||||
RTC_DATA_ATTR bool coldBoot = true;
|
RTC_DATA_ATTR bool coldBoot = true;
|
||||||
|
RTC_DATA_ATTR long rtcDeepSleepTime = 0; /**< Time, when the microcontroller shall be up again */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger0 = 0; /**<Level for the moisture sensor */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger1 = 0; /**<Level for the moisture sensor */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger2 = 0; /**<Level for the moisture sensor */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger3 = 0; /**<Level for the moisture sensor */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger4 = 0; /**<Level for the moisture sensor */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger5 = 0; /**<Level for the moisture sensor */
|
||||||
|
RTC_DATA_ATTR long rtcMoistureTrigger6 = 0; /**<Level for the moisture sensor */
|
||||||
|
|
||||||
bool warmBoot = true;
|
bool warmBoot = true;
|
||||||
bool mode2Active = false;
|
bool mode2Active = false;
|
||||||
bool mode3Active = false;
|
bool mode3Active = false;
|
||||||
@ -147,15 +158,10 @@ void loopHandler() {
|
|||||||
plant0.setProperty("switch").send(String("OFF"));
|
plant0.setProperty("switch").send(String("OFF"));
|
||||||
plant1.setProperty("switch").send(String("OFF"));
|
plant1.setProperty("switch").send(String("OFF"));
|
||||||
plant2.setProperty("switch").send(String("OFF"));
|
plant2.setProperty("switch").send(String("OFF"));
|
||||||
|
|
||||||
#if (MAX_PLANTS >= 4)
|
|
||||||
plant3.setProperty("switch").send(String("OFF"));
|
plant3.setProperty("switch").send(String("OFF"));
|
||||||
plant4.setProperty("switch").send(String("OFF"));
|
plant4.setProperty("switch").send(String("OFF"));
|
||||||
plant5.setProperty("switch").send(String("OFF"));
|
plant5.setProperty("switch").send(String("OFF"));
|
||||||
#endif
|
|
||||||
#if (MAX_PLANTS >= 7)
|
|
||||||
plant6.setProperty("switch").send(String("OFF"));
|
plant6.setProperty("switch").send(String("OFF"));
|
||||||
#endif
|
|
||||||
|
|
||||||
for(int i=0; i < MAX_PLANTS; i++) {
|
for(int i=0; i < MAX_PLANTS; i++) {
|
||||||
mPlants[i].calculateSensorValue(AMOUNT_SENOR_QUERYS);
|
mPlants[i].calculateSensorValue(AMOUNT_SENOR_QUERYS);
|
||||||
@ -186,6 +192,15 @@ void loopHandler() {
|
|||||||
digitalWrite(OUTPUT_PUMP, HIGH);
|
digitalWrite(OUTPUT_PUMP, HIGH);
|
||||||
digitalWrite(mPlants[plntIdx].getPumpPin(), HIGH);
|
digitalWrite(mPlants[plntIdx].getPumpPin(), HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtcDeepSleepTime = deepSleepTime.get();
|
||||||
|
rtcMoistureTrigger0 = mPlants[0].getSettingSensorDry();
|
||||||
|
rtcMoistureTrigger1 = mPlants[1].getSettingSensorDry();
|
||||||
|
rtcMoistureTrigger2 = mPlants[2].getSettingSensorDry();
|
||||||
|
rtcMoistureTrigger3 = mPlants[3].getSettingSensorDry();
|
||||||
|
rtcMoistureTrigger4 = mPlants[4].getSettingSensorDry();
|
||||||
|
rtcMoistureTrigger5 = mPlants[5].getSettingSensorDry();
|
||||||
|
rtcMoistureTrigger6 = mPlants[6].getSettingSensorDry();
|
||||||
}
|
}
|
||||||
mLoopInited = true;
|
mLoopInited = true;
|
||||||
|
|
||||||
@ -422,6 +437,51 @@ void systemInit(){
|
|||||||
bool mode1(){
|
bool mode1(){
|
||||||
Serial.println("Init mode 1");
|
Serial.println("Init mode 1");
|
||||||
readSensors();
|
readSensors();
|
||||||
|
|
||||||
|
if ((rtcDeepSleepTime == 0) ||
|
||||||
|
(rtcMoistureTrigger0 == 0) ||
|
||||||
|
(rtcMoistureTrigger1 == 0) ||
|
||||||
|
(rtcMoistureTrigger2 == 0) ||
|
||||||
|
(rtcMoistureTrigger3 == 0) ||
|
||||||
|
(rtcMoistureTrigger4 == 0) ||
|
||||||
|
(rtcMoistureTrigger5 == 0) ||
|
||||||
|
(rtcMoistureTrigger6 == 0)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Serial.println("Missing RTC information");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((rtcMoistureTrigger0 != DEACTIVATED_PLANT) && (mPlants[0].getSensorValue() < rtcMoistureTrigger0) ) {
|
||||||
|
Serial.println("Moisture of plant 0");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((rtcMoistureTrigger1 != DEACTIVATED_PLANT) && (mPlants[1].getSensorValue() < rtcMoistureTrigger1) ) {
|
||||||
|
Serial.println("Moisture of plant 1");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((rtcMoistureTrigger2 != DEACTIVATED_PLANT) && (mPlants[2].getSensorValue() < rtcMoistureTrigger2) ) {
|
||||||
|
Serial.println("Moisture of plant 2");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((rtcMoistureTrigger3 != DEACTIVATED_PLANT) && (mPlants[3].getSensorValue() < rtcMoistureTrigger3) ) {
|
||||||
|
Serial.println("Moisture of plant 3");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((rtcMoistureTrigger4 != DEACTIVATED_PLANT) && (mPlants[4].getSensorValue() < rtcMoistureTrigger4) ) {
|
||||||
|
Serial.println("Moisture of plant 4");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((rtcMoistureTrigger5 != DEACTIVATED_PLANT) && (mPlants[5].getSensorValue() < rtcMoistureTrigger5) ) {
|
||||||
|
Serial.println("Moisture of plant 5");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((rtcMoistureTrigger6 != DEACTIVATED_PLANT) && (mPlants[6].getSensorValue() < rtcMoistureTrigger6) ) {
|
||||||
|
Serial.println("Moisture of plant 6");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//TODO read sensor values for each plant
|
||||||
|
|
||||||
//TODO evaluate if something is to do
|
//TODO evaluate if something is to do
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user