use only seconds for time units, improve self test debug
This commit is contained in:
parent
e70e467e9b
commit
7d80d444cf
@ -26,7 +26,7 @@ typedef struct PlantSettings_t
|
|||||||
HomieSetting<long> *pPumpAllowedHourRangeStart;
|
HomieSetting<long> *pPumpAllowedHourRangeStart;
|
||||||
HomieSetting<long> *pPumpAllowedHourRangeEnd;
|
HomieSetting<long> *pPumpAllowedHourRangeEnd;
|
||||||
HomieSetting<bool> *pPumpOnlyWhenLowLight;
|
HomieSetting<bool> *pPumpOnlyWhenLowLight;
|
||||||
HomieSetting<long> *pPumpCooldownInMinutes;
|
HomieSetting<long> *pPumpCooldownInSeconds;
|
||||||
HomieSetting<long> *pPumpDuration;
|
HomieSetting<long> *pPumpDuration;
|
||||||
HomieSetting<long> *pPumpPowerLevel;
|
HomieSetting<long> *pPumpPowerLevel;
|
||||||
} PlantSettings_t;
|
} PlantSettings_t;
|
||||||
|
@ -30,4 +30,5 @@
|
|||||||
#define LOG_DEBUG_CODE 1001
|
#define LOG_DEBUG_CODE 1001
|
||||||
#define LOG_SLEEP_NIGHT 100
|
#define LOG_SLEEP_NIGHT 100
|
||||||
#define LOG_SLEEP_DAY 101
|
#define LOG_SLEEP_DAY 101
|
||||||
|
#define LOG_SLEEP_CYCLE 102
|
||||||
#define LOG_MISSING_PUMP -4
|
#define LOG_MISSING_PUMP -4
|
@ -122,7 +122,7 @@ public:
|
|||||||
void init(void);
|
void init(void);
|
||||||
|
|
||||||
long getCooldownInSeconds() {
|
long getCooldownInSeconds() {
|
||||||
return this->mSetting->pPumpCooldownInMinutes->get()*60;
|
return this->mSetting->pPumpCooldownInSeconds->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,9 +46,9 @@ void Plant::init(void)
|
|||||||
return ((candidate >= 0) && (candidate <= 23));
|
return ((candidate >= 0) && (candidate <= 23));
|
||||||
});
|
});
|
||||||
this->mSetting->pPumpOnlyWhenLowLight->setDefaultValue(true);
|
this->mSetting->pPumpOnlyWhenLowLight->setDefaultValue(true);
|
||||||
this->mSetting->pPumpCooldownInMinutes->setDefaultValue(20); // minutes
|
this->mSetting->pPumpCooldownInSeconds->setDefaultValue(60*60); // 1 hour
|
||||||
this->mSetting->pPumpCooldownInMinutes->setValidator([](long candidate) {
|
this->mSetting->pPumpCooldownInSeconds->setValidator([](long candidate) {
|
||||||
return ((candidate >= 0) && (candidate <= 60*24*7));
|
return (candidate >= 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
this->mSetting->pPumpDuration->setDefaultValue(5);
|
this->mSetting->pPumpDuration->setDefaultValue(5);
|
||||||
@ -71,9 +71,7 @@ void Plant::init(void)
|
|||||||
Serial.println("Set GPIO mode " + String(mPinSensor) + "=" + String(ANALOG));
|
Serial.println("Set GPIO mode " + String(mPinSensor) + "=" + String(ANALOG));
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
pinMode(this->mPinSensor, INPUT);
|
pinMode(this->mPinSensor, INPUT);
|
||||||
Serial.println("Set GPIO " + String(mPinPump) + "=" + String(LOW));
|
|
||||||
Serial.flush();
|
|
||||||
digitalWrite(this->mPinPump, LOW);
|
|
||||||
pcnt_unit_t unit = (pcnt_unit_t) (PCNT_UNIT_0 + this->mPlantId);
|
pcnt_unit_t unit = (pcnt_unit_t) (PCNT_UNIT_0 + this->mPlantId);
|
||||||
pcnt_config_t pcnt_config = { }; // Instancia PCNT config
|
pcnt_config_t pcnt_config = { }; // Instancia PCNT config
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ Plant mPlants[MAX_PLANTS] = {
|
|||||||
* LOCAL FUNCTIONS
|
* LOCAL FUNCTIONS
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
void espDeepSleep()
|
void espDeepSleep(bool afterPump = false)
|
||||||
{
|
{
|
||||||
if (mDownloadMode)
|
if (mDownloadMode)
|
||||||
{
|
{
|
||||||
@ -144,6 +144,13 @@ void espDeepSleep()
|
|||||||
|
|
||||||
long secondsToSleep = -1;
|
long secondsToSleep = -1;
|
||||||
|
|
||||||
|
if (afterPump)
|
||||||
|
{
|
||||||
|
log(LOG_LEVEL_INFO, "AfterPump Cycle Resume", LOG_SLEEP_CYCLE);
|
||||||
|
secondsToSleep = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE)
|
if (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE)
|
||||||
{
|
{
|
||||||
log(LOG_LEVEL_INFO, String(String(mSolarVoltage) + "V! Low light -> deepSleepNight"), LOG_SLEEP_NIGHT);
|
log(LOG_LEVEL_INFO, String(String(mSolarVoltage) + "V! Low light -> deepSleepNight"), LOG_SLEEP_NIGHT);
|
||||||
@ -154,6 +161,7 @@ void espDeepSleep()
|
|||||||
log(LOG_LEVEL_INFO, "Sunny -> deepSleep", LOG_SLEEP_DAY);
|
log(LOG_LEVEL_INFO, "Sunny -> deepSleep", LOG_SLEEP_DAY);
|
||||||
secondsToSleep = deepSleepTime.get();
|
secondsToSleep = deepSleepTime.get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
esp_sleep_enable_timer_wakeup((secondsToSleep * 1000U * 1000U));
|
esp_sleep_enable_timer_wakeup((secondsToSleep * 1000U * 1000U));
|
||||||
if (aliveWasRead())
|
if (aliveWasRead())
|
||||||
@ -409,7 +417,7 @@ int determineNextPump(bool isLowLight)
|
|||||||
if (plant.isPumpRequired())
|
if (plant.isPumpRequired())
|
||||||
{
|
{
|
||||||
/* Handle e.g. start = 21, end = 8 */
|
/* Handle e.g. start = 21, end = 8 */
|
||||||
if ( plant.isHydroponic() || (((plant.getHoursStart() > plant.getHoursEnd()) &&
|
if (plant.isHydroponic() || (((plant.getHoursStart() > plant.getHoursEnd()) &&
|
||||||
(getCurrentHour() >= plant.getHoursStart() || getCurrentHour() <= plant.getHoursEnd())) ||
|
(getCurrentHour() >= plant.getHoursStart() || getCurrentHour() <= plant.getHoursEnd())) ||
|
||||||
/* Handle e.g. start = 8, end = 21 */
|
/* Handle e.g. start = 8, end = 21 */
|
||||||
((plant.getHoursStart() < plant.getHoursEnd()) &&
|
((plant.getHoursStart() < plant.getHoursEnd()) &&
|
||||||
@ -426,7 +434,8 @@ int determineNextPump(bool isLowLight)
|
|||||||
plant.publishState("active");
|
plant.publishState("active");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!plant.isHydroponic()){
|
if (!plant.isHydroponic())
|
||||||
|
{
|
||||||
consecutiveWateringPlant[i]++;
|
consecutiveWateringPlant[i]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +547,7 @@ bool switch7(const HomieRange &range, const String &value)
|
|||||||
void initPumpLogic()
|
void initPumpLogic()
|
||||||
{
|
{
|
||||||
//set targets
|
//set targets
|
||||||
pumpTarget = millis() + (mPlants[pumpToRun].getPumpDuration() * 1000);
|
|
||||||
#ifdef FLOWMETER_PIN
|
#ifdef FLOWMETER_PIN
|
||||||
pumpTargetMl = mPlants[pumpToRun].getPumpDuration();
|
pumpTargetMl = mPlants[pumpToRun].getPumpDuration();
|
||||||
|
|
||||||
@ -558,6 +567,9 @@ void initPumpLogic()
|
|||||||
|
|
||||||
pcnt_counter_clear(unit); // Zera o contador PCNT
|
pcnt_counter_clear(unit); // Zera o contador PCNT
|
||||||
pcnt_counter_resume(unit);
|
pcnt_counter_resume(unit);
|
||||||
|
#else
|
||||||
|
pumpTarget = millis() + (mPlants[pumpToRun].getPumpDuration() * 1000);
|
||||||
|
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s", LOG_PUMP_STARTED_CODE);
|
||||||
#endif
|
#endif
|
||||||
//enable power
|
//enable power
|
||||||
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
|
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
|
||||||
@ -574,7 +586,6 @@ void pumpActiveLoop()
|
|||||||
|
|
||||||
if (!pumpStarted)
|
if (!pumpStarted)
|
||||||
{
|
{
|
||||||
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) , LOG_PUMP_STARTED_CODE );
|
|
||||||
initPumpLogic();
|
initPumpLogic();
|
||||||
pumpStarted = true;
|
pumpStarted = true;
|
||||||
rtcLastWateringPlant[pumpToRun] = getCurrentTime();
|
rtcLastWateringPlant[pumpToRun] = getCurrentTime();
|
||||||
@ -604,7 +615,7 @@ void pumpActiveLoop()
|
|||||||
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped));
|
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (millis() > pumpTarget*1000)
|
if (millis() > pumpTarget)
|
||||||
{
|
{
|
||||||
targetReached = true;
|
targetReached = true;
|
||||||
}
|
}
|
||||||
@ -623,7 +634,7 @@ void pumpActiveLoop()
|
|||||||
pumpStarted = false;
|
pumpStarted = false;
|
||||||
//if runtime is larger than cooldown, else it would run continously
|
//if runtime is larger than cooldown, else it would run continously
|
||||||
rtcLastWateringPlant[pumpToRun] = getCurrentTime();
|
rtcLastWateringPlant[pumpToRun] = getCurrentTime();
|
||||||
espDeepSleep();
|
espDeepSleep(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,12 +830,17 @@ void setup()
|
|||||||
|
|
||||||
void selfTest()
|
void selfTest()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (pumpToRun >= 0 && pumpToRun < MAX_PLANTS)
|
if (pumpToRun >= 0 && pumpToRun < MAX_PLANTS)
|
||||||
{
|
{
|
||||||
|
Serial << "self test mode pump deactivate " << pumpToRun << endl;
|
||||||
|
Serial.flush();
|
||||||
mPlants[pumpToRun].deactivatePump();
|
mPlants[pumpToRun].deactivatePump();
|
||||||
}
|
}
|
||||||
if (pumpToRun >= MAX_PLANTS)
|
if (pumpToRun >= MAX_PLANTS)
|
||||||
{
|
{
|
||||||
|
Serial << "self test finished all pumps, proceed to initial wait mode " << pumpToRun << endl;
|
||||||
|
Serial.flush();
|
||||||
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
|
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
|
||||||
nextBlink = millis() + 500;
|
nextBlink = millis() + 500;
|
||||||
}
|
}
|
||||||
@ -835,6 +851,8 @@ void selfTest()
|
|||||||
}
|
}
|
||||||
if (pumpToRun < MAX_PLANTS)
|
if (pumpToRun < MAX_PLANTS)
|
||||||
{
|
{
|
||||||
|
Serial << "self test activating pump " << pumpToRun << endl;
|
||||||
|
Serial.flush();
|
||||||
mPlants[pumpToRun].activatePump();
|
mPlants[pumpToRun].activatePump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user