Alive topic added

This commit is contained in:
Ollo 2020-10-13 20:16:28 +02:00
parent a16c98d7c6
commit 8aa9a2147e
2 changed files with 25 additions and 2 deletions

View File

@ -11,7 +11,7 @@
#ifndef CONTROLLER_CONFIG_H #ifndef CONTROLLER_CONFIG_H
#define 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(adc) ((adc) * 3.3 ) / 4095)
#define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc) * 3.3 * (multi)) / 4095) #define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc) * 3.3 * (multi)) / 4095)

View File

@ -25,6 +25,7 @@ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minut
bool mLoopInited = false; bool mLoopInited = false;
bool mDeepSleep = false; bool mDeepSleep = false;
bool mAlive=false; /**< Controller must not sleep */
int plantSensor1 = 0; int plantSensor1 = 0;
@ -67,6 +68,7 @@ HomieNode sensorLipo("lipo", "Battery Status", "Lipo");
HomieNode sensorSolar("solar", "Solar Status", "Solarpanel"); HomieNode sensorSolar("solar", "Solar Status", "Solarpanel");
HomieNode sensorWater("water", "WaterSensor", "Water"); HomieNode sensorWater("water", "WaterSensor", "Water");
HomieNode sensorTemp("temperature", "Temperature", "temperature"); HomieNode sensorTemp("temperature", "Temperature", "temperature");
HomieNode stayAlive("stay", "alive", "alive");
HomieSetting<long> deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)"); HomieSetting<long> deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)");
HomieSetting<long> deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)"); HomieSetting<long> 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 * @brief Handle Mqtt commands for the pumpe, responsible for the first plant
* *
@ -380,7 +402,6 @@ void setup() {
/* activate Wifi again */ /* activate Wifi again */
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) {
Serial << "HOMIE | Settings: " << HomieInternals::MAX_CONFIG_SETTING_SIZE << "/" << MAX_CONFIG_SETTING_ITEMS << endl; 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_CONFIG_SETTING_SIZE to " << MAX_CONFIG_SETTING_ITEMS << endl;
@ -479,6 +500,8 @@ void setup() {
.setDatatype("number") .setDatatype("number")
.setUnit("V"); .setUnit("V");
sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%");
stayAlive.advertise("stay").setName("Alive").setDatatype("number").settable(aliveHandler);
} }
Homie.setup(); Homie.setup();