This commit is contained in:
Ollo 2020-10-20 22:54:41 +02:00
commit 0106641044
8 changed files with 40 additions and 42 deletions

Binary file not shown.

View File

@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x150000,
app1, app, ota_1, 0x160000,0x150000,
spiffs, data, spiffs, 0x300000,0x17000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x150000
5 app1 app ota_1 0x160000 0x150000
6 spiffs data spiffs 0x300000 0x17000

View File

@ -51,12 +51,11 @@ HomieSetting<long> waterLevelVol("waterVolume", "(ml) between minimum and maximu
#define GENERATE_PLANT(plant, strplant) \ #define GENERATE_PLANT(plant, strplant) \
HomieSetting<long> mSensorDry##plant = HomieSetting<long>("moistdry" strplant, "Plant " strplant "- Moist sensor dry threshold"); \ HomieSetting<long> mSensorDry##plant = HomieSetting<long>("moistdry" strplant, "Plant " strplant "- Moist sensor dry threshold"); \
HomieSetting<long> mSensorWet##plant = HomieSetting<long>("moistwet" strplant, "Plant" strplant " - Moist sensor wet threshold"); \
HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("rangehourstart" strplant, "Plant" strplant " - Range pump allowed hour start (0-23)"); \ HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("rangehourstart" strplant, "Plant" strplant " - Range pump allowed hour start (0-23)"); \
HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("rangehourend" strplant, "Plant" strplant " - Range pump allowed hour end (0-23)"); \ HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("rangehourend" strplant, "Plant" strplant " - Range pump allowed hour end (0-23)"); \
HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ" strplant, "Plant" strplant " - Enable the Pump only, when there is light but not enought to charge battery"); \ HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ" strplant, "Plant" strplant " - Enable the Pump only, when there is light but not enought to charge battery"); \
HomieSetting<long> mPumpCooldownInHours##plant = HomieSetting<long>("cooldownpump" strplant, "Plant" strplant " - How long to wait until the pump is activated again (minutes)"); \ HomieSetting<long> mPumpCooldownInHours##plant = HomieSetting<long>("cooldownpump" strplant, "Plant" strplant " - How long to wait until the pump is activated again (minutes)"); \
PlantSettings_t mSetting##plant = { &mSensorDry##plant, &mSensorWet##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInHours##plant }; PlantSettings_t mSetting##plant = { &mSensorDry##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInHours##plant };
GENERATE_PLANT(0, "0"); GENERATE_PLANT(0, "0");
GENERATE_PLANT(1, "1"); GENERATE_PLANT(1, "1");

View File

@ -17,7 +17,6 @@
typedef struct PlantSettings_t { typedef struct PlantSettings_t {
HomieSetting<long>* pSensorDry; HomieSetting<long>* pSensorDry;
HomieSetting<long>* pSensorWet;
HomieSetting<long>* pPumpAllowedHourRangeStart; HomieSetting<long>* pPumpAllowedHourRangeStart;
HomieSetting<long>* pPumpAllowedHourRangeEnd; HomieSetting<long>* pPumpAllowedHourRangeEnd;
HomieSetting<bool>* pPumpOnlyWhenLowLight; HomieSetting<bool>* pPumpOnlyWhenLowLight;

View File

@ -76,7 +76,7 @@ public:
* @return false * @return false
*/ */
bool isPumpRequired() { bool isPumpRequired() {
return (this->mSetting->pSensorWet != NULL) && (this->mValue < this->mSetting->pSensorWet->get()); return (this->mSetting->pSensorDry != NULL) && (this->mValue < this->mSetting->pSensorDry->get());
} }
HomieInternals::SendingPromise& setProperty(const String& property) const { HomieInternals::SendingPromise& setProperty(const String& property) const {

View File

@ -13,6 +13,7 @@ platform = espressif32
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
framework = arduino framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
board_build.partitions = defaultWithSmallerSpiffs.csv
; the latest development brankitchen-lightch (convention V3.0.x) ; the latest development brankitchen-lightch (convention V3.0.x)
lib_deps = ArduinoJson@6.16.1 lib_deps = ArduinoJson@6.16.1

View File

@ -24,10 +24,6 @@ void Plant::init(void) {
this->mSetting->pSensorDry->setValidator([] (long candidate) { this->mSetting->pSensorDry->setValidator([] (long candidate) {
return (((candidate >= 0) && (candidate <= 4095) ) || candidate == DEACTIVATED_PLANT); return (((candidate >= 0) && (candidate <= 4095) ) || candidate == DEACTIVATED_PLANT);
}); });
this->mSetting->pSensorWet->setDefaultValue(0);
this->mSetting->pSensorWet->setValidator([] (long candidate) {
return ((candidate >= 0) && (candidate <= 4095) );
});
this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8); // start at 8:00 this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8); // start at 8:00
this->mSetting->pPumpAllowedHourRangeStart->setValidator([] (long candidate) { this->mSetting->pPumpAllowedHourRangeStart->setValidator([] (long candidate) {
return ((candidate >= 0) && (candidate <= 23) ); return ((candidate >= 0) && (candidate <= 23) );

View File

@ -116,7 +116,7 @@ bool prepareSleep(void *) {
void mode2MQTT(){ void mode2MQTT(){
if (deepSleepTime.get()) { if (deepSleepTime.get()) {
Serial << "HOMIE | Setup sleeping for " << deepSleepTime.get() << " ms" << endl; Serial << "sleeping for " << deepSleepTime.get() << endl;
} }
/* Publish default values */ /* Publish default values */
@ -125,13 +125,13 @@ void mode2MQTT(){
//TODO attribute used water in ml to plantid //TODO attribute used water in ml to plantid
} }
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - mWaterGone )); sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - mWaterGone ));
Serial << "Water : " << mWaterGone << " cm (" << String(waterLevelMax.get() - mWaterGone ) << "%)" << endl; Serial << "W : " << mWaterGone << " cm (" << String(waterLevelMax.get() - mWaterGone ) << "%)" << endl;
lastWaterValue = mWaterGone; lastWaterValue = mWaterGone;
if (mWaterGone <= waterLevelMin.get()) { if (mWaterGone <= waterLevelMin.get()) {
/* let the ESP sleep qickly, as nothing must be done */ /* let the ESP sleep qickly, as nothing must be done */
if ((millis() >= (MIN_TIME_RUNNING * MS_TO_S)) && (deepSleepTime.get() > 0)) { if ((millis() >= (MIN_TIME_RUNNING * MS_TO_S)) && (deepSleepTime.get() > 0)) {
Serial << "No Water for pumps" << endl; Serial << "No W" << endl;
/* in 500 microseconds */ /* in 500 microseconds */
wait4sleep.in(500, prepareSleep); wait4sleep.in(500, prepareSleep);
return; return;
@ -255,7 +255,7 @@ long getLastActivationForPump(int plantId){
* These sensors (ADC2) can only be read when no Wifi is used. * These sensors (ADC2) can only be read when no Wifi is used.
*/ */
void readSensors() { void readSensors() {
Serial << "Read sensors..." << endl; Serial << "rs" << endl;
/* activate all sensors */ /* activate all sensors */
pinMode(OUTPUT_SENSOR, OUTPUT); pinMode(OUTPUT_SENSOR, OUTPUT);
@ -269,9 +269,9 @@ void readSensors() {
} }
} }
Serial << "DS18B20 | Initialization " << endl; Serial << "DS18B20" << 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" << String(dallas.readDevices()) << endl;
delay(200); delay(200);
@ -280,13 +280,13 @@ void readSensors() {
float* pFloat = temp; float* pFloat = temp;
// first read returns crap, ignore result and read twice // first read returns crap, ignore result and read twice
if (dallas.readAllTemperatures(pFloat, 2) > 0) { if (dallas.readAllTemperatures(pFloat, 2) > 0) {
Serial << "DS18B20 | Temperature 1: " << String(temp[0]) << endl; Serial << "t1: " << String(temp[0]) << endl;
Serial << "DS18B20 | Temperature 2: " << String(temp[1]) << endl; Serial << "t2: " << String(temp[1]) << endl;
} }
delay(200); delay(200);
if (dallas.readAllTemperatures(pFloat, 2) > 0) { if (dallas.readAllTemperatures(pFloat, 2) > 0) {
Serial << "Temperature 1: " << String(temp[0]) << endl; Serial << "t1: " << String(temp[0]) << endl;
Serial << "Temperature 2: " << String(temp[1]) << endl; Serial << "t2: " << String(temp[1]) << endl;
} }
temp1.add(temp[0]); temp1.add(temp[0]);
@ -327,10 +327,10 @@ void onHomieEvent(const HomieEvent& event) {
if(!mode3Active){ if(!mode3Active){
mode2MQTT(); mode2MQTT();
} }
Homie.getLogger() << "MQTT connected, preparing for deep sleep after 100ms..." << endl; Homie.getLogger() << "MQTT 1" << endl;
break; break;
case HomieEventType::READY_TO_SLEEP: case HomieEventType::READY_TO_SLEEP:
Homie.getLogger() << "Ready to sleep" << endl; Homie.getLogger() << "rtsleep" << endl;
esp_deep_sleep_start(); esp_deep_sleep_start();
break; break;
} }
@ -415,14 +415,13 @@ bool switchGeneralPumpHandler(const int pump, const HomieRange& range, const Str
*/ */
bool aliveHandler(const HomieRange& range, const String& value) { 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")) {
mode3Active=true; mode3Active=true;
} else { } else {
mode3Active=false; mode3Active=false;
esp_deep_sleep_start(); esp_deep_sleep_start();
} }
Serial << "HOMIE | Controller " << (mode3Active ? " has coffee" : " is tired") << endl; Serial << (mode3Active ? "stayalive" : "") << endl;
return true; return true;
} }
@ -551,7 +550,7 @@ void systemInit(){
bool mode1(){ bool mode1(){
Serial.println("Init mode 1"); Serial.println("m1");
readSensors(); readSensors();
//queue sensor values for //queue sensor values for
@ -565,36 +564,36 @@ bool mode1(){
(rtcMoistureTrigger6 == 0) (rtcMoistureTrigger6 == 0)
) )
{ {
Serial.println("Missing RTC information"); Serial.println("RTCm2");
return true; return true;
} }
if ((rtcMoistureTrigger0 != DEACTIVATED_PLANT) && (mPlants[0].getSensorValue() < rtcMoistureTrigger0) ) { if ((rtcMoistureTrigger0 != DEACTIVATED_PLANT) && (mPlants[0].getSensorValue() < rtcMoistureTrigger0) ) {
Serial.println("Moisture of plant 0"); Serial.println("mt0");
return true; return true;
} }
if ((rtcMoistureTrigger1 != DEACTIVATED_PLANT) && (mPlants[1].getSensorValue() < rtcMoistureTrigger1) ) { if ((rtcMoistureTrigger1 != DEACTIVATED_PLANT) && (mPlants[1].getSensorValue() < rtcMoistureTrigger1) ) {
Serial.println("Moisture of plant 1"); Serial.println("mt1");
return true; return true;
} }
if ((rtcMoistureTrigger2 != DEACTIVATED_PLANT) && (mPlants[2].getSensorValue() < rtcMoistureTrigger2) ) { if ((rtcMoistureTrigger2 != DEACTIVATED_PLANT) && (mPlants[2].getSensorValue() < rtcMoistureTrigger2) ) {
Serial.println("Moisture of plant 2"); Serial.println("mt2");
return true; return true;
} }
if ((rtcMoistureTrigger3 != DEACTIVATED_PLANT) && (mPlants[3].getSensorValue() < rtcMoistureTrigger3) ) { if ((rtcMoistureTrigger3 != DEACTIVATED_PLANT) && (mPlants[3].getSensorValue() < rtcMoistureTrigger3) ) {
Serial.println("Moisture of plant 3"); Serial.println("mt3");
return true; return true;
} }
if ((rtcMoistureTrigger4 != DEACTIVATED_PLANT) && (mPlants[4].getSensorValue() < rtcMoistureTrigger4) ) { if ((rtcMoistureTrigger4 != DEACTIVATED_PLANT) && (mPlants[4].getSensorValue() < rtcMoistureTrigger4) ) {
Serial.println("Moisture of plant 4"); Serial.println("mt4");
return true; return true;
} }
if ((rtcMoistureTrigger5 != DEACTIVATED_PLANT) && (mPlants[5].getSensorValue() < rtcMoistureTrigger5) ) { if ((rtcMoistureTrigger5 != DEACTIVATED_PLANT) && (mPlants[5].getSensorValue() < rtcMoistureTrigger5) ) {
Serial.println("Moisture of plant 5"); Serial.println("mt5");
return true; return true;
} }
if ((rtcMoistureTrigger6 != DEACTIVATED_PLANT) && (mPlants[6].getSensorValue() < rtcMoistureTrigger6) ) { if ((rtcMoistureTrigger6 != DEACTIVATED_PLANT) && (mPlants[6].getSensorValue() < rtcMoistureTrigger6) ) {
Serial.println("Moisture of plant 6"); Serial.println("mt6");
return true; return true;
} }
//check how long it was already in mode1 if to long goto mode2 //check how long it was already in mode1 if to long goto mode2
@ -604,13 +603,12 @@ bool mode1(){
} }
void mode2(){ void mode2(){
Serial.println("Init mode 2"); Serial.println("m2");
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"); Serial.println("m3");
mode3Active = true; mode3Active = true;
} }
} }
@ -643,9 +641,8 @@ void setup() {
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
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; //increase the config settings to 50 and the json to 3000
Serial << " | Update Limits.hpp : MAX_CONFIG_SETTING_SIZE to " << MAX_CONFIG_SETTING_ITEMS << endl; Serial << "Limits.hpp" << endl;
Serial << " | Update Limits.hpp : MAX_JSON_CONFIG_FILE_SIZE to 5000" << endl;
} }
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
@ -658,11 +655,11 @@ void setup() {
// Configure Deep Sleep: // Configure Deep Sleep:
if (mConfigured && (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 << deepSleepNightTime.get() << "ms ds " << 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 (mConfigured && deepSleepTime.get()) { }else if (mConfigured && deepSleepTime.get()) {
Serial << "HOMIE | Setup sleeping for " << deepSleepTime.get() << " ms" << endl; Serial << deepSleepTime.get() << " ms ds" << 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);
} }
@ -672,7 +669,7 @@ void setup() {
(ADC_5V_TO_3V3(lipoSenor) > NO_LIPO_VOLT) && (ADC_5V_TO_3V3(lipoSenor) > NO_LIPO_VOLT) &&
(deepSleepTime.get()) ) { (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 << sleepEmptyLipo << " ms lipo " << ADC_5V_TO_3V3(lipoSenor) << "V" << endl;
esp_sleep_enable_timer_wakeup(sleepEmptyLipo * 1000U); esp_sleep_enable_timer_wakeup(sleepEmptyLipo * 1000U);
mDeepSleep = true; mDeepSleep = true;
} }
@ -680,7 +677,7 @@ void setup() {
if(mode1()){ if(mode1()){
mode2(); mode2();
} else { } else {
Serial.println("Nothing to do back to sleep"); Serial.println("nop");
Serial.flush(); Serial.flush();
esp_deep_sleep_start(); esp_deep_sleep_start();
} }
@ -695,7 +692,7 @@ void loop() {
Homie.loop(); Homie.loop();
if(millis() > 30000 && !mode3Active){ if(millis() > 30000 && !mode3Active){
Serial << (millis()/ 1000) << "s running; going to suicide ..." << endl; Serial << (millis()/ 1000) << " ds watchdog" << endl;
Serial.flush(); Serial.flush();
esp_deep_sleep_start(); esp_deep_sleep_start();
} }