Cleanup of last changes

This commit is contained in:
c3ma 2021-10-06 20:05:09 +02:00
parent 244dfb9b27
commit b5569aa8ab
3 changed files with 20 additions and 18 deletions

View File

@ -107,6 +107,9 @@
#define TEMPERATUR_TIMEOUT 3000 /**< 3 Seconds timeout for the temperatur sensors */ #define TEMPERATUR_TIMEOUT 3000 /**< 3 Seconds timeout for the temperatur sensors */
#define DS18B20_RESOLUTION 9 /**< 9bit temperature resolution -> 0.5°C steps */ #define DS18B20_RESOLUTION 9 /**< 9bit temperature resolution -> 0.5°C steps */
#define UTC_OFFSET_DE 3600 /* UTC offset in seconds for Germany */
#define UTF_OFFSET_DE_DST 3600 /* offset in seconds if daylight saving time is active */
/* @} */ /* @} */
#endif #endif

View File

@ -24,6 +24,6 @@
#define LOG_PUMP_INEFFECTIVE -4 #define LOG_PUMP_INEFFECTIVE -4
#define LOG_DEBUG_CODE 1001 #define LOG_DEBUG_CODE 1001
#define LOG_NOPUMP_LOWLIGHT 100 #define LOG_SLEEP_NIGHT 100
#define LOG_NOPUMPS 101 #define LOG_SLEEP_DAY 101
#define LOG_MISSING_PUMP -4 #define LOG_MISSING_PUMP -4

View File

@ -66,7 +66,6 @@ bool determineTimedLightState(bool lowLight);
* NON VOLATILE VARIABLES in DEEP SLEEP * NON VOLATILE VARIABLES in DEEP SLEEP
******************************************************************************/ ******************************************************************************/
RTC_DATA_ATTR long lastWaterValue = 0; /**< to calculate the used water per plant */
#if defined(TIMED_LIGHT_PIN) #if defined(TIMED_LIGHT_PIN)
RTC_DATA_ATTR bool timedLightOn = false; /**< allow fast recovery after poweron */ RTC_DATA_ATTR bool timedLightOn = false; /**< allow fast recovery after poweron */
RTC_DATA_ATTR bool timedLightLowVoltageTriggered = false; /**remember if it was shut down due to voltage level */ RTC_DATA_ATTR bool timedLightLowVoltageTriggered = false; /**remember if it was shut down due to voltage level */
@ -91,6 +90,12 @@ RunningMedian waterRawSensor = RunningMedian(5);
float mSolarVoltage = 0.0f; /**< Voltage from solar panels */ float mSolarVoltage = 0.0f; /**< Voltage from solar panels */
unsigned long setupFinishedTimestamp; unsigned long setupFinishedTimestamp;
bool pumpStarted = false;
long pumpTarget = -1;
#ifdef FLOWMETER
long pumpTargetMl = -1;
#endif
/*************************** Hardware abstraction *****************************/ /*************************** Hardware abstraction *****************************/
OneWire oneWire(SENSOR_ONEWIRE); OneWire oneWire(SENSOR_ONEWIRE);
@ -154,12 +159,12 @@ void espDeepSleep()
if (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE) if (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE)
{ {
log(LOG_LEVEL_INFO, String(String(mSolarVoltage) + "V! No pumps to activate and low light, deepSleepNight"), LOG_NOPUMP_LOWLIGHT); log(LOG_LEVEL_INFO, String(String(mSolarVoltage) + "V! Low light -> deepSleepNight"), LOG_SLEEP_NIGHT);
secondsToSleep = deepSleepTime.get(); secondsToSleep = deepSleepNightTime.get();
} }
else else
{ {
log(LOG_LEVEL_INFO, "No pumps to activate, deepSleep", LOG_NOPUMPS); log(LOG_LEVEL_INFO, "Sunny -> deepSleep", LOG_SLEEP_DAY);
secondsToSleep = deepSleepTime.get(); secondsToSleep = deepSleepTime.get();
} }
@ -374,7 +379,7 @@ void onHomieEvent(const HomieEvent &event)
} }
mSensorsRead = true; // MQTT is working, deactivate timeout logic mSensorsRead = true; // MQTT is working, deactivate timeout logic
configTime(3600, 3600, ntpServer.get()); configTime(UTC_OFFSET_DE, UTF_OFFSET_DE_DST, ntpServer.get());
{ {
getTopic(TEST_TOPIC, testopic) getTopic(TEST_TOPIC, testopic)
@ -586,14 +591,10 @@ bool switch7(const HomieRange &range, const String &value)
return mPlants[6].switchHandler(range, value); return mPlants[6].switchHandler(range, value);
} }
bool pumpStarted = false;
long pumpTarget = -1;
#ifdef FLOWMETER
long pumpTargetMl = -1;
#endif
void pumpActiveLoop() void pumpActiveLoop()
{ {
bool targetReached = false;
if (!pumpStarted) if (!pumpStarted)
{ {
@ -612,7 +613,6 @@ void pumpActiveLoop()
pumpStarted = true; pumpStarted = true;
} }
bool targetReached = false;
#ifdef FLOWMETER #ifdef FLOWMETER
long pumped = //readFlowMeterCounter * ratio; long pumped = //readFlowMeterCounter * ratio;
if(pumped >= pumpTargetMl)) if(pumped >= pumpTargetMl))
@ -620,12 +620,12 @@ void pumpActiveLoop()
targetReached = true; targetReached = true;
} }
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped)); mPlants[pumpToRun].setProperty("waterusage").send(String(pumped));
#endif #else
if (millis() > pumpTarget) if (millis() > pumpTarget)
{ {
targetReached = true; targetReached = true;
} }
#endif
if (targetReached) if (targetReached)
{ {
@ -922,8 +922,7 @@ void plantcontrol()
readOneWireSensors(); readOneWireSensors();
Serial << "W : " << waterRawSensor.getAverage() << " cm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << "%)" << endl; Serial << "W : " << waterRawSensor.getAverage() << " cm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << "%)" << endl;
lastWaterValue = waterRawSensor.getAverage();
float batteryVoltage = battery.getVoltage(BATTSENSOR_INDEX_BATTERY); float batteryVoltage = battery.getVoltage(BATTSENSOR_INDEX_BATTERY);
float chipTemp = battery.getTemperature(); float chipTemp = battery.getTemperature();
Serial << "Chip Temperatur " << chipTemp << " °C " << endl; Serial << "Chip Temperatur " << chipTemp << " °C " << endl;
@ -956,7 +955,7 @@ void plantcontrol()
} }
bool isLowLight = (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE); bool isLowLight = (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE);
bool hasWater = true; //FIXMEmWaterGone > waterLevelMin.get(); bool hasWater = true; //FIXME remaining > waterLevelMin.get();
//FIXME no water warning message //FIXME no water warning message
pumpToRun = determineNextPump(isLowLight); pumpToRun = determineNextPump(isLowLight);
//early aborts //early aborts