mode3 is controllable via MQTT
This commit is contained in:
parent
b9ca98904d
commit
8e6a2a44e7
@ -26,7 +26,6 @@ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minut
|
|||||||
|
|
||||||
/********************* non volatile enable after deepsleep *******************************/
|
/********************* non volatile enable after deepsleep *******************************/
|
||||||
|
|
||||||
RTC_DATA_ATTR bool coldBoot = true;
|
|
||||||
RTC_DATA_ATTR long rtcDeepSleepTime = 0; /**< Time, when the microcontroller shall be up again */
|
RTC_DATA_ATTR long rtcDeepSleepTime = 0; /**< Time, when the microcontroller shall be up again */
|
||||||
RTC_DATA_ATTR long rtcMoistureTrigger0 = 0; /**<Level for the moisture sensor */
|
RTC_DATA_ATTR long rtcMoistureTrigger0 = 0; /**<Level for the moisture sensor */
|
||||||
RTC_DATA_ATTR long rtcMoistureTrigger1 = 0; /**<Level for the moisture sensor */
|
RTC_DATA_ATTR long rtcMoistureTrigger1 = 0; /**<Level for the moisture sensor */
|
||||||
@ -38,12 +37,11 @@ RTC_DATA_ATTR long rtcMoistureTrigger6 = 0; /**<Level for the moisture sensor
|
|||||||
|
|
||||||
bool warmBoot = true;
|
bool warmBoot = true;
|
||||||
bool mode2Active = false;
|
bool mode2Active = false;
|
||||||
bool mode3Active = false;
|
bool mode3Active = false; /**< Controller must not sleep */
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -300,11 +298,12 @@ bool aliveHandler(const HomieRange& range, const String& value) {
|
|||||||
if (range.isRange) return false; // only one controller is present
|
if (range.isRange) return false; // only one controller is present
|
||||||
|
|
||||||
if (value.equals("ON") || value.equals("On") || value.equals("1")) {
|
if (value.equals("ON") || value.equals("On") || value.equals("1")) {
|
||||||
mAlive=true;
|
mode3Active=true;
|
||||||
} else {
|
} else {
|
||||||
mAlive=false;
|
mode3Active=false;
|
||||||
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
Serial << "HOMIE | Controller " << (mAlive ? " has coffee" : " is tired") << endl;
|
Serial << "HOMIE | Controller " << (mode3Active ? " has coffee" : " is tired") << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +350,6 @@ void systemInit(){
|
|||||||
Homie_setFirmware("PlantControl", FIRMWARE_VERSION);
|
Homie_setFirmware("PlantControl", FIRMWARE_VERSION);
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
|
||||||
mConfigured = Homie.isConfigured();
|
|
||||||
|
|
||||||
// Set default values
|
// Set default values
|
||||||
deepSleepTime.setDefaultValue(300000); /* 5 minutes in milliseconds */
|
deepSleepTime.setDefaultValue(300000); /* 5 minutes in milliseconds */
|
||||||
@ -363,6 +361,7 @@ void systemInit(){
|
|||||||
waterLevelWarn.setDefaultValue(500); /* 50cm in mm */
|
waterLevelWarn.setDefaultValue(500); /* 50cm in mm */
|
||||||
waterLevelVol.setDefaultValue(5000); /* 5l in ml */
|
waterLevelVol.setDefaultValue(5000); /* 5l in ml */
|
||||||
|
|
||||||
|
mConfigured = Homie.isConfigured();
|
||||||
if (mConfigured) {
|
if (mConfigured) {
|
||||||
// Advertise topics
|
// Advertise topics
|
||||||
plant1.advertise("switch").setName("Pump 1")
|
plant1.advertise("switch").setName("Pump 1")
|
||||||
@ -490,23 +489,16 @@ void mode2(){
|
|||||||
Serial.println("Init mode 2");
|
Serial.println("Init mode 2");
|
||||||
mode2Active = true;
|
mode2Active = true;
|
||||||
|
|
||||||
|
|
||||||
systemInit();
|
systemInit();
|
||||||
|
|
||||||
/* Jump into Mode 3, if not configured */
|
/* Jump into Mode 3, if not configured */
|
||||||
if (!mConfigured) {
|
if (!mConfigured) {
|
||||||
|
Serial.println("upgrade to mode 3");
|
||||||
mode2Active = false;
|
mode2Active = false;
|
||||||
mode3Active = true;
|
mode3Active = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mode3(){
|
|
||||||
Serial.println("Init mode 3");
|
|
||||||
mode3Active = true;
|
|
||||||
|
|
||||||
systemInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Startup function
|
* @brief Startup function
|
||||||
* Is called once, the controller is started
|
* Is called once, the controller is started
|
||||||
@ -530,11 +522,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
/* read button */
|
/* read button */
|
||||||
pinMode(BUTTON, INPUT);
|
pinMode(BUTTON, INPUT);
|
||||||
if(!coldBoot){
|
|
||||||
digitalWrite(OUTPUT_SENSOR, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Disable Wifi and bluetooth */
|
/* Disable Wifi and bluetooth */
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
@ -581,33 +568,9 @@ void setup() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(coldBoot){
|
|
||||||
coldBoot = false;
|
|
||||||
delay(1000);
|
|
||||||
if (digitalRead(BUTTON) == LOW){
|
|
||||||
for(int i = 0;i<10;i++){
|
|
||||||
digitalWrite(OUTPUT_SENSOR, LOW);
|
|
||||||
delay(50);
|
|
||||||
digitalWrite(OUTPUT_SENSOR, HIGH);
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
mode3();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
digitalWrite(OUTPUT_SENSOR, LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Perform the active modes (non mode1) */
|
/* Perform the active modes (non mode1) */
|
||||||
if (mode3Active || mode2Active) {
|
if (mode3Active || mode2Active) {
|
||||||
Homie.loop();
|
Homie.loop();
|
||||||
if(!mode3Active){
|
|
||||||
/* Upgrade to mode 3 via reset */
|
|
||||||
if (digitalRead(BUTTON) == LOW){
|
|
||||||
coldBoot=true;
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Check which mode shall be selected */
|
/* Check which mode shall be selected */
|
||||||
if(warmBoot){
|
if(warmBoot){
|
||||||
@ -615,11 +578,6 @@ void loop() {
|
|||||||
if(mode1()){
|
if(mode1()){
|
||||||
mode2();
|
mode2();
|
||||||
} else {
|
} else {
|
||||||
/* Upgrade to mode 3 via reset */
|
|
||||||
if (digitalRead(BUTTON) == LOW){
|
|
||||||
coldBoot=true;
|
|
||||||
ESP.restart();
|
|
||||||
}
|
|
||||||
Serial.println("Nothing to do back to sleep");
|
Serial.println("Nothing to do back to sleep");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
|
Loading…
Reference in New Issue
Block a user