Deep sleep is set according daylight
This commit is contained in:
parent
5591c6dba2
commit
1485539a8b
@ -86,6 +86,14 @@ Plant mPlants[MAX_PLANTS] = {
|
|||||||
Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6, &plant6, &mSetting6)
|
Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6, &plant6, &mSetting6)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
float getBatteryVoltage(){
|
||||||
|
return ADC_5V_TO_3V3(lipoRawSensor.getAverage());
|
||||||
|
}
|
||||||
|
|
||||||
|
float getSolarVoltage(){
|
||||||
|
return SOLAR_VOLT(solarRawSensor.getAverage());
|
||||||
|
}
|
||||||
|
|
||||||
void readSystemSensors() {
|
void readSystemSensors() {
|
||||||
lipoRawSensor.add(analogRead(SENSOR_LIPO));
|
lipoRawSensor.add(analogRead(SENSOR_LIPO));
|
||||||
solarRawSensor.add(analogRead(SENSOR_SOLAR));
|
solarRawSensor.add(analogRead(SENSOR_SOLAR));
|
||||||
@ -120,6 +128,8 @@ void espDeepSleepFor(long seconds){
|
|||||||
wait4sleep.in(500, prepareSleep);
|
wait4sleep.in(500, prepareSleep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mode2MQTT(){
|
void mode2MQTT(){
|
||||||
readSystemSensors();
|
readSystemSensors();
|
||||||
|
|
||||||
@ -144,9 +154,9 @@ void mode2MQTT(){
|
|||||||
lastWaterValue = mWaterGone;
|
lastWaterValue = mWaterGone;
|
||||||
|
|
||||||
sensorLipo.setProperty("percent").send( String(100 * lipoRawSensor.getAverage() / 4095) );
|
sensorLipo.setProperty("percent").send( String(100 * lipoRawSensor.getAverage() / 4095) );
|
||||||
sensorLipo.setProperty("volt").send( String(ADC_5V_TO_3V3(lipoRawSensor.getAverage())) );
|
sensorLipo.setProperty("volt").send( String(getBatteryVoltage()) );
|
||||||
sensorSolar.setProperty("percent").send(String((100 * solarRawSensor.getAverage() ) / 4095));
|
sensorSolar.setProperty("percent").send(String((100 * solarRawSensor.getAverage() ) / 4095));
|
||||||
sensorSolar.setProperty("volt").send( String(SOLAR_VOLT(solarRawSensor.getAverage())) );
|
sensorSolar.setProperty("volt").send( String(getSolarVoltage()) );
|
||||||
|
|
||||||
float temp[2] = { TEMP_INIT_VALUE, TEMP_INIT_VALUE };
|
float temp[2] = { TEMP_INIT_VALUE, TEMP_INIT_VALUE };
|
||||||
float* pFloat = temp;
|
float* pFloat = temp;
|
||||||
@ -179,9 +189,8 @@ void mode2MQTT(){
|
|||||||
setLastActivationForPump(lastPumpRunning, getCurrentTime());
|
setLastActivationForPump(lastPumpRunning, getCurrentTime());
|
||||||
digitalWrite(mPlants[lastPumpRunning].mPinPump, HIGH);
|
digitalWrite(mPlants[lastPumpRunning].mPinPump, HIGH);
|
||||||
}
|
}
|
||||||
float solarValue = solarRawSensor.getMedian();
|
|
||||||
if(lastPumpRunning == -1 || !hasWater){
|
if(lastPumpRunning == -1 || !hasWater){
|
||||||
if((ADC_5V_TO_3V3(solarValue) < SOLAR_CHARGE_MIN_VOLTAGE)){
|
if(getSolarVoltage() < SOLAR_CHARGE_MIN_VOLTAGE){
|
||||||
gotoMode2AfterThisTimestamp = getCurrentTime()+deepSleepNightTime.get();
|
gotoMode2AfterThisTimestamp = getCurrentTime()+deepSleepNightTime.get();
|
||||||
Serial.println("No pumps to activate and low light, deepSleepNight");
|
Serial.println("No pumps to activate and low light, deepSleepNight");
|
||||||
espDeepSleepFor(deepSleepNightTime.get());
|
espDeepSleepFor(deepSleepNightTime.get());
|
||||||
@ -375,7 +384,7 @@ void onHomieEvent(const HomieEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int determineNextPump(){
|
int determineNextPump(){
|
||||||
float solarValue = solarRawSensor.getMedian();
|
float solarValue = getSolarVoltage();
|
||||||
bool isLowLight =(ADC_5V_TO_3V3(solarValue) > SOLAR_CHARGE_MIN_VOLTAGE || ADC_5V_TO_3V3(solarValue) < SOLAR_CHARGE_MAX_VOLTAGE);
|
bool isLowLight =(ADC_5V_TO_3V3(solarValue) > SOLAR_CHARGE_MIN_VOLTAGE || ADC_5V_TO_3V3(solarValue) < SOLAR_CHARGE_MAX_VOLTAGE);
|
||||||
|
|
||||||
|
|
||||||
@ -710,9 +719,9 @@ void setup() {
|
|||||||
// Big TODO use here the settings in RTC_Memory
|
// Big TODO use here the settings in RTC_Memory
|
||||||
|
|
||||||
//Panik mode, the Lipo is empty, sleep a long long time:
|
//Panik mode, the Lipo is empty, sleep a long long time:
|
||||||
if ((ADC_5V_TO_3V3(lipoRawSensor.getAverage()) < MINIMUM_LIPO_VOLT) &&
|
if ((getBatteryVoltage() < MINIMUM_LIPO_VOLT) &&
|
||||||
(ADC_5V_TO_3V3(lipoRawSensor.getAverage()) > NO_LIPO_VOLT)) {
|
(getBatteryVoltage() > NO_LIPO_VOLT)) {
|
||||||
Serial << PANIK_MODE_DEEPSLEEP << " s lipo " << ADC_5V_TO_3V3(lipoRawSensor.getAverage()) << "V" << endl;
|
Serial << PANIK_MODE_DEEPSLEEP << " s lipo " << getBatteryVoltage() << "V" << endl;
|
||||||
esp_sleep_enable_timer_wakeup(PANIK_MODE_DEEPSLEEP_US);
|
esp_sleep_enable_timer_wakeup(PANIK_MODE_DEEPSLEEP_US);
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user