Controller is starting again
This commit is contained in:
parent
4f7cc70bbd
commit
ff33c58288
@ -11,7 +11,8 @@
|
|||||||
"algorithm": "cpp",
|
"algorithm": "cpp",
|
||||||
"istream": "cpp",
|
"istream": "cpp",
|
||||||
"limits": "cpp",
|
"limits": "cpp",
|
||||||
"streambuf": "cpp"
|
"streambuf": "cpp",
|
||||||
|
"functional": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,6 @@
|
|||||||
#define SENSOR_SR04_ECHO 17 /**< GPIO 17 - Echo */
|
#define SENSOR_SR04_ECHO 17 /**< GPIO 17 - Echo */
|
||||||
#define SENSOR_SR04_TRIG 23 /**< GPIO 23 - Trigger */
|
#define SENSOR_SR04_TRIG 23 /**< GPIO 23 - Trigger */
|
||||||
|
|
||||||
|
#define MAX_CONFIG_SETTING_ITEMS 30 /**< Parameter, that can be configured in Homie */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,6 +40,7 @@ int mWaterAtEmptyLevel = 0;
|
|||||||
int mWaterGone = -1; /**< Amount of centimeter, where no water is seen */
|
int mWaterGone = -1; /**< Amount of centimeter, where no water is seen */
|
||||||
int readCounter = 0;
|
int readCounter = 0;
|
||||||
int mButtonClicks = 0;
|
int mButtonClicks = 0;
|
||||||
|
bool mConfigured = false;
|
||||||
|
|
||||||
RTC_DATA_ATTR int gBootCount = 0;
|
RTC_DATA_ATTR int gBootCount = 0;
|
||||||
|
|
||||||
@ -427,97 +428,105 @@ void setup() {
|
|||||||
WiFi.mode(WIFI_STA);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
Homie_setFirmware("PlantControl", FIRMWARE_VERSION);
|
Homie_setFirmware("PlantControl", FIRMWARE_VERSION);
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
|
||||||
// Load the settings
|
mConfigured = Homie.isConfigured();
|
||||||
deepSleepTime.setDefaultValue(0);
|
if (mConfigured) {
|
||||||
deepSleepNightTime.setDefaultValue(0);
|
// Load the settings
|
||||||
wateringTime0.setDefaultValue(60);
|
deepSleepTime.setDefaultValue(0);
|
||||||
wateringTime1.setDefaultValue(60);
|
deepSleepNightTime.setDefaultValue(0);
|
||||||
wateringTime2.setDefaultValue(60);
|
wateringTime0.setDefaultValue(60);
|
||||||
wateringTime3.setDefaultValue(60);
|
wateringTime1.setDefaultValue(60);
|
||||||
wateringTime4.setDefaultValue(60);
|
wateringTime2.setDefaultValue(60);
|
||||||
wateringTime5.setDefaultValue(60);
|
wateringTime3.setDefaultValue(60);
|
||||||
wateringTime6.setDefaultValue(60);
|
wateringTime4.setDefaultValue(60);
|
||||||
plantCnt.setDefaultValue(0).setValidator([] (long candidate) {
|
wateringTime5.setDefaultValue(60);
|
||||||
return ((candidate >= 0) && (candidate <= 6) );
|
wateringTime6.setDefaultValue(60);
|
||||||
});
|
plantCnt.setDefaultValue(0).setValidator([] (long candidate) {
|
||||||
plant1SensorTrigger.setDefaultValue(0);
|
return ((candidate >= 0) && (candidate <= 6) );
|
||||||
plant2SensorTrigger.setDefaultValue(0);
|
});
|
||||||
plant3SensorTrigger.setDefaultValue(0);
|
plant1SensorTrigger.setDefaultValue(0);
|
||||||
#if (MAX_PLANTS >= 4)
|
plant2SensorTrigger.setDefaultValue(0);
|
||||||
plant4SensorTrigger.setDefaultValue(0);
|
plant3SensorTrigger.setDefaultValue(0);
|
||||||
plant5SensorTrigger.setDefaultValue(0);
|
#if (MAX_PLANTS >= 4)
|
||||||
plant6SensorTrigger.setDefaultValue(0);
|
plant4SensorTrigger.setDefaultValue(0);
|
||||||
#endif
|
plant5SensorTrigger.setDefaultValue(0);
|
||||||
|
plant6SensorTrigger.setDefaultValue(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HC_SR04
|
#ifdef HC_SR04
|
||||||
waterLevel.setDefaultValue(50);
|
waterLevel.setDefaultValue(50);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Advertise topics
|
// Advertise topics
|
||||||
plant1.advertise("switch").setName("Pump 1")
|
plant1.advertise("switch").setName("Pump 1")
|
||||||
.setDatatype("boolean")
|
.setDatatype("boolean")
|
||||||
.settable(switch1Handler);
|
.settable(switch1Handler);
|
||||||
plant1.advertise("moist").setName("Percent")
|
plant1.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
plant2.advertise("switch").setName("Pump 2")
|
plant2.advertise("switch").setName("Pump 2")
|
||||||
.setDatatype("boolean")
|
.setDatatype("boolean")
|
||||||
.settable(switch2Handler);
|
.settable(switch2Handler);
|
||||||
plant2.advertise("moist").setName("Percent")
|
plant2.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
plant3.advertise("switch").setName("Pump 3")
|
plant3.advertise("switch").setName("Pump 3")
|
||||||
.setDatatype("boolean")
|
.setDatatype("boolean")
|
||||||
.settable(switch3Handler);
|
.settable(switch3Handler);
|
||||||
plant3.advertise("moist").setName("Percent")
|
plant3.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
#if (MAX_PLANTS >= 4)
|
#if (MAX_PLANTS >= 4)
|
||||||
plant4.advertise("moist").setName("Percent")
|
plant4.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
plant5.advertise("moist").setName("Percent")
|
plant5.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
plant6.advertise("moist").setName("Percent")
|
plant6.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
plant0.advertise("moist").setName("Percent")
|
plant0.advertise("moist").setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
sensorTemp.advertise("control")
|
sensorTemp.advertise("control")
|
||||||
.setName("Temperature")
|
.setName("Temperature")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("°C");
|
.setUnit("°C");
|
||||||
sensorTemp.advertise("temp")
|
sensorTemp.advertise("temp")
|
||||||
.setName("Temperature")
|
.setName("Temperature")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("°C");
|
.setUnit("°C");
|
||||||
|
|
||||||
sensorLipo.advertise("percent")
|
sensorLipo.advertise("percent")
|
||||||
.setName("Percent")
|
.setName("Percent")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("%");
|
.setUnit("%");
|
||||||
sensorLipo.advertise("volt")
|
sensorLipo.advertise("volt")
|
||||||
.setName("Volt")
|
.setName("Volt")
|
||||||
.setDatatype("number")
|
.setDatatype("number")
|
||||||
.setUnit("V");
|
.setUnit("V");
|
||||||
|
|
||||||
sensorSolar.advertise("percent")
|
|
||||||
.setName("Percent")
|
|
||||||
.setDatatype("number")
|
|
||||||
.setUnit("%");
|
|
||||||
sensorSolar.advertise("volt")
|
|
||||||
.setName("Volt")
|
|
||||||
.setDatatype("number")
|
|
||||||
.setUnit("V");
|
|
||||||
sensorWater.advertise("remaining").setDatatype("number").setUnit("%");
|
|
||||||
|
|
||||||
|
sensorSolar.advertise("percent")
|
||||||
|
.setName("Percent")
|
||||||
|
.setDatatype("number")
|
||||||
|
.setUnit("%");
|
||||||
|
sensorSolar.advertise("volt")
|
||||||
|
.setName("Volt")
|
||||||
|
.setDatatype("number")
|
||||||
|
.setUnit("V");
|
||||||
|
sensorWater.advertise("remaining").setDatatype("number").setUnit("%");
|
||||||
|
}
|
||||||
|
|
||||||
Homie.setup();
|
Homie.setup();
|
||||||
|
|
||||||
/* Intialize inputs and outputs */
|
/* Intialize inputs and outputs */
|
||||||
@ -536,18 +545,18 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
// Configure Deep Sleep:
|
// Configure Deep Sleep:
|
||||||
if ((deepSleepNightTime.get() > 0) &&
|
if (mConfigured && (deepSleepNightTime.get() > 0) &&
|
||||||
( SOLAR_VOLT(solarSensor) < MINIMUM_SOLAR_VOLT)) {
|
( SOLAR_VOLT(solarSensor) < MINIMUM_SOLAR_VOLT)) {
|
||||||
Serial << "HOMIE | Setup sleeping for " << deepSleepNightTime.get() << " ms as sun is at " << SOLAR_VOLT(solarSensor) << "V" << endl;
|
Serial << "HOMIE | Setup sleeping for " << deepSleepNightTime.get() << " ms as sun is at " << SOLAR_VOLT(solarSensor) << "V" << endl;
|
||||||
uint64_t usSleepTime = deepSleepNightTime.get() * 1000U;
|
uint64_t usSleepTime = deepSleepNightTime.get() * 1000U;
|
||||||
esp_sleep_enable_timer_wakeup(usSleepTime);
|
esp_sleep_enable_timer_wakeup(usSleepTime);
|
||||||
}else if (deepSleepTime.get()) {
|
}else if (mConfigured && deepSleepTime.get()) {
|
||||||
Serial << "HOMIE | Setup sleeping for " << deepSleepTime.get() << " ms" << endl;
|
Serial << "HOMIE | Setup sleeping for " << deepSleepTime.get() << " ms" << endl;
|
||||||
uint64_t usSleepTime = deepSleepTime.get() * 1000U;
|
uint64_t usSleepTime = deepSleepTime.get() * 1000U;
|
||||||
esp_sleep_enable_timer_wakeup(usSleepTime);
|
esp_sleep_enable_timer_wakeup(usSleepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (ADC_5V_TO_3V3(lipoSenor) < MINIMUM_LIPO_VOLT) && (deepSleepTime.get()) ) {
|
if (mConfigured && (ADC_5V_TO_3V3(lipoSenor) < MINIMUM_LIPO_VOLT) && (deepSleepTime.get()) ) {
|
||||||
long sleepEmptyLipo = (deepSleepTime.get() * EMPTY_LIPO_MULTIPL);
|
long sleepEmptyLipo = (deepSleepTime.get() * EMPTY_LIPO_MULTIPL);
|
||||||
Serial << "HOMIE | Change sleeping to " << sleepEmptyLipo << " ms as lipo is at " << ADC_5V_TO_3V3(lipoSenor) << "V" << endl;
|
Serial << "HOMIE | Change sleeping to " << sleepEmptyLipo << " ms as lipo is at " << ADC_5V_TO_3V3(lipoSenor) << "V" << endl;
|
||||||
esp_sleep_enable_timer_wakeup(sleepEmptyLipo * 1000U);
|
esp_sleep_enable_timer_wakeup(sleepEmptyLipo * 1000U);
|
||||||
@ -559,7 +568,7 @@ void setup() {
|
|||||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
|
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
|
||||||
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL,ESP_PD_OPTION_ON);
|
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL,ESP_PD_OPTION_ON);
|
||||||
|
|
||||||
|
Serial << "DS18B20 | Initialization " << endl;
|
||||||
/* Read the temperature sensors once, as first time 85 degree is returned */
|
/* Read the temperature sensors once, as first time 85 degree is returned */
|
||||||
Serial << "DS18B20 | sensors: " << String(dallas.readDevices()) << endl;
|
Serial << "DS18B20 | sensors: " << String(dallas.readDevices()) << endl;
|
||||||
delay(200);
|
delay(200);
|
||||||
@ -579,7 +588,7 @@ void setup() {
|
|||||||
* Executs the Homie base functionallity or triggers sleeping, if requested.
|
* Executs the Homie base functionallity or triggers sleeping, if requested.
|
||||||
*/
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!mDeepSleep) {
|
if (!mDeepSleep || !mConfigured) {
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
// read the incoming byte:
|
// read the incoming byte:
|
||||||
int incomingByte = Serial.read();
|
int incomingByte = Serial.read();
|
||||||
|
Loading…
Reference in New Issue
Block a user