From 8aa9a2147efc13fe1fec731765a7e9a9b33e8b24 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 13 Oct 2020 20:16:28 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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) ); + } + } } }