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