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/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``` 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/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/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/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 diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index ac4e3bb..3925888 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)"); @@ -229,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; } } @@ -238,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)) { @@ -285,6 +286,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 << "HOMIE | Controller " << (mAlive ? " has coffee" : " is tired") << endl; + return true; +} + /** * @brief Handle Mqtt commands for the pumpe, responsible for the first plant * @@ -380,10 +401,10 @@ 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; + Serial << " | Update Limits.hpp : MAX_JSON_CONFIG_FILE_SIZE to 3000" << endl; } Homie_setFirmware("PlantControl", FIRMWARE_VERSION); @@ -479,6 +500,8 @@ void setup() { .setDatatype("number") .setUnit("V"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); + + stayAlive.advertise("alive").setName("Alive").setDatatype("number").settable(aliveHandler); } Homie.setup(); @@ -645,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) ); + } + } } }