From dca13dfe44215340f61147822ca6497fee74a94f Mon Sep 17 00:00:00 2001 From: c3ma Date: Fri, 9 Oct 2020 19:29:28 +0200 Subject: [PATCH 01/12] Debugging board --- esp32test/Esp32DeepSleepTest/platformio.ini | 2 +- esp32test/Esp32DeepSleepTest/src/main.cpp | 113 +++++++++++++------- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/esp32test/Esp32DeepSleepTest/platformio.ini b/esp32test/Esp32DeepSleepTest/platformio.ini index e0a6037..768aa93 100644 --- a/esp32test/Esp32DeepSleepTest/platformio.ini +++ b/esp32test/Esp32DeepSleepTest/platformio.ini @@ -12,4 +12,4 @@ platform = espressif32 board = esp32doit-devkit-v1 framework = arduino -build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY \ No newline at end of file +build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY diff --git a/esp32test/Esp32DeepSleepTest/src/main.cpp b/esp32test/Esp32DeepSleepTest/src/main.cpp index fd5ee8b..246e2a8 100644 --- a/esp32test/Esp32DeepSleepTest/src/main.cpp +++ b/esp32test/Esp32DeepSleepTest/src/main.cpp @@ -4,6 +4,18 @@ #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 2 /* Time ESP32 will go to sleep (in seconds) */ +#define OUTPUT_PUMP0 23 /**< GPIO 23 */ +#define OUTPUT_PUMP1 22 /**< GPIO 22 */ +#define OUTPUT_PUMP2 21 /**< GPIO 21 */ +#define OUTPUT_PUMP3 19 /**< GPIO 19 */ +#define OUTPUT_PUMP4 18 /**< GPIO 18 */ +#define OUTPUT_PUMP5 5 /**< GPIO 5 */ +#define OUTPUT_PUMP6 15 /**< GPIO 15 */ + +#define OUTPUT_SENSOR 16 /**< GPIO 16 - Enable Sensors */ +#define OUTPUT_PUMP 13 /**< GPIO 13 - Enable Pumps */ + + RTC_DATA_ATTR int bootCount = 0; int secondBootCount = 0; @@ -22,25 +34,31 @@ void print_wakeup_reason(){ } } +void setAll2Off() { + digitalWrite(OUTPUT_PUMP0, LOW); + digitalWrite(OUTPUT_PUMP1, LOW); + digitalWrite(OUTPUT_PUMP2, LOW); + digitalWrite(OUTPUT_PUMP3, LOW); + digitalWrite(OUTPUT_PUMP4, LOW); + digitalWrite(OUTPUT_PUMP5, LOW); + digitalWrite(OUTPUT_PUMP6, LOW); + digitalWrite(OUTPUT_SENSOR, LOW); + digitalWrite(OUTPUT_PUMP, LOW); +} + void setup() { - pinMode(GPIO_NUM_23, OUTPUT); - pinMode(GPIO_NUM_22, OUTPUT); - pinMode(GPIO_NUM_21, OUTPUT); - pinMode(GPIO_NUM_19, OUTPUT); - pinMode(GPIO_NUM_18, OUTPUT); - pinMode(GPIO_NUM_5, OUTPUT); - pinMode(GPIO_NUM_4, OUTPUT); - pinMode(GPIO_NUM_15, OUTPUT); - pinMode(GPIO_NUM_13, OUTPUT); - digitalWrite(GPIO_NUM_23, HIGH); - digitalWrite(GPIO_NUM_22, HIGH); - digitalWrite(GPIO_NUM_21, HIGH); - digitalWrite(GPIO_NUM_19, HIGH); - digitalWrite(GPIO_NUM_18, HIGH); - digitalWrite(GPIO_NUM_5, HIGH); - digitalWrite(GPIO_NUM_4, HIGH); - digitalWrite(GPIO_NUM_15, HIGH); - digitalWrite(GPIO_NUM_13, HIGH); + pinMode(OUTPUT_PUMP0, OUTPUT); + pinMode(OUTPUT_PUMP1, OUTPUT); + pinMode(OUTPUT_PUMP2, OUTPUT); + pinMode(OUTPUT_PUMP3, OUTPUT); + pinMode(OUTPUT_PUMP4, OUTPUT); + pinMode(OUTPUT_PUMP5, OUTPUT); + pinMode(OUTPUT_PUMP6, OUTPUT); + pinMode(OUTPUT_SENSOR, OUTPUT); + pinMode(OUTPUT_PUMP, OUTPUT); + + setAll2Off(); + Serial.begin(115200); //Increment boot number and print it every reboot @@ -77,31 +95,52 @@ void setup() { pinMode(GPIO_NUM_12, INPUT_PULLUP); } + + void loop() { Serial.println("------------"); Serial.flush(); delay(1000); digitalWrite(GPIO_NUM_23, analogRead(GPIO_NUM_34) > 3500); - Serial.println(analogRead(GPIO_NUM_34)); - - Serial.println(analogRead(GPIO_NUM_35)); - - Serial.println(analogRead(GPIO_NUM_32)); - - Serial.println(analogRead(GPIO_NUM_33)); - - Serial.println(analogRead(GPIO_NUM_25)); - - Serial.println(analogRead(GPIO_NUM_26)); - - Serial.println(analogRead(GPIO_NUM_27)); - Serial.println(analogRead(GPIO_NUM_14)); - Serial.println(analogRead(GPIO_NUM_12)); - - gpio_hold_en(GPIO_NUM_4); - gpio_hold_en(GPIO_NUM_13); - gpio_hold_en(GPIO_NUM_15); + digitalWrite(OUTPUT_PUMP0, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP1, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP2, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP3, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP4, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP5, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP6, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_SENSOR, HIGH); + delay(1000); + setAll2Off(); + + digitalWrite(OUTPUT_PUMP, HIGH); + delay(1000); + setAll2Off(); + + delay(1000); + delay(1000); gpio_deep_sleep_hold_en(); esp_deep_sleep_start(); From d1d89d66f6d43610223201a6f11cbf0b56043cc0 Mon Sep 17 00:00:00 2001 From: c3ma Date: Fri, 9 Oct 2020 20:45:47 +0200 Subject: [PATCH 02/12] Deepsleep and pump are working --- esp32test/Esp32DeepSleepTest/src/main.cpp | 89 +++++++++++++---------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/esp32test/Esp32DeepSleepTest/src/main.cpp b/esp32test/Esp32DeepSleepTest/src/main.cpp index 246e2a8..b918c7b 100644 --- a/esp32test/Esp32DeepSleepTest/src/main.cpp +++ b/esp32test/Esp32DeepSleepTest/src/main.cpp @@ -2,7 +2,11 @@ #include "esp_sleep.h" #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ -#define TIME_TO_SLEEP 2 /* Time ESP32 will go to sleep (in seconds) */ +#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ + +#define SENSOR_LIPO 34 /**< GPIO 34 (ADC1) */ +#define SENSOR_SOLAR 35 /**< GPIO 35 (ADC1) */ + #define OUTPUT_PUMP0 23 /**< GPIO 23 */ #define OUTPUT_PUMP1 22 /**< GPIO 22 */ @@ -15,8 +19,18 @@ #define OUTPUT_SENSOR 16 /**< GPIO 16 - Enable Sensors */ #define OUTPUT_PUMP 13 /**< GPIO 13 - Enable Pumps */ +#define SENSOR_PLANT0 32 /**< GPIO 32 (ADC1) */ + + +#define ADC_TO_VOLT(adc) ((adc) * 3.3 ) / 4095) +#define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc) * 3.3 * (multi)) / 4095) + + +#define SOLAR_VOLT(adc) ADC_TO_VOLT_WITH_MULTI(adc, 4.0306) /**< 100k and 33k voltage dividor */ +#define ADC_5V_TO_3V3(adc) ADC_TO_VOLT_WITH_MULTI(adc, 1.7) /**< 33k and 47k8 voltage dividor */ RTC_DATA_ATTR int bootCount = 0; +RTC_DATA_ATTR int pumpActive = 0; int secondBootCount = 0; void print_wakeup_reason(){ @@ -57,6 +71,10 @@ void setup() { pinMode(OUTPUT_SENSOR, OUTPUT); pinMode(OUTPUT_PUMP, OUTPUT); + pinMode(SENSOR_LIPO, ANALOG); + pinMode(SENSOR_SOLAR, ANALOG); + pinMode(SENSOR_PLANT0, ANALOG); + setAll2Off(); Serial.begin(115200); @@ -93,55 +111,46 @@ void setup() { pinMode(GPIO_NUM_27, INPUT_PULLUP); pinMode(GPIO_NUM_14, INPUT_PULLUP); pinMode(GPIO_NUM_12, INPUT_PULLUP); + + + /* Sensor activieren */ + digitalWrite(OUTPUT_SENSOR, HIGH); + + /* activate power pump and pump 0 */ + digitalWrite(OUTPUT_PUMP, HIGH); } -void loop() { - Serial.println("------------"); - Serial.flush(); - delay(1000); - digitalWrite(GPIO_NUM_23, analogRead(GPIO_NUM_34) > 3500); +void loop() { + double value = analogRead(SENSOR_LIPO); - digitalWrite(OUTPUT_PUMP0, HIGH); - delay(1000); - setAll2Off(); + Serial.println(value); + + double volt = ADC_5V_TO_3V3(value); + Serial.print("Lipo: "); + Serial.println(volt); - digitalWrite(OUTPUT_PUMP1, HIGH); - delay(1000); - setAll2Off(); + pumpActive = (pumpActive + 1) % 2; + if (pumpActive) { + digitalWrite(OUTPUT_PUMP0, HIGH); + } else { + digitalWrite(OUTPUT_PUMP0, LOW); + } - digitalWrite(OUTPUT_PUMP2, HIGH); - delay(1000); - setAll2Off(); + double solarVal = analogRead(SENSOR_SOLAR); + + Serial.println(solarVal); + + double solarVolt = SOLAR_VOLT(solarVal); + Serial.print("Solar: "); + Serial.println(solarVolt); - digitalWrite(OUTPUT_PUMP3, HIGH); - delay(1000); - setAll2Off(); + Serial.print("Moist0: "); + Serial.println(analogRead(SENSOR_PLANT0)); - digitalWrite(OUTPUT_PUMP4, HIGH); - delay(1000); - setAll2Off(); - - digitalWrite(OUTPUT_PUMP5, HIGH); - delay(1000); - setAll2Off(); - - digitalWrite(OUTPUT_PUMP6, HIGH); - delay(1000); - setAll2Off(); - - digitalWrite(OUTPUT_SENSOR, HIGH); - delay(1000); - setAll2Off(); - - digitalWrite(OUTPUT_PUMP, HIGH); - delay(1000); - setAll2Off(); - - delay(1000); delay(1000); gpio_deep_sleep_hold_en(); - + gpio_hold_en(GPIO_NUM_13); esp_deep_sleep_start(); } \ No newline at end of file From 8aa9a2147efc13fe1fec731765a7e9a9b33e8b24 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 13 Oct 2020 20:16:28 +0200 Subject: [PATCH 03/12] Alive topic added --- esp32/include/ControllerConfiguration.h | 2 +- esp32/src/main.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index 1da04b5..4c2520b 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -11,7 +11,7 @@ #ifndef CONTROLLER_CONFIG_H #define CONTROLLER_CONFIG_H -#define FIRMWARE_VERSION "1.0.1" +#define FIRMWARE_VERSION "1.0.2" #define ADC_TO_VOLT(adc) ((adc) * 3.3 ) / 4095) #define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc) * 3.3 * (multi)) / 4095) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index ac4e3bb..0523e6a 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -25,6 +25,7 @@ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minut bool mLoopInited = false; bool mDeepSleep = false; +bool mAlive=false; /**< Controller must not sleep */ int plantSensor1 = 0; @@ -67,6 +68,7 @@ HomieNode sensorLipo("lipo", "Battery Status", "Lipo"); HomieNode sensorSolar("solar", "Solar Status", "Solarpanel"); HomieNode sensorWater("water", "WaterSensor", "Water"); HomieNode sensorTemp("temperature", "Temperature", "temperature"); +HomieNode stayAlive("stay", "alive", "alive"); HomieSetting deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)"); HomieSetting deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)"); @@ -285,6 +287,26 @@ bool switchGeneralPumpHandler(const int pump, const HomieRange& range, const Str } } +/** + * @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 + * @return false on errors when parsing the request + */ +bool aliveHandler(const HomieRange& range, const String& value) { + if (range.isRange) return false; // only one controller is present + + if (value.equals("ON") || value.equals("On") || value.equals("1")) { + mAlive=true; + } else { + mAlive=false; + } + Serial << "Controller " << (mAlive ? " has coffee" : " is tired") << endl; + return true; +} + /** * @brief Handle Mqtt commands for the pumpe, responsible for the first plant * @@ -380,7 +402,6 @@ void setup() { /* activate Wifi again */ WiFi.mode(WIFI_STA); - 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; @@ -479,6 +500,8 @@ void setup() { .setDatatype("number") .setUnit("V"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); + + stayAlive.advertise("stay").setName("Alive").setDatatype("number").settable(aliveHandler); } Homie.setup(); From b87cfdb772c8c8f58adcf478b105f490023ad589 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 13 Oct 2020 20:24:08 +0200 Subject: [PATCH 04/12] Moved configuration and webserver --- esp32/{ => data}/homie/.gitignore | 0 esp32/{ => data}/homie/ui_bundle.gz | Bin esp32/platformio.ini | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename esp32/{ => data}/homie/.gitignore (100%) rename esp32/{ => data}/homie/ui_bundle.gz (100%) diff --git a/esp32/homie/.gitignore b/esp32/data/homie/.gitignore similarity index 100% rename from esp32/homie/.gitignore rename to esp32/data/homie/.gitignore diff --git a/esp32/homie/ui_bundle.gz b/esp32/data/homie/ui_bundle.gz similarity index 100% rename from esp32/homie/ui_bundle.gz rename to esp32/data/homie/ui_bundle.gz diff --git a/esp32/platformio.ini b/esp32/platformio.ini index cfd3748..360c453 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -18,4 +18,4 @@ board_build.partitions = huge_app.csv ; the latest development brankitchen-lightch (convention V3.0.x) lib_deps = https://github.com/homieiot/homie-esp8266.git#v3.0 OneWire -upload_port = /dev/ttyUSB0 +upload_port = /dev/ttyUSB1 From 85994304581603e60fdf87542cde1d680e679540 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 13 Oct 2020 21:09:20 +0200 Subject: [PATCH 05/12] Describe filesystem uploade --- esp32/data/homie/Readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 esp32/data/homie/Readme.md diff --git a/esp32/data/homie/Readme.md b/esp32/data/homie/Readme.md new file mode 100644 index 0000000..dafb240 --- /dev/null +++ b/esp32/data/homie/Readme.md @@ -0,0 +1,9 @@ +# Filesystem +## Configuration +Use the config-example.json from the host folder and create here a config.json file. +## HowTo upload +Start Platform.io +Open a new Atom-Terminal and generate the filesystem with the following command : +```pio run -t buildfs``` +Upload this new generated filesystem with: +```pio run -t uploadfs``` From 7991a37d4dd3febb36d746f6b1dd481c2e08f080 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 13 Oct 2020 21:22:21 +0200 Subject: [PATCH 06/12] Configuration is flashable --- esp32/host/config-example.json | 17 +++++++++++++++-- esp32/src/main.cpp | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/esp32/host/config-example.json b/esp32/host/config-example.json index 5c1d81c..b383013 100644 --- a/esp32/host/config-example.json +++ b/esp32/host/config-example.json @@ -18,19 +18,32 @@ "enabled": true }, "settings": { - "deepsleep": 60000, + "deepsleep" : 60000, + "nightsleep" : 60000, "pumpdeepsleep": 1000, "watermaxlevel": 50, "watermin" : 5, "plants" : 3, + "moist0" : 2000, "moist1" : 2000, "moist2" : 2000, "moist3" : 2000, + "moist4" : 2000, + "moist5" : 2000, + "moist6" : 2000, + "plant0MaxPumpTime": 1000, "plant1MaxPumpTime": 1000, "plant2MaxPumpTime": 1000, "plant3MaxPumpTime": 1000, + "plant4MaxPumpTime": 1000, + "plant5MaxPumpTime": 1000, + "plant6MaxPumpTime": 1000, + "plant0MinPumpIdle": 10000, "plant1MinPumpIdle": 10000, "plant2MinPumpIdle": 10000, - "plant3MinPumpIdle": 10000 + "plant3MinPumpIdle": 10000, + "plant4MinPumpIdle": 10000, + "plant5MinPumpIdle": 10000, + "plant6MinPumpIdle": 10000 } } diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 0523e6a..403df77 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -405,6 +405,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; } Homie_setFirmware("PlantControl", FIRMWARE_VERSION); From 089476facc1f7db703904f1ec38080482ef3a1e0 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 13 Oct 2020 21:47:56 +0200 Subject: [PATCH 07/12] Controller will stay alive if it has to --- esp32/src/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 403df77..3925888 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -231,7 +231,7 @@ void loopHandler() { if (waterLevelPercent <= waterMinPercent.get()) { /* let the ESP sleep qickly, as nothing must be done */ if ((millis() >= (MIN_TIME_RUNNING * MS_TO_S)) && (deepSleepTime.get() > 0)) { - mDeepSleep = true; + mDeepSleep = true; Serial << "No Water for pumps" << endl; } } @@ -240,7 +240,6 @@ void loopHandler() { /* Pump is running, go to sleep after defined time */ if (millis() >= ((MIN_TIME_RUNNING + 5) && (deepSleepTime.get() > 0))) { - Serial << "No sleeping activated (maximum)" << endl; mDeepSleep = true; } else if ((millis() >= ((MIN_TIME_RUNNING * MS_TO_S) + 0)) && (deepSleepTime.get() > 0)) { @@ -303,7 +302,7 @@ bool aliveHandler(const HomieRange& range, const String& value) { } else { mAlive=false; } - Serial << "Controller " << (mAlive ? " has coffee" : " is tired") << endl; + Serial << "HOMIE | Controller " << (mAlive ? " has coffee" : " is tired") << endl; return true; } @@ -502,7 +501,7 @@ void setup() { .setUnit("V"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); - stayAlive.advertise("stay").setName("Alive").setDatatype("number").settable(aliveHandler); + stayAlive.advertise("alive").setName("Alive").setDatatype("number").settable(aliveHandler); } Homie.setup(); @@ -669,8 +668,17 @@ void loop() { } } else { - Serial << (millis()/ 1000) << "s running; sleeeping ..." << endl; - Serial.flush(); - esp_deep_sleep_start(); + if (!mAlive) { + Serial << (millis()/ 1000) << "s running; sleeeping ..." << endl; + Serial.flush(); + esp_deep_sleep_start(); + } else { + mDeepSleep = false; + + if (((millis()) % 10000) == 0) { + /* tell everybody how long we are awoken */ + stayAlive.setProperty("alive").send( String(millis()/ 1000) ); + } + } } } From 5bda74bbcc9f430c89bd632899a7da9366f7b277 Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 14 Oct 2020 17:10:55 +0200 Subject: [PATCH 08/12] Temp sensor added --- esp32test/Esp32DeepSleepTest/platformio.ini | 1 + esp32test/Esp32DeepSleepTest/src/main.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/esp32test/Esp32DeepSleepTest/platformio.ini b/esp32test/Esp32DeepSleepTest/platformio.ini index 768aa93..27cb0c8 100644 --- a/esp32test/Esp32DeepSleepTest/platformio.ini +++ b/esp32test/Esp32DeepSleepTest/platformio.ini @@ -13,3 +13,4 @@ platform = espressif32 board = esp32doit-devkit-v1 framework = arduino build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY +lib_deps = OneWire diff --git a/esp32test/Esp32DeepSleepTest/src/main.cpp b/esp32test/Esp32DeepSleepTest/src/main.cpp index b918c7b..161e0b8 100644 --- a/esp32test/Esp32DeepSleepTest/src/main.cpp +++ b/esp32test/Esp32DeepSleepTest/src/main.cpp @@ -1,5 +1,6 @@ #include #include "esp_sleep.h" +#include #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ @@ -7,6 +8,8 @@ #define SENSOR_LIPO 34 /**< GPIO 34 (ADC1) */ #define SENSOR_SOLAR 35 /**< GPIO 35 (ADC1) */ +#define SENSOR_DS18B20 2 /**< GPIO 2 */ + #define OUTPUT_PUMP0 23 /**< GPIO 23 */ #define OUTPUT_PUMP1 22 /**< GPIO 22 */ @@ -33,6 +36,8 @@ RTC_DATA_ATTR int bootCount = 0; RTC_DATA_ATTR int pumpActive = 0; int secondBootCount = 0; +Ds18B20 ds(SENSOR_DS18B20); + void print_wakeup_reason(){ esp_sleep_wakeup_cause_t wakeup_reason; @@ -61,6 +66,7 @@ void setAll2Off() { } void setup() { + pinMode(OUTPUT_PUMP0, OUTPUT); pinMode(OUTPUT_PUMP1, OUTPUT); pinMode(OUTPUT_PUMP2, OUTPUT); @@ -126,6 +132,18 @@ void loop() { double value = analogRead(SENSOR_LIPO); Serial.println(value); + + float temp[2] = {0, 0}; + float* pFloat = temp; + + Serial.print("DS18B20 sensors: "); + Serial.println(ds.readDevices()); + delay(200); + if (ds.readAllTemperatures(pFloat, 2) > 0) { + Serial.println(temp[0]); + Serial.println(temp[1]); + } + double volt = ADC_5V_TO_3V3(value); Serial.print("Lipo: "); From e1c4ca7e98f4590db44ad6fb640217c70f27b201 Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 14 Oct 2020 17:50:13 +0200 Subject: [PATCH 09/12] Empires Wunschliste --- esp32/Readme.md | 59 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/esp32/Readme.md b/esp32/Readme.md index b391aef..81d0013 100644 --- a/esp32/Readme.md +++ b/esp32/Readme.md @@ -1,15 +1,58 @@ # PlantControl ## Hardware -Uses ESP32MniniKit +Uses ESP32MiniKit ### Used Pins: -* IO27 for DS18B20 temperature sensor +* See '''include/ControllerConfiguration.h''' ## Software -* Mqtt topics - * temperature - * switch1 -* Settings: - * ds18b20 - Enables Temperature measurement - * deepsleep - Setup intervall how long the controller sleeps +* MQTT topics + +# Hardware +## Features +* Support for up to + * 7 Moister sensors + * 7 Pumps + * Sensors + * Solar powered (voltage) + * Lipo-Powered (voltage) + * Temperature + * Custom GPIO + +# Features +## Empires Wunschliste + * Pflanze + * Pumpe + * Zeitspann (wann laufen darf) + * Helligkeitstrigger (Um den Morgen zum pumpen zu erkennen) + * Maximal Dauer zum Pumpen (als Zeit oder Milliliter) + * Zeitspanne zwischen zwei Pumpvorgängen + * Moister sensor + * Oberen + * Unteren Wert +* Tank + * Füllstand Anzeige (in Liter) + * Minimum Wasserstand (in cm damit Pumpen nicht leer laufen; enspricht 0 nutzbaren Liter) + * Trigger-Erinnerungen um Wasser nachzufüllen + * Maximaler Wasserstand des Tanks (in cm & Liter) +* System + * Tiefentladungsschutz vom LIPO (fest im Controller die Spannung festlegen) + * 3.5V unterschritten, dann nur noch Deepsleep + * MQTT Topic, wenn Spannung unterschritten wurde + * Lipo innerhalb 24h nicht geladen -> MQTT Topic + * Deep-Sleep + * Mode1: + * Nur Sensor werte einsameln + * Wird verlassen bei Aktionen + * Pumpe schalten + * MQTT Nachrichten + * nach x Minuten nur in Mode1 + * Mode2: + * WLAN aktivieren und Werte über MQTT raus hauen + * aktuelle Werte raushauen + * MQTT lesen + * Mode3: + * Deepsleep verboten (MQTT topic, retained) + * alle Pumpen & Sensoren deaktiviert + From 24b842f5a3124a5abee27456dca0b75d35e3f20d Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 14 Oct 2020 19:01:13 +0200 Subject: [PATCH 10/12] Default values in configuration set --- esp32/platformio.ini | 2 +- esp32/src/main.cpp | 51 ++++++++++++++++++++------------------------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/esp32/platformio.ini b/esp32/platformio.ini index 360c453..cfd3748 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -18,4 +18,4 @@ board_build.partitions = huge_app.csv ; the latest development brankitchen-lightch (convention V3.0.x) lib_deps = https://github.com/homieiot/homie-esp8266.git#v3.0 OneWire -upload_port = /dev/ttyUSB1 +upload_port = /dev/ttyUSB0 diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 3925888..a446f39 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -79,7 +79,7 @@ HomieSetting plantCnt("plants", "amout of plants to control (1 ... 7)"); HomieSetting waterLevel("watermaxlevel", "Water maximum level in centimeter (50 cm default)"); HomieSetting waterMinPercent("watermin", "Minimum percentage of water, to activate the pumps (default 5%)"); #endif -HomieSetting plant0SensorTrigger("moist0", "Moist0 sensor value, when pump activates"); +HomieSetting plant0SensorTrigger("moist0", "Moist0 sensor dry "); HomieSetting plant1SensorTrigger("moist1", "Moist1 sensor value, when pump activates"); HomieSetting plant2SensorTrigger("moist2", "Moist2 sensor value, when pump activates"); HomieSetting plant3SensorTrigger("moist3", "Moist3 sensor value, when pump activates"); @@ -104,27 +104,13 @@ HomieSetting wateringIdleTime6("plant6MinPumpIdle", "time in seconds Pump6 Ds18B20 dallas(SENSOR_DS18B20); Plant mPlants[MAX_PLANTS] = { -#if (MAX_PLANTS >= 1) Plant(SENSOR_PLANT0, OUTPUT_PUMP0, &plant0, &plant0SensorTrigger, &wateringTime0, &wateringIdleTime0), -#endif -#if (MAX_PLANTS >= 2) Plant(SENSOR_PLANT1, OUTPUT_PUMP1, &plant1, &plant1SensorTrigger, &wateringTime1, &wateringIdleTime1), -#endif -#if (MAX_PLANTS >= 3) Plant(SENSOR_PLANT2, OUTPUT_PUMP2, &plant2, &plant2SensorTrigger, &wateringTime2, &wateringIdleTime2), -#endif -#if (MAX_PLANTS >= 4) - Plant(SENSOR_PLANT3, OUTPUT_PUMP3, &plant3, &plant3SensorTrigger, &wateringTime3, &wateringIdleTime3), -#endif -#if (MAX_PLANTS >= 5) - Plant(SENSOR_PLANT4, OUTPUT_PUMP4, &plant4, &plant4SensorTrigger, &wateringTime4, &wateringIdleTime4), -#endif -#if (MAX_PLANTS >= 6) - Plant(SENSOR_PLANT5, OUTPUT_PUMP5, &plant5, &plant5SensorTrigger, &wateringTime5, &wateringIdleTime5), -#endif -#if (MAX_PLANTS >= 7) + Plant(SENSOR_PLANT3, OUTPUT_PUMP3, &plant3, &plant3SensorTrigger, &wateringTime3, &wateringIdleTime3), + Plant(SENSOR_PLANT4, OUTPUT_PUMP4, &plant4, &plant4SensorTrigger, &wateringTime4, &wateringIdleTime4), + Plant(SENSOR_PLANT5, OUTPUT_PUMP5, &plant5, &plant5SensorTrigger, &wateringTime5, &wateringIdleTime5), Plant(SENSOR_PLANT6, OUTPUT_PUMP6, &plant6, &plant6SensorTrigger, &wateringTime6, &wateringIdleTime6) -#endif }; void readAnalogValues() { @@ -411,7 +397,6 @@ void setup() { Homie.setLoopFunction(loopHandler); mConfigured = Homie.isConfigured(); - if (mConfigured) { // Load the settings deepSleepTime.setDefaultValue(0); deepSleepNightTime.setDefaultValue(0); @@ -423,22 +408,31 @@ void setup() { wateringTime5.setDefaultValue(60); wateringTime6.setDefaultValue(60); plantCnt.setDefaultValue(0).setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 6) ); + return ((candidate >= 0) && (candidate <= 7) ); }); - plant1SensorTrigger.setDefaultValue(0); - plant2SensorTrigger.setDefaultValue(0); - plant3SensorTrigger.setDefaultValue(0); - #if (MAX_PLANTS >= 4) - plant4SensorTrigger.setDefaultValue(0); - plant5SensorTrigger.setDefaultValue(0); - plant6SensorTrigger.setDefaultValue(0); - #endif + plant0SensorTrigger.setDefaultValue(4000); + plant1SensorTrigger.setDefaultValue(4000); + plant2SensorTrigger.setDefaultValue(4000); + plant3SensorTrigger.setDefaultValue(4000); + plant4SensorTrigger.setDefaultValue(4000); + plant5SensorTrigger.setDefaultValue(4000); + plant6SensorTrigger.setDefaultValue(4000); + wateringDeepSleep.setDefaultValue(60); + + wateringIdleTime0.setDefaultValue(60); + wateringIdleTime1.setDefaultValue(60); + wateringIdleTime2.setDefaultValue(60); + wateringIdleTime3.setDefaultValue(60); + wateringIdleTime4.setDefaultValue(60); + wateringIdleTime5.setDefaultValue(60); + wateringIdleTime6.setDefaultValue(60); #ifdef HC_SR04 waterLevel.setDefaultValue(50); waterMinPercent.setDefaultValue(5); #endif + if (mConfigured) { // Advertise topics plant1.advertise("switch").setName("Pump 1") .setDatatype("boolean") @@ -501,6 +495,7 @@ void setup() { .setUnit("V"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); + // Mode 3 stayAlive.advertise("alive").setName("Alive").setDatatype("number").settable(aliveHandler); } From 1a4cddc36653e92c7d8ddaf0b188731f0b30704e Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 14 Oct 2020 20:07:56 +0200 Subject: [PATCH 11/12] Plant object expanded with settings --- esp32/PlantControl.code-workspace | 3 +- esp32/include/ControllerConfiguration.h | 3 +- esp32/include/PlantCtrl.h | 16 ++--- esp32/src/PlantCtrl.cpp | 68 +++++++++++++++--- esp32/src/main.cpp | 94 ++++++------------------- 5 files changed, 90 insertions(+), 94 deletions(-) diff --git a/esp32/PlantControl.code-workspace b/esp32/PlantControl.code-workspace index fadf157..a513b43 100644 --- a/esp32/PlantControl.code-workspace +++ b/esp32/PlantControl.code-workspace @@ -12,7 +12,8 @@ "istream": "cpp", "limits": "cpp", "streambuf": "cpp", - "functional": "cpp" + "functional": "cpp", + "string": "cpp" } } } diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index 4c2520b..e099349 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -47,7 +47,8 @@ #define MIN_TIME_RUNNING 5UL /**< Amount of seconds the controller must stay awoken */ #define MAX_PLANTS 7 #define EMPTY_LIPO_MULTIPL 3 /**< Multiplier to increase time for sleeping when lipo is empty */ -#define MINIMUM_LIPO_VOLT 3.3f /**< Minimum voltage of the Lipo, that must be present */ +#define MINIMUM_LIPO_VOLT 3.6f /**< Minimum voltage of the Lipo, that must be present */ +#define NO_LIPO_VOLT 2.0f /**< No Lipo connected */ #define MINIMUM_SOLAR_VOLT 4.0f /**< Minimum voltage of the sun, to detect daylight */ #define HC_SR04 /**< Ultrasonic distance sensor to measure water level */ diff --git a/esp32/include/PlantCtrl.h b/esp32/include/PlantCtrl.h index da7a22d..df1a914 100644 --- a/esp32/include/PlantCtrl.h +++ b/esp32/include/PlantCtrl.h @@ -25,9 +25,12 @@ private: int mAnalogValue=0; /**< moist sensor values, used for a calculation */ HomieNode *mPlant = NULL; - HomieSetting *mSensorTriggerLevel=NULL; - HomieSetting *mWateringTime=NULL; - HomieSetting *mWateringIdleTime=NULL; + HomieSetting *mSensorDry; + HomieSetting *mSensorWet; + HomieSetting *mPumpAllowedHourRangeStart; + HomieSetting *mPumpAllowedHourRangeEnd; + HomieSetting *mPumpOnlyWhenLowLight; + HomieSetting *mPumpCooldownInHours; public: @@ -38,10 +41,7 @@ public: * @param pinPump Pin of the Pump to use */ Plant(int pinSensor, int pinPump, - HomieNode *plant, - HomieSetting *sensorTriggerLevel, - HomieSetting *wateringTime, - HomieSetting *wateringIdleTime); + int plantId); /** * @brief Add a value, to be measured @@ -81,7 +81,7 @@ public: * @return false */ bool isPumpRequired() { - return (this->mSensorTriggerLevel != NULL) && (this->mValue < this->mSensorTriggerLevel->get()); + return (this->mSensorWet != NULL) && (this->mValue < this->mSensorWet->get()); } HomieInternals::SendingPromise& setProperty(const String& property) const { diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index 613afe4..fdba9cd 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -12,17 +12,63 @@ #include "PlantCtrl.h" -Plant::Plant(int pinSensor, int pinPump, - HomieNode *plant, - HomieSetting *sensorTriggerLevel, - HomieSetting *wateringTime, - HomieSetting *wateringIdleTime) { - this->mPlant=plant; - this->mPinSensor = pinSensor; - this->mPinPump = pinPump; - this->mSensorTriggerLevel=sensorTriggerLevel; - this->mWateringTime=wateringTime; - this->mWateringIdleTime=wateringIdleTime; +Plant::Plant(int pinSensor, int pinPump,int plantId) { + this->mPinSensor = pinSensor; + this->mPinPump = pinPump; + + char plantIdChar = plantId+'0'; + + { + char* name = "moistZdry"; + name[6]= 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) ); + }); + } } void Plant::addSenseValue(int analog) { diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index a446f39..4fa8096 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -73,44 +73,22 @@ HomieNode stayAlive("stay", "alive", "alive"); HomieSetting deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)"); HomieSetting deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)"); HomieSetting wateringDeepSleep("pumpdeepsleep", "time seconds to sleep, while a pump is running"); -HomieSetting plantCnt("plants", "amout of plants to control (1 ... 7)"); -#ifdef HC_SR04 -HomieSetting waterLevel("watermaxlevel", "Water maximum level in centimeter (50 cm default)"); -HomieSetting waterMinPercent("watermin", "Minimum percentage of water, to activate the pumps (default 5%)"); -#endif -HomieSetting plant0SensorTrigger("moist0", "Moist0 sensor dry "); -HomieSetting plant1SensorTrigger("moist1", "Moist1 sensor value, when pump activates"); -HomieSetting plant2SensorTrigger("moist2", "Moist2 sensor value, when pump activates"); -HomieSetting plant3SensorTrigger("moist3", "Moist3 sensor value, when pump activates"); -HomieSetting plant4SensorTrigger("moist4", "Moist4 sensor value, when pump activates"); -HomieSetting plant5SensorTrigger("moist5", "Moist5 sensor value, when pump activates"); -HomieSetting plant6SensorTrigger("moist6", "Moist6 sensor value, when pump activates"); -HomieSetting wateringTime0("plant0MaxPumpTime", "time seconds Pump0 is running (60 is the default)"); -HomieSetting wateringTime1("plant1MaxPumpTime", "time seconds Pump1 is running (60 is the default)"); -HomieSetting wateringTime2("plant2MaxPumpTime", "time seconds Pump2 is running (60 is the default)"); -HomieSetting wateringTime3("plant3MaxPumpTime", "time seconds Pump3 is running (60 is the default)"); -HomieSetting wateringTime4("plant4MaxPumpTime", "time seconds Pump4 is running (60 is the default)"); -HomieSetting wateringTime5("plant5MaxPumpTime", "time seconds Pump5 is running (60 is the default)"); -HomieSetting wateringTime6("plant6MaxPumpTime", "time seconds Pump6 is running (60 is the default)"); -HomieSetting wateringIdleTime0("plant0MinPumpIdle", "time in seconds Pump0 will wait (60 is the default)"); -HomieSetting wateringIdleTime1("plant1MinPumpIdle", "time in seconds Pump1 will wait (60 is the default)"); -HomieSetting wateringIdleTime2("plant2MinPumpIdle", "time in seconds Pump2 will wait (60 is the default)"); -HomieSetting wateringIdleTime3("plant3MinPumpIdle", "time in seconds Pump3 will wait (60 is the default)"); -HomieSetting wateringIdleTime4("plant4MinPumpIdle", "time in seconds Pump4 will wait (60 is the default)"); -HomieSetting wateringIdleTime5("plant5MinPumpIdle", "time in seconds Pump5 will wait (60 is the default)"); -HomieSetting wateringIdleTime6("plant6MinPumpIdle", "time in seconds Pump6 will wait (60 is the default)"); +HomieSetting waterLevelMax("watermaxlevel", "distance at maximum water level"); +HomieSetting waterLevelMin("waterminlevel", "distance at minimum water level (pumps still covered)"); +HomieSetting waterLevelWarn("waterlevelwarn", "warn if below this water level %"); +HomieSetting waterLevelVol("waterVolume", "ml between minimum and maximum"); Ds18B20 dallas(SENSOR_DS18B20); Plant mPlants[MAX_PLANTS] = { - Plant(SENSOR_PLANT0, OUTPUT_PUMP0, &plant0, &plant0SensorTrigger, &wateringTime0, &wateringIdleTime0), - Plant(SENSOR_PLANT1, OUTPUT_PUMP1, &plant1, &plant1SensorTrigger, &wateringTime1, &wateringIdleTime1), - Plant(SENSOR_PLANT2, OUTPUT_PUMP2, &plant2, &plant2SensorTrigger, &wateringTime2, &wateringIdleTime2), - Plant(SENSOR_PLANT3, OUTPUT_PUMP3, &plant3, &plant3SensorTrigger, &wateringTime3, &wateringIdleTime3), - Plant(SENSOR_PLANT4, OUTPUT_PUMP4, &plant4, &plant4SensorTrigger, &wateringTime4, &wateringIdleTime4), - Plant(SENSOR_PLANT5, OUTPUT_PUMP5, &plant5, &plant5SensorTrigger, &wateringTime5, &wateringIdleTime5), - Plant(SENSOR_PLANT6, OUTPUT_PUMP6, &plant6, &plant6SensorTrigger, &wateringTime6, &wateringIdleTime6) + 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) }; void readAnalogValues() { @@ -134,8 +112,6 @@ void readAnalogValues() { */ void loopHandler() { - int waterLevelPercent = (100 * mWaterGone) / waterLevel.get(); - /* Move from Setup to this position, because the Settings are only here available */ if (!mLoopInited) { // Configure Deep Sleep: @@ -156,7 +132,7 @@ void loopHandler() { plant6.setProperty("switch").send(String("OFF")); #endif - for(int i=0; i < plantCnt.get() && i < MAX_PLANTS; i++) { + for(int i=0; i < MAX_PLANTS; i++) { mPlants[i].calculateSensorValue(AMOUNT_SENOR_QUERYS); mPlants[i].setProperty("moist").send(String(100 * mPlants[i].getSensorValue() / 4095 )); /* the last Plant, that was watered is stored in non volatile memory */ @@ -170,14 +146,14 @@ void loopHandler() { } } - sensorWater.setProperty("remaining").send(String(waterLevelPercent)); - Serial << "Water : " << mWaterGone << " cm (" << waterLevelPercent << "%)" << endl; + sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - mWaterGone )); + Serial << "Water : " << mWaterGone << " cm (" << String(waterLevelMax.get() - mWaterGone ) << "%)" << endl; /* Check if a plant needs water */ if (gCurrentPlant > 0) { int plntIdx = (gCurrentPlant-1); if (mPlants[plntIdx].isPumpRequired() && - (waterLevelPercent > waterMinPercent.get()) && + (mWaterGone > waterLevelMin.get()) && (digitalRead(mPlants[plntIdx].getPumpPin()) == LOW) ) { Serial << "Plant" << plntIdx << " needs water" << endl; mPlants[plntIdx].setProperty("switch").send(String("ON")); @@ -214,7 +190,7 @@ void loopHandler() { } /* Main Loop functionality */ - if (waterLevelPercent <= waterMinPercent.get()) { + if (mWaterGone <= waterLevelMin.get()) { /* let the ESP sleep qickly, as nothing must be done */ if ((millis() >= (MIN_TIME_RUNNING * MS_TO_S)) && (deepSleepTime.get() > 0)) { mDeepSleep = true; @@ -400,37 +376,6 @@ void setup() { // Load the settings deepSleepTime.setDefaultValue(0); deepSleepNightTime.setDefaultValue(0); - wateringTime0.setDefaultValue(60); - wateringTime1.setDefaultValue(60); - wateringTime2.setDefaultValue(60); - wateringTime3.setDefaultValue(60); - wateringTime4.setDefaultValue(60); - wateringTime5.setDefaultValue(60); - wateringTime6.setDefaultValue(60); - plantCnt.setDefaultValue(0).setValidator([] (long candidate) { - return ((candidate >= 0) && (candidate <= 7) ); - }); - plant0SensorTrigger.setDefaultValue(4000); - plant1SensorTrigger.setDefaultValue(4000); - plant2SensorTrigger.setDefaultValue(4000); - plant3SensorTrigger.setDefaultValue(4000); - plant4SensorTrigger.setDefaultValue(4000); - plant5SensorTrigger.setDefaultValue(4000); - plant6SensorTrigger.setDefaultValue(4000); - wateringDeepSleep.setDefaultValue(60); - - wateringIdleTime0.setDefaultValue(60); - wateringIdleTime1.setDefaultValue(60); - wateringIdleTime2.setDefaultValue(60); - wateringIdleTime3.setDefaultValue(60); - wateringIdleTime4.setDefaultValue(60); - wateringIdleTime5.setDefaultValue(60); - wateringIdleTime6.setDefaultValue(60); - - #ifdef HC_SR04 - waterLevel.setDefaultValue(50); - waterMinPercent.setDefaultValue(5); - #endif if (mConfigured) { // Advertise topics @@ -502,7 +447,7 @@ void setup() { Homie.setup(); /* Intialize inputs and outputs */ - for(int i=0; i < plantCnt.get(); i++) { + for(int i=0; i < MAX_PLANTS; i++) { pinMode(mPlants[i].getPumpPin(), OUTPUT); pinMode(mPlants[i].getSensorPin(), ANALOG); digitalWrite(mPlants[i].getPumpPin(), LOW); @@ -528,7 +473,10 @@ void setup() { esp_sleep_enable_timer_wakeup(usSleepTime); } - if (mConfigured && (ADC_5V_TO_3V3(lipoSenor) < MINIMUM_LIPO_VOLT) && (deepSleepTime.get()) ) { + if (mConfigured && + (ADC_5V_TO_3V3(lipoSenor) < MINIMUM_LIPO_VOLT) && + (ADC_5V_TO_3V3(lipoSenor) > NO_LIPO_VOLT) && + (deepSleepTime.get()) ) { long sleepEmptyLipo = (deepSleepTime.get() * EMPTY_LIPO_MULTIPL); Serial << "HOMIE | Change sleeping to " << sleepEmptyLipo << " ms as lipo is at " << ADC_5V_TO_3V3(lipoSenor) << "V" << endl; esp_sleep_enable_timer_wakeup(sleepEmptyLipo * 1000U); From 67d1aa55de32e6293e6ac07e0282338fa17f5087 Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 14 Oct 2020 20:19:27 +0200 Subject: [PATCH 12/12] all new inside comment and everything works --- esp32/src/PlantCtrl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index fdba9cd..e06a9f1 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -18,9 +18,10 @@ Plant::Plant(int pinSensor, int pinPump,int plantId) { char plantIdChar = plantId+'0'; + /* { char* name = "moistZdry"; - name[6]= plantIdChar; + name[5]= plantIdChar; mSensorDry = new HomieSetting(name, "Moist sensor dry threshold"); mSensorDry->setDefaultValue(4095); mSensorDry->setValidator([] (long candidate) { @@ -69,6 +70,7 @@ Plant::Plant(int pinSensor, int pinPump,int plantId) { return ((candidate >= 0) && (candidate <= 1024) ); }); } +*/ } void Plant::addSenseValue(int analog) {