From 7a841d423b5a5c8fa15f772386bbc785dec22554 Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 29 Apr 2022 10:45:59 +0200 Subject: [PATCH 1/9] use more sane default (pump always not only at night) --- esp32/src/PlantCtrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index 72fc01b..cf33de6 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -39,7 +39,7 @@ void Plant::init(void) this->mSetting->pPumpAllowedHourRangeEnd->setDefaultValue(20); // stop pumps at 20:00 this->mSetting->pPumpAllowedHourRangeEnd->setValidator([](long candidate) { return ((candidate >= 0) && (candidate <= 23)); }); - this->mSetting->pPumpOnlyWhenLowLight->setDefaultValue(true); + this->mSetting->pPumpOnlyWhenLowLight->setDefaultValue(false); this->mSetting->pPumpCooldownInSeconds->setDefaultValue(60 * 60); // 1 hour this->mSetting->pPumpCooldownInSeconds->setValidator([](long candidate) { return (candidate >= 0); }); From 0dd45539996b608cc2fc248fa096cd5f7dbd4083 Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 29 Apr 2022 10:47:16 +0200 Subject: [PATCH 2/9] do not use pump for download indication anymore --- esp32/src/main.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 333146f..a43c0a4 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -56,6 +56,7 @@ int determineNextPump(bool lowLight); void plantcontrol(); void readPowerSwitchedSensors(); bool determineTimedLightState(bool lowLight); +bool otaRunning = false; /****************************************************************************** * NON VOLATILE VARIABLES in DEEP SLEEP @@ -401,10 +402,7 @@ void onHomieEvent(const HomieEvent &event) { mPlants[i].deactivatePump(); } - WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); - digitalWrite(OUTPUT_ENABLE_PUMP, HIGH); - delay(100); - WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1); + otaRunning = true; mDownloadMode = true; break; case HomieEventType::OTA_SUCCESSFUL: @@ -981,7 +979,14 @@ void loop() digitalWrite(OUTPUT_ENABLE_SENSOR, !digitalRead(OUTPUT_ENABLE_SENSOR)); if (mConfigured) { - nextBlink = millis() + 500; + if (otaRunning) + { + nextBlink = millis() + 100; + } + else + { + nextBlink = millis() + 501; + } } else { From 15e96a4990c0b25a7f51b9177446ebe2b4af3437 Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 29 Apr 2022 10:47:46 +0200 Subject: [PATCH 3/9] ensure compilation with bricking limits is not possible --- esp32/src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index a43c0a4..78ed413 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -751,12 +751,14 @@ void safeSetup() pinMode(OUTPUT_ENABLE_SENSOR, OUTPUT); + static_assert(HomieInternals::MAX_CONFIG_SETTING_SIZE >= MAX_CONFIG_SETTING_ITEMS, "Limits.hpp not adjusted MAX_CONFIG_SETTING_ITEMS"); if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { //increase the config settings Serial << "Limits.hpp is not adjusted, please search for this string and increase" << endl; return; } + static_assert(HomieInternals::MAX_JSON_CONFIG_FILE_SIZE >= MAX_JSON_CONFIG_FILE_SIZE_CUSTOM, "Limits.hpp not adjusted MAX_JSON_CONFIG_FILE_SIZE"); if (HomieInternals::MAX_JSON_CONFIG_FILE_SIZE < MAX_JSON_CONFIG_FILE_SIZE_CUSTOM) { //increase the config settings From 5dedc7672731c9b988503cf476da6adb381261cf Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 29 Apr 2022 10:47:54 +0200 Subject: [PATCH 4/9] formating only --- esp32/src/main.cpp | 129 +++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 78ed413..5dfc947 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -1,18 +1,18 @@ /** \addtogroup Controller * @{ - * + * * @file main.cpp * @author Ollo * @brief PlantControl * @version 0.1 * @date 2020-05-01 - * + * * @copyright Copyright (c) 2020 */ /****************************************************************************** * INCLUDES -******************************************************************************/ + ******************************************************************************/ #include "LogDefines.h" #include "FileUtils.h" #include "TimeUtils.h" @@ -37,20 +37,19 @@ #include "MQTTUtils.h" #include "esp_ota_ops.h" #if defined(TIMED_LIGHT_PIN) - #include "ulp-pwm.h" +#include "ulp-pwm.h" #endif - /****************************************************************************** * DEFINES -******************************************************************************/ + ******************************************************************************/ #define AMOUNT_SENOR_QUERYS 8 #define MAX_TANK_DEPTH 2000 #define REBOOT_LOOP_DETECTION_ERROR 5 /****************************************************************************** * FUNCTION PROTOTYPES -******************************************************************************/ + ******************************************************************************/ int determineNextPump(bool lowLight); void plantcontrol(); @@ -60,7 +59,7 @@ bool otaRunning = false; /****************************************************************************** * NON VOLATILE VARIABLES in DEEP SLEEP -******************************************************************************/ + ******************************************************************************/ #if defined(TIMED_LIGHT_PIN) RTC_DATA_ATTR bool timedLightLowVoltageTriggered = false; /**remember if it was shut down due to voltage level */ #endif // TIMED_LIGHT_PIN @@ -70,7 +69,7 @@ RTC_DATA_ATTR long consecutiveWateringPlant[MAX_PLANTS] = {0}; /****************************************************************************** * LOCAL VARIABLES -******************************************************************************/ + ******************************************************************************/ bool volatile mDownloadMode = false; /**< Controller must not sleep */ bool volatile mSensorsRead = false; /**< Sensors are read without Wifi or MQTT */ int volatile pumpToRun = -1; /** pump to run at the end of the cycle */ @@ -131,7 +130,7 @@ Plant mPlants[MAX_PLANTS] = { /****************************************************************************** * LOCAL FUNCTIONS -******************************************************************************/ + ******************************************************************************/ void finsihedCycleSucessfully() { @@ -153,7 +152,7 @@ void espDeepSleep(bool afterPump = false) if (mDownloadMode) { log(LOG_LEVEL_DEBUG, "abort deepsleep, DownloadMode active", LOG_DEBUG_CODE); - //if we manage to get to the download mode, the device can be restored + // if we manage to get to the download mode, the device can be restored finsihedCycleSucessfully(); return; } @@ -213,7 +212,7 @@ void espDeepSleep(bool afterPump = false) } } -//requires homie being started +// requires homie being started void readOneWireSensors() { for (uint8_t i = 0; i < sensors.getDeviceCount(); i++) @@ -241,7 +240,7 @@ void readOneWireSensors() if (!valid) { - //wrong family or crc errors on each retry + // wrong family or crc errors on each retry continue; } @@ -316,17 +315,19 @@ void readPowerSwitchedSensors() Plant plant = mPlants[i]; switch (plant.getSensorMode()) { - case CAPACITIVE_FREQUENCY: { - Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " hz " << mPlants[i].getCurrentMoisturePCT() << "%" << endl; - break; - } - case ANALOG_RESISTANCE_PROBE : { - Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " mV " << mPlants[i].getCurrentMoisturePCT() << "%" << endl; - break; - } - case NONE : { - - } + case CAPACITIVE_FREQUENCY: + { + Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " hz " << mPlants[i].getCurrentMoisturePCT() << "%" << endl; + break; + } + case ANALOG_RESISTANCE_PROBE: + { + Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " mV " << mPlants[i].getCurrentMoisturePCT() << "%" << endl; + break; + } + case NONE: + { + } } } @@ -486,12 +487,14 @@ int determineNextPump(bool isLowLight) } else { - if(mDownloadMode){ + if (mDownloadMode) + { plant.publishState("active+supressed"); - }else { + } + else + { plant.publishState("active"); } - } if (!plant.isHydroponic()) @@ -520,7 +523,7 @@ int determineNextPump(bool isLowLight) else { plant.publishState("wet"); - //plant was detected as wet, remove consecutive count + // plant was detected as wet, remove consecutive count consecutiveWateringPlant[i] = 0; } } @@ -529,7 +532,7 @@ int determineNextPump(bool isLowLight) /** * @brief Handle Mqtt commands to keep controller alive - * + * * @param range multiple transmitted values (not used for this function) * @param value single value * @return true when the command was parsed and executed succuessfully @@ -606,12 +609,12 @@ bool switch7(const HomieRange &range, const String &value) void initPumpLogic() { - //set targets + // set targets #ifdef FLOWMETER_PIN pumpTargetMl = mPlants[pumpToRun].getPumpMl(); - //0-6 are used for moisture measurment + // 0-6 are used for moisture measurment pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_7); pcnt_config_t pcnt_config = {}; // Instancia PCNT config pcnt_config.pulse_gpio_num = FLOWMETER_PIN; // Configura GPIO para entrada dos pulsos @@ -630,14 +633,13 @@ void initPumpLogic() #endif pumpStartTime = millis(); pumpTarget = millis() + (mPlants[pumpToRun].getPumpDuration() * 1000); - #ifdef FLOWMETER_PIN - log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s or " + String(pumpTargetMl) + "ml", LOG_PUMP_STARTED_CODE); - #else - log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s", LOG_PUMP_STARTED_CODE); - #endif - +#ifdef FLOWMETER_PIN + log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s or " + String(pumpTargetMl) + "ml", LOG_PUMP_STARTED_CODE); +#else + log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s", LOG_PUMP_STARTED_CODE); +#endif - //enable power + // enable power WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); digitalWrite(OUTPUT_ENABLE_PUMP, HIGH); delay(100); @@ -664,7 +666,7 @@ void pumpActiveLoop() mqttUpdateTick = true; } -long duration = millis() - pumpStartTime; + long duration = millis() - pumpStartTime; #ifdef FLOWMETER_PIN int16_t pulses; pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_7); @@ -674,11 +676,10 @@ long duration = millis() - pumpStartTime; log(LOG_LEVEL_ERROR, LOG_HARDWARECOUNTER_ERROR_MESSAGE, LOG_HARDWARECOUNTER_ERROR_CODE); targetReached = true; log(LOG_LEVEL_INFO, "Reached pump target ml " + String(pumpToRun), LOG_PUMP_STARTED_CODE); - } else { - float mLPumped = pulses/FLOWMETER_PULSES_PER_ML; //mLperMs*duration; + float mLPumped = pulses / FLOWMETER_PULSES_PER_ML; // mLperMs*duration; if (mLPumped >= pumpTargetMl) { targetReached = true; @@ -686,7 +687,7 @@ long duration = millis() - pumpStartTime; mPlants[pumpToRun].setProperty("pulses").send(String(pulses)); mPlants[pumpToRun].setProperty("waterusage").send(String(mLPumped)); } - + else if (mqttUpdateTick) { mPlants[pumpToRun].setProperty("pulses").send(String(pulses)); @@ -695,7 +696,6 @@ long duration = millis() - pumpStartTime; } #endif - if (millis() > pumpTarget) { mPlants[pumpToRun].setProperty("watertime").send(String(duration)); @@ -709,12 +709,12 @@ long duration = millis() - pumpStartTime; if (targetReached) { - //disable all + // disable all digitalWrite(OUTPUT_ENABLE_PUMP, LOW); mPlants[pumpToRun].deactivatePump(); - //disable loop, to prevent multi processing + // disable loop, to prevent multi processing 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(); espDeepSleep(true); } @@ -731,7 +731,7 @@ void safeSetup() WiFi.mode(WIFI_OFF); Serial.flush(); -//restore state before releasing pin, to prevent flickering +// restore state before releasing pin, to prevent flickering #if defined(TIMED_LIGHT_PIN) ulp_pwm_init(); #endif // TIMED_LIGHT_PIN @@ -754,25 +754,25 @@ void safeSetup() static_assert(HomieInternals::MAX_CONFIG_SETTING_SIZE >= MAX_CONFIG_SETTING_ITEMS, "Limits.hpp not adjusted MAX_CONFIG_SETTING_ITEMS"); if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { - //increase the config settings + // increase the config settings Serial << "Limits.hpp is not adjusted, please search for this string and increase" << endl; return; } static_assert(HomieInternals::MAX_JSON_CONFIG_FILE_SIZE >= MAX_JSON_CONFIG_FILE_SIZE_CUSTOM, "Limits.hpp not adjusted MAX_JSON_CONFIG_FILE_SIZE"); if (HomieInternals::MAX_JSON_CONFIG_FILE_SIZE < MAX_JSON_CONFIG_FILE_SIZE_CUSTOM) { - //increase the config settings + // increase the config settings Serial << "Limits.hpp is not adjusted, please search for this string and increase" << endl; return; } - /************************* Start Homie Framework ***************/ + /************************* Start Homie Framework ***************/ Homie_setFirmware("PlantControl", FIRMWARE_VERSION); Homie.disableLedFeedback(); Homie_setBrand("PlantControl"); // Set default values - //in seconds + // in seconds deepSleepTime.setDefaultValue(600).setValidator([](long candidate) { return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */); }); deepSleepNightTime.setDefaultValue(600); @@ -789,7 +789,7 @@ void safeSetup() #if defined(TIMED_LIGHT_PIN) timedLightPowerLevel.setDefaultValue(25).setValidator([](long candidate) - { return (candidate > 0) && (candidate <= (255)); }); + { return (candidate > 0) && (candidate <= (255)); }); timedLightStart.setDefaultValue(18).setValidator([](long candidate) { return (candidate > 0) && (candidate < (25)); }); timedLightEnd.setDefaultValue(23).setValidator([](long candidate) @@ -809,15 +809,13 @@ void safeSetup() } readPowerSwitchedSensors(); - Homie.setup(); Wire = TwoWire(0); Wire.setPins(SENSOR_TANK_SDA, SENSOR_TANK_SCL); Wire.begin(); - - /************************* Start One-Wire bus ***************/ + /************************* Start One-Wire bus ***************/ int tempInitStartTime = millis(); uint8_t sensorCount = 0U; @@ -835,7 +833,7 @@ void safeSetup() /* Measure temperature TODO idea: move this into setup */ if (sensorCount > 0) { - //sensors.setResolution(DS18B20_RESOLUTION); + // sensors.setResolution(DS18B20_RESOLUTION); sensors.requestTemperatures(); } @@ -905,7 +903,7 @@ void safeSetup() } readOneWireSensors(); - //prevent BOD to be paranoid + // prevent BOD to be paranoid WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); digitalWrite(OUTPUT_ENABLE_PUMP, HIGH); delay(100); @@ -1077,18 +1075,21 @@ void plantcontrol() #if defined(TIMED_LIGHT_PIN) bool isLowLight = mSolarVoltage <= 9; bool shouldLight = determineTimedLightState(isLowLight); - if(shouldLight){ + if (shouldLight) + { ulp_pwm_set_level(timedLightPowerLevel.get()); - }else { + } + else + { ulp_pwm_set_level(0); } - + #endif // TIMED_LIGHT_PIN - bool hasWater = true; //FIXME remaining > waterLevelMin.get(); - //FIXME no water warning message + bool hasWater = true; // FIXME remaining > waterLevelMin.get(); + // FIXME no water warning message pumpToRun = determineNextPump(isLowLight); - //early aborts + // early aborts if (pumpToRun != -1) { if (hasWater) @@ -1122,7 +1123,7 @@ bool determineTimedLightState(bool lowLight) long hoursStart = timedLightStart.get(); long hoursEnd = timedLightEnd.get(); - //ntp missing + // ntp missing if (getCurrentTime() < 10000) { timedLightNode.setProperty("state").send(String("Off, missing ntp")); From 662d7bc8532011658ed64276524e358e867cf4c0 Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 20 May 2022 01:00:04 +0200 Subject: [PATCH 5/9] add timer only mode, more sane default config --- esp32/include/HomieTypes.h | 2 ++ esp32/include/PlantCtrl.h | 8 +++++++- esp32/platformio.ini | 10 +++++----- esp32/src/PlantCtrl.cpp | 2 +- esp32/src/main.cpp | 6 ++++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/esp32/include/HomieTypes.h b/esp32/include/HomieTypes.h index f3d5cc9..d39cd3b 100644 --- a/esp32/include/HomieTypes.h +++ b/esp32/include/HomieTypes.h @@ -45,6 +45,8 @@ static const char *SENSOR_STRING[] = { #define MISSING_SENSOR -2 //plant uses only cooldown and duration, moisture is measured but ignored, allowedHours is ignored (eg. make a 30min on 30min off cycle) #define HYDROPONIC_MODE -3 +//plant uses cooldown and duration and workhours, moisture is measured but ignored +#define TIMER_ONLY -4 typedef struct PlantSettings_t { diff --git a/esp32/include/PlantCtrl.h b/esp32/include/PlantCtrl.h index ed211e4..332b1a7 100644 --- a/esp32/include/PlantCtrl.h +++ b/esp32/include/PlantCtrl.h @@ -75,6 +75,12 @@ public: return SENSOR_STRING[mode]; } + bool isTimerOnly() + { + long current = this->mSetting->pSensorDry->get(); + return equalish(current, TIMER_ONLY); + } + bool isHydroponic() { long current = this->mSetting->pSensorDry->get(); @@ -94,7 +100,7 @@ public: */ bool isPumpRequired() { - if (isHydroponic()) + if (isHydroponic() || isTimerOnly()) { // hydroponic only uses timer based controll return true; diff --git a/esp32/platformio.ini b/esp32/platformio.ini index 060c0c3..eaa7c40 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -15,11 +15,11 @@ framework = arduino build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -DPLANT0_SENSORTYPE=ANALOG_RESISTANCE_PROBE -DPLANT1_SENSORTYPE=ANALOG_RESISTANCE_PROBE - -DPLANT2_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT3_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT4_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT5_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT6_SENSORTYPE=CAPACITIVE_FREQUENCY + -DPLANT2_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT3_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT4_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT5_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT6_SENSORTYPE=ANALOG_RESISTANCE_PROBE board_build.partitions = defaultWithSmallerSpiffs.csv diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index cf33de6..246d880 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -31,7 +31,7 @@ void Plant::init(void) /* Initialize Home Settings validator */ this->mSetting->pSensorDry->setDefaultValue(DEACTIVATED_PLANT); this->mSetting->pSensorDry->setValidator([](long candidate) - { return (((candidate >= 0.0) && (candidate <= 100.0)) || equalish(candidate, DEACTIVATED_PLANT) || equalish(candidate, HYDROPONIC_MODE)); }); + { return (((candidate >= 0.0) && (candidate <= 100.0)) || equalish(candidate, DEACTIVATED_PLANT) || equalish(candidate, HYDROPONIC_MODE) || equalish(candidate, TIMER_ONLY)); }); this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8); // start at 8:00 this->mSetting->pPumpAllowedHourRangeStart->setValidator([](long candidate) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 5dfc947..369cbc5 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -460,7 +460,7 @@ int determineNextPump(bool isLowLight) log(LOG_LEVEL_DEBUG, String(String(i) + " No pump required: due to light"), LOG_DEBUG_CODE); continue; } - if (!plant.isHydroponic()) + if (! (plant.isHydroponic() || plant.isTimerOnly())) { if (equalish(plant.getCurrentMoistureRaw(), MISSING_SENSOR)) { @@ -497,7 +497,7 @@ int determineNextPump(bool isLowLight) } } - if (!plant.isHydroponic()) + if (! (plant.isHydroponic() || plant.isTimerOnly())) { consecutiveWateringPlant[i]++; } @@ -1137,9 +1137,11 @@ bool determineTimedLightState(bool lowLight) } int curHour = getCurrentHour(); + bool condition1 = ((hoursStart > hoursEnd) && (curHour >= hoursStart || curHour <= hoursEnd)); bool condition2 = /* Handle e.g. start = 8, end = 21 */ + ((hoursStart < hoursEnd) && (curHour >= hoursStart && curHour <= hoursEnd)); timedLightNode.setProperty("debug").send(String(curHour) + " " + String(hoursStart) + " " + String(hoursEnd) + " " + String(condition1) + " " + String(condition2)); From 37a08dede6f2835766456a28d14deeb58cae46aa Mon Sep 17 00:00:00 2001 From: Empire Date: Tue, 20 Dec 2022 00:04:57 +0100 Subject: [PATCH 6/9] add frozen water mode --- esp32/include/LogDefines.h | 3 +++ esp32/src/main.cpp | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/esp32/include/LogDefines.h b/esp32/include/LogDefines.h index dc6ff3c..4d3b894 100644 --- a/esp32/include/LogDefines.h +++ b/esp32/include/LogDefines.h @@ -29,6 +29,9 @@ #define LOG_PUMP_AND_DOWNLOADMODE "Download mode, ignoring pump request" #define LOG_PUMP_AND_DOWNLOADMODE_CODE 2 +#define LOG_VERY_COLD_WATER "Water potentially frozen, ignoring pump request" +#define LOG_VERY_COLD_WATER -7 + //msg is dynamic defined #define LOG_PUMP_INEFFECTIVE -4 #define LOG_PUMP_STARTED_CODE 10 diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 369cbc5..c9d6ead 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -90,6 +90,8 @@ long lastSendPumpUpdate = 0; long pumpTargetMl = -1; #endif +float waterTemp = 30; + /*************************** Hardware abstraction *****************************/ OneWire oneWire(SENSOR_ONEWIRE); @@ -267,6 +269,7 @@ void readOneWireSensors() { mqttWrite(&sensorTemp, TEMPERATUR_SENSOR_WATER, String(temp)); Serial << "Water Temperatur " << temp << " °C " << endl; + waterTemp = temp; } /* Always send the sensor address with the temperatur value */ mqttWrite(&sensorTemp, String(buf), String(temp)); @@ -1085,25 +1088,31 @@ void plantcontrol() } #endif // TIMED_LIGHT_PIN - + bool isLiquid = waterTemp > 5; bool hasWater = true; // FIXME remaining > waterLevelMin.get(); // FIXME no water warning message pumpToRun = determineNextPump(isLowLight); // early aborts if (pumpToRun != -1) { - if (hasWater) - { - if (mDownloadMode) + if(isLiquid){ + if (hasWater) { - log(LOG_LEVEL_INFO, LOG_PUMP_AND_DOWNLOADMODE, LOG_PUMP_AND_DOWNLOADMODE_CODE); + if (mDownloadMode) + { + log(LOG_LEVEL_INFO, LOG_PUMP_AND_DOWNLOADMODE, LOG_PUMP_AND_DOWNLOADMODE_CODE); + pumpToRun = -1; + } + } + else + { + log(LOG_LEVEL_ERROR, LOG_PUMP_BUTNOTANK_MESSAGE, LOG_PUMP_BUTNOTANK_CODE); pumpToRun = -1; } } - else - { + else{ log(LOG_LEVEL_ERROR, LOG_PUMP_BUTNOTANK_MESSAGE, LOG_PUMP_BUTNOTANK_CODE); - pumpToRun = -1; + pumpToRun = -1; } } From 2914a0c7a144c2565c8699a97762d9da9ed18c1c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 Jul 2022 11:48:43 +0200 Subject: [PATCH 7/9] slightly adjust range for better precision --- esp32/include/ControllerConfiguration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index 3d0ac5e..20e47e7 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -98,7 +98,7 @@ #define MOIST_SENSOR_MIN_FRQ 500 // 0.5kHz (500Hz margin) #define ANALOG_SENSOR_MAX_MV 1300 //successive approximation of good range -#define ANALOG_SENSOR_MIN_MV 300 //successive approximation of good range +#define ANALOG_SENSOR_MIN_MV 100 //successive approximation of good range #define SOLAR_VOLT_FACTOR 11 #define BATTSENSOR_INDEX_SOLAR 0 From 0d15479268e4d74bc0d3d1613e7ba5bfc546eb61 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 Jul 2022 11:48:52 +0200 Subject: [PATCH 8/9] remove leftover --- esp32/platformio.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/esp32/platformio.ini b/esp32/platformio.ini index eaa7c40..dcefede 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -29,7 +29,6 @@ lib_deps = ArduinoJson@6.16.1 DallasTemperature pololu/VL53L0X https://github.com/homieiot/homie-esp8266.git#develop - robtillaart/SHT2x@^0.1.3 [platformio] From 43e638a587da799cda3b316cd8a87a09769ecaba Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 20 Dec 2022 00:07:10 +0100 Subject: [PATCH 9/9] set more state retained --- esp32/src/PlantCtrl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index 246d880..a01f847 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -264,9 +264,9 @@ void Plant::advertise(void) { // Advertise topics mPump = this->mPlant->advertise("switch").setName("Pump").setDatatype("Boolean"); - this->mPlant->advertise("lastPump").setName("lastPump").setDatatype("Integer").setUnit("unixtime"); - this->mPlant->advertise("moist").setName("Percent").setDatatype("Float").setUnit("%"); - this->mPlant->advertise("moistraw").setName("adc").setDatatype("Float").setUnit("3.3/4096V"); - this->mPlant->advertise("state").setName("state").setDatatype("String"); + this->mPlant->advertise("lastPump").setName("lastPump").setDatatype("Integer").setUnit("unixtime").setRetained(true); + this->mPlant->advertise("moist").setName("Percent").setDatatype("Float").setUnit("%").setRetained(true); + this->mPlant->advertise("moistraw").setName("adc").setDatatype("Float").setUnit("3.3/4096V").setRetained(true); + this->mPlant->advertise("state").setName("state").setDatatype("String").setRetained(true); }