Sleep 3 times longer, if the battery voltage is low
This commit is contained in:
parent
a84344f978
commit
9f2e21d94c
@ -102,10 +102,12 @@
|
|||||||
#define ESP_STALE_TIMEOUT (MQTT_TIMEOUT+(700*1000))
|
#define ESP_STALE_TIMEOUT (MQTT_TIMEOUT+(700*1000))
|
||||||
|
|
||||||
#define MAX_PLANTS 7
|
#define MAX_PLANTS 7
|
||||||
#define SOLAR_CHARGE_MIN_VOLTAGE 7 /**< Sun is rising (morning detected) */
|
#define SOLAR_CHARGE_MIN_VOLTAGE 7 /**< Sun is rising (morning detected) */
|
||||||
#define SOLAR_CHARGE_MAX_VOLTAGE 9 /**< Sun is shining (noon) */
|
#define SOLAR_CHARGE_MAX_VOLTAGE 9 /**< Sun is shining (noon) */
|
||||||
#define SOLAR_MAX_VOLTAGE_POSSIBLE 100 /**< higher values are treated as not connected sensor */
|
#define SOLAR_MAX_VOLTAGE_POSSIBLE 100 /**< higher values are treated as not connected sensor */
|
||||||
#define VOLT_MAX_BATT 4.2f
|
#define VOLT_MAX_BATT 4.2f
|
||||||
|
#define VOLT_MIN_BATT 3.0f /**< Minimum battery voltage for normal operation */
|
||||||
|
#define LOWVOLT_SLEEP_FACTOR 3 /**< Factor for nightsleep delay, if the battery drops below minimum (@see VOLT_MIN_BATT) */
|
||||||
|
|
||||||
#define MAX_CONFIG_SETTING_ITEMS 100 /**< Parameter, that can be configured in Homie */
|
#define MAX_CONFIG_SETTING_ITEMS 100 /**< Parameter, that can be configured in Homie */
|
||||||
#define MAX_JSON_CONFIG_FILE_SIZE_CUSTOM 2500
|
#define MAX_JSON_CONFIG_FILE_SIZE_CUSTOM 2500
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#define LOG_DEBUG_CODE 1001
|
#define LOG_DEBUG_CODE 1001
|
||||||
#define LOG_SLEEP_NIGHT 100
|
#define LOG_SLEEP_NIGHT 100
|
||||||
#define LOG_SLEEP_DAY 101
|
#define LOG_SLEEP_DAY 101
|
||||||
|
#define LOG_SLEEP_LOWVOLTAGE 502
|
||||||
#define LOG_SLEEP_CYCLE 102
|
#define LOG_SLEEP_CYCLE 102
|
||||||
#define LOG_MISSING_PUMP -4
|
#define LOG_MISSING_PUMP -4
|
||||||
#define LOG_BOOT_ERROR_DETECTION 10000
|
#define LOG_BOOT_ERROR_DETECTION 10000
|
||||||
|
@ -148,7 +148,7 @@ public:
|
|||||||
{
|
{
|
||||||
return MISSING_SENSOR;
|
return MISSING_SENSOR;
|
||||||
}
|
}
|
||||||
if (mMoisture_raw.getMedian() > MOIST_SENSOR_MAX_FRQ)
|
else if (mMoisture_raw.getMedian() > MOIST_SENSOR_MAX_FRQ)
|
||||||
{
|
{
|
||||||
return SHORT_CIRCUIT_MODE;
|
return SHORT_CIRCUIT_MODE;
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ long nextBlink = 0; /**< Time needed in main loop to support expected blink code
|
|||||||
|
|
||||||
RunningMedian waterRawSensor = RunningMedian(5);
|
RunningMedian waterRawSensor = RunningMedian(5);
|
||||||
float mSolarVoltage = 0.0f; /**< Voltage from solar panels */
|
float mSolarVoltage = 0.0f; /**< Voltage from solar panels */
|
||||||
|
float mBatteryVoltage = 0.0f; /**< Voltage from lipo */
|
||||||
unsigned long setupFinishedTimestamp;
|
unsigned long setupFinishedTimestamp;
|
||||||
|
|
||||||
bool pumpStarted = false;
|
bool pumpStarted = false;
|
||||||
@ -189,7 +190,12 @@ void espDeepSleep(bool afterPump = false)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE)
|
if (mBatteryVoltage < VOLT_MIN_BATT)
|
||||||
|
{
|
||||||
|
log(LOG_LEVEL_INFO, String(String(mBatteryVoltage) + "V! Almost empty -> deepSleepNight times " + String(LOWVOLT_SLEEP_FACTOR)), LOG_SLEEP_LOWVOLTAGE);
|
||||||
|
secondsToSleep = (deepSleepNightTime.get() * LOWVOLT_SLEEP_FACTOR);
|
||||||
|
}
|
||||||
|
else if (mSolarVoltage < SOLAR_CHARGE_MIN_VOLTAGE)
|
||||||
{
|
{
|
||||||
log(LOG_LEVEL_INFO, String(String(mSolarVoltage) + "V! Low light -> deepSleepNight"), LOG_SLEEP_NIGHT);
|
log(LOG_LEVEL_INFO, String(String(mSolarVoltage) + "V! Low light -> deepSleepNight"), LOG_SLEEP_NIGHT);
|
||||||
secondsToSleep = deepSleepNightTime.get();
|
secondsToSleep = deepSleepNightTime.get();
|
||||||
@ -1042,7 +1048,7 @@ void plantcontrol()
|
|||||||
|
|
||||||
Serial << "W : " << waterRawSensor.getAverage() << " mm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << " mm left)" << endl;
|
Serial << "W : " << waterRawSensor.getAverage() << " mm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << " mm left)" << endl;
|
||||||
|
|
||||||
float batteryVoltage = battery.getVoltage(BATTSENSOR_INDEX_BATTERY);
|
mBatteryVoltage = 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;
|
||||||
|
|
||||||
@ -1062,8 +1068,8 @@ void plantcontrol()
|
|||||||
sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage()));
|
sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT));
|
sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT));
|
||||||
sensorLipo.setProperty("volt").send(String(batteryVoltage));
|
sensorLipo.setProperty("volt").send(String(mBatteryVoltage));
|
||||||
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
|
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
|
||||||
sensorLipo.setProperty("Ah").send(String(battery.getAh()));
|
sensorLipo.setProperty("Ah").send(String(battery.getAh()));
|
||||||
sensorLipo.setProperty("ICA").send(String(battery.getICA()));
|
sensorLipo.setProperty("ICA").send(String(battery.getICA()));
|
||||||
@ -1082,7 +1088,7 @@ void plantcontrol()
|
|||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isLowLight = mSolarVoltage <= 9;
|
bool isLowLight = (mSolarVoltage <= SOLAR_CHARGE_MAX_VOLTAGE);
|
||||||
#if defined(TIMED_LIGHT_PIN)
|
#if defined(TIMED_LIGHT_PIN)
|
||||||
|
|
||||||
bool shouldLight = determineTimedLightState(isLowLight);
|
bool shouldLight = determineTimedLightState(isLowLight);
|
||||||
|
Loading…
Reference in New Issue
Block a user