Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
aee4725379 | |||
697ed69d95 | |||
6adfb3c09e |
@ -12,7 +12,6 @@ Heating::Heating() : mHeizungTicker(),
|
||||
msettings(nullptr),
|
||||
mheatingservice(nullptr),
|
||||
mHeatingStatus(false),
|
||||
mPumpCycleActive(false),
|
||||
lasttemp(0),
|
||||
lasthum(0),
|
||||
sensor() {}
|
||||
@ -33,8 +32,8 @@ void Heating::init(unsigned mode, const SettingState *settings, HeatingInfoServi
|
||||
|
||||
sensor.onData([this](float hum, float temp) {
|
||||
schedule_function([hum, temp, this]() {
|
||||
// Serial.printf("Temp: %gdegC\n", temp);
|
||||
// Serial.printf("Humid: %g%%\n", hum);
|
||||
Serial.printf("Temp: %gdegC\n", temp);
|
||||
Serial.printf("Humid: %g%%\n", hum);
|
||||
|
||||
mheatingservice->setSensorData(hum, temp);
|
||||
|
||||
@ -56,16 +55,13 @@ void Heating::init(unsigned mode, const SettingState *settings, HeatingInfoServi
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
}
|
||||
|
||||
// schedule_function([e]() {
|
||||
// Serial.printf("Error: %d\n", e);
|
||||
// });
|
||||
schedule_function([e]() {
|
||||
Serial.printf("Error: %d\n", e);
|
||||
});
|
||||
});
|
||||
|
||||
mHeizungTicker.attach(10, [this]() {
|
||||
// only check if no pump cycle is active
|
||||
if (!mPumpCycleActive) {
|
||||
sensor.read();
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
@ -80,10 +76,9 @@ void Heating::handleHeatingEvents() {
|
||||
if (mHeatingStatus == false) {
|
||||
// turn off active turnoff timers
|
||||
mLuefterTicker.detach();
|
||||
//Serial.println("heating should run now!");
|
||||
|
||||
Serial.println("heating should run now!");
|
||||
// turn on heating and fan
|
||||
digitalWrite(LuefterPin, HIGH);
|
||||
|
||||
digitalWrite(HeizungPin, HIGH);
|
||||
|
||||
mHeatingStatus = true;
|
||||
@ -95,7 +90,7 @@ void Heating::handleHeatingEvents() {
|
||||
// if humidity too low turn off heating and fan after 60secs
|
||||
if (mHeatingStatus == true) {
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
////Serial.println("heating should NOT run now!");
|
||||
Serial.println("heating should NOT run now!");
|
||||
// add the heat time it took to the total
|
||||
mheatingservice->addHeatTime(Timer::getSystemSeconds() - mheatingservice->getLastHeatingStartTime());
|
||||
|
||||
@ -105,7 +100,7 @@ void Heating::handleHeatingEvents() {
|
||||
// turn off fan
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
schedule_function([]() {
|
||||
////Serial.println("turning off fan");
|
||||
Serial.println("turning off fan");
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -126,46 +121,21 @@ void Heating::handleTimeHeater() {
|
||||
digitalWrite(LuefterPin, HIGH);
|
||||
digitalWrite(HeizungPin, HIGH);
|
||||
|
||||
////Serial.println("Turning on heating");
|
||||
Serial.println("Turning on heating");
|
||||
|
||||
mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
|
||||
////Serial.println("Turned off heating!");
|
||||
Serial.println("Turned off heating!");
|
||||
});
|
||||
|
||||
mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
|
||||
////Serial.println("Turned off fan!");
|
||||
Serial.println("Turned off fan!");
|
||||
});
|
||||
};
|
||||
|
||||
func();
|
||||
mHeizungTicker.attach(refreshperiod, func);
|
||||
}
|
||||
|
||||
void Heating::setPumCycleActive(bool active) {
|
||||
mPumpCycleActive = active;
|
||||
|
||||
// turn off fan if pumpcycleactive
|
||||
if (active) {
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
|
||||
mHeizungTicker.detach();
|
||||
|
||||
if (mHeatingStatus) {
|
||||
// to add the correct time to the heat min counter!
|
||||
mheatingservice->addHeatTime(Timer::getSystemSeconds() - mheatingservice->getLastHeatingStartTime());
|
||||
}
|
||||
} else {
|
||||
mHeizungTicker.detach();
|
||||
mHeizungTicker.attach(10, [this]() {
|
||||
// only check if no pump cycle is active
|
||||
if (!mPumpCycleActive) {
|
||||
sensor.read();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ public:
|
||||
*/
|
||||
void init(unsigned mode, const SettingState* settings, HeatingInfoService *heatingservice);
|
||||
|
||||
void setPumCycleActive(bool active);
|
||||
|
||||
enum MODES {TIME, HUMIDITY};
|
||||
private:
|
||||
Ticker mHeizungTicker;
|
||||
@ -32,7 +30,7 @@ private:
|
||||
const SettingState* msettings;
|
||||
HeatingInfoService *mheatingservice;
|
||||
|
||||
bool mHeatingStatus, mPumpCycleActive;
|
||||
bool mHeatingStatus;
|
||||
|
||||
float lasttemp;
|
||||
float lasthum;
|
||||
|
@ -16,6 +16,6 @@
|
||||
#define TempSensorPin D4
|
||||
|
||||
// version info
|
||||
#define VERSION "v1.2.4-Alpa1"
|
||||
#define VERSION "v1.2.4-Alpha2"
|
||||
|
||||
#endif //PUMPENSTEUERUNG_PINS_H
|
||||
|
@ -17,12 +17,12 @@ SettingsService::SettingsService(AsyncWebServer *server, SecurityManager *securi
|
||||
}
|
||||
|
||||
void SettingsService::onConfigUpdated() {
|
||||
////Serial.println("switching led!");
|
||||
Serial.println("switching led!");
|
||||
|
||||
File settingsFile = ESPFS.open("settings.json", "w+");
|
||||
|
||||
if (settingsFile) {
|
||||
////Serial.println("writing config file!");
|
||||
Serial.println("writing config file!");
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
doc["waterOutageWaitDuration"] = _state.waterOutageWaitDuration;
|
||||
@ -46,7 +46,7 @@ void SettingsService::begin() {
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, settingsFile);
|
||||
if (error) {
|
||||
////Serial.println(F("Failed to read file, using default configuration"));
|
||||
Serial.println(F("Failed to read file, using default configuration"));
|
||||
onConfigUpdated();
|
||||
return;
|
||||
}
|
||||
@ -59,7 +59,7 @@ void SettingsService::begin() {
|
||||
_state.heatLow = doc["heatLow"] | 65;
|
||||
_state.fanRuntime = doc["fanRuntime"] | 60;
|
||||
|
||||
////Serial.println("read config file!");
|
||||
Serial.println("read config file!");
|
||||
|
||||
settingsFile.close();
|
||||
}
|
||||
|
71
src/main.cpp
71
src/main.cpp
@ -15,7 +15,7 @@ bool error = false;
|
||||
Ticker status;
|
||||
|
||||
//pumpendauer maximum ticker
|
||||
Ticker pumpendauer;
|
||||
Ticker pumpendauer, wasserSensorDoubleCheck;
|
||||
|
||||
//WifiManager mang;
|
||||
Heating mHeat;
|
||||
@ -33,11 +33,11 @@ SettingsService settingsservice = SettingsService(&server, esp8266React.getSecur
|
||||
void pumpeSchalten(bool on) {
|
||||
// digitalWrite(4,on);
|
||||
if (on) {
|
||||
//Serial.println("versuche Pumpe EIN zuschalten");
|
||||
Serial.println("versuche Pumpe EIN zuschalten");
|
||||
// refresh last pump counter
|
||||
generalinfo.setlastPumpTime(Timer::getSystemSeconds());
|
||||
} else {
|
||||
//Serial.println("versuche Pumpe AUS zuschalten");
|
||||
Serial.println("versuche Pumpe AUS zuschalten");
|
||||
}
|
||||
|
||||
if (allow && !error) {
|
||||
@ -45,57 +45,49 @@ void pumpeSchalten(bool on) {
|
||||
pumpcycles++;
|
||||
generalinfo.setPumpCycles(pumpcycles);
|
||||
|
||||
// pump cycle started
|
||||
mHeat.setPumCycleActive(true);
|
||||
|
||||
pumpendauer.once((float) settingsservice.getSettings()->maxpumpduration + 1, []() {
|
||||
//erlaube keine einschaltung von mehr als 60 sek
|
||||
if (Timer::getSystemSeconds() - turnontime >=
|
||||
(unsigned) settingsservice.getSettings()->maxpumpduration && turnontime != 0) {
|
||||
//error zu lange
|
||||
//Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
|
||||
Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
|
||||
pumpeSchalten(false);
|
||||
error = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
generalinfo.setPumpDuration(Timer::getSystemSeconds() - turnontime);
|
||||
|
||||
// pump cycle stopped...
|
||||
mHeat.setPumCycleActive(false);
|
||||
}
|
||||
|
||||
// save pump start time
|
||||
turnontime = Timer::getSystemSeconds();
|
||||
|
||||
digitalWrite(SchuetzPin, on);
|
||||
//Serial.println("[Erfolg] pumpe wird geschalten");
|
||||
Serial.println("[Erfolg] pumpe wird geschalten");
|
||||
} else {
|
||||
//Serial.println("[FEHLGESCHLAGEN] Schalten des Schütz gesperrt durch Timeout oder Fehler-- sofortiges ausschalten der pumpe\n");
|
||||
Serial.println(
|
||||
"[FEHLGESCHLAGEN] Schalten des Schütz gesperrt durch Timeout oder Fehler-- sofortiges ausschalten der pumpe\n");
|
||||
turnontime = -1;
|
||||
digitalWrite(SchuetzPin, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
ICACHE_RAM_ATTR void DruckschalterInt() {
|
||||
schedule_function([]() {
|
||||
if (digitalRead(DruckSensorPin) == HIGH) {
|
||||
//pumpe einschalten
|
||||
//Serial.println("\n\nDruck Sensor EIN");
|
||||
Serial.println("\n\nDruck Sensor EIN");
|
||||
if (digitalRead(WasserSensorPin)) {
|
||||
//Serial.println("Wasser Sensor EIN");
|
||||
Serial.println("Wasser Sensor EIN");
|
||||
pumpeSchalten(true);
|
||||
} else {
|
||||
//Serial.println("Wasser Sensor aus irgent einem Grund doch nicht ein -- sofort abschalten!");
|
||||
Serial.println("Wasser Sensor aus irgent einem Grund doch nicht ein -- sofort abschalten!");
|
||||
pumpeSchalten(false);
|
||||
}
|
||||
} else {
|
||||
//pumpe ausschalten
|
||||
//Serial.println("\n\nDruck Sensor AUS");
|
||||
Serial.println("\n\nDruck Sensor AUS");
|
||||
pumpeSchalten(false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// time counter to wait
|
||||
@ -103,50 +95,55 @@ int wateroutagewaitduration;
|
||||
|
||||
void WasserSensorCheck() {
|
||||
if (digitalRead(WasserSensorPin) == LOW) {
|
||||
//Serial.println("Wasser Sensor AUS");
|
||||
// check if water sensor is also low after 500ms and lock it then
|
||||
wasserSensorDoubleCheck.once_ms(500, []() {
|
||||
if (digitalRead(WasserSensorPin) == LOW) {
|
||||
Serial.println("Wasser Sensor AUS");
|
||||
//kein Wasser dh timer auf 10min stellen
|
||||
|
||||
// refresh wateroutage counter
|
||||
generalinfo.setlastWaterOutage(Timer::getSystemSeconds());
|
||||
|
||||
allow = false;
|
||||
//Serial.println("Schalte pumpe aus");
|
||||
Serial.println("Schalte pumpe aus");
|
||||
pumpeSchalten(false);
|
||||
|
||||
//Serial.println("warte 30min");
|
||||
Serial.println("warte 30min");
|
||||
|
||||
status.detach();
|
||||
|
||||
wateroutagewaitduration = settingsservice.getSettings()->waterOutageWaitDuration;
|
||||
|
||||
status.detach();
|
||||
status.attach(5, []() {
|
||||
wateroutagewaitduration -= 5;
|
||||
//Serial.print("noch ");
|
||||
//Serial.print(wateroutagewaitduration);
|
||||
//Serial.println(" Sekunden verbleibend");
|
||||
Serial.print("noch ");
|
||||
Serial.print(wateroutagewaitduration);
|
||||
Serial.println(" Sekunden verbleibend");
|
||||
|
||||
if (wateroutagewaitduration <= 0) {
|
||||
status.detach();
|
||||
if (digitalRead(WasserSensorPin)) {
|
||||
allow = true;
|
||||
//Serial.println("Einschalten der Pumpe wieder erlaubt.");
|
||||
Serial.println("Einschalten der Pumpe wieder erlaubt.");
|
||||
|
||||
//pruefen ob drucksensor ein
|
||||
DruckschalterInt();
|
||||
} else {
|
||||
//Serial.print("wassersensor immer noch kein Wasser --> verlaengern um 120min\n\n");
|
||||
Serial.print("wassersensor immer noch kein Wasser --> verlaengern um 120min\n\n");
|
||||
WasserSensorCheck();
|
||||
}
|
||||
status.detach();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//Serial.println("Wasser Sensor EIN");
|
||||
Serial.println("Wasser Sensor EIN");
|
||||
}
|
||||
}
|
||||
|
||||
ICACHE_RAM_ATTR void WasserSensorInt() {
|
||||
schedule_function([]() {
|
||||
WasserSensorCheck();
|
||||
});
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@ -167,9 +164,9 @@ void setup() {
|
||||
|
||||
// initilize serial connection
|
||||
Serial.begin(115200);
|
||||
//Serial.println("\n\n\n\nstartup of ESP");
|
||||
//Serial.print("Version: ");
|
||||
//Serial.println(VERSION);
|
||||
Serial.println("\n\n\n\nstartup of ESP");
|
||||
Serial.print("Version: ");
|
||||
Serial.println(VERSION);
|
||||
|
||||
|
||||
//initial measurement of water state
|
||||
@ -191,16 +188,16 @@ void setup() {
|
||||
|
||||
|
||||
// initialize wifi
|
||||
//Serial.println("Initializing wifi");
|
||||
Serial.println("Initializing wifi");
|
||||
esp8266React.begin();
|
||||
settingsservice.begin();
|
||||
server.begin();
|
||||
|
||||
// initialize heating control
|
||||
//Serial.println("initializing heating service");
|
||||
Serial.println("initializing heating service");
|
||||
mHeat.init(Heating::HUMIDITY, settingsservice.getSettings(), &heatinginfo);
|
||||
|
||||
//Serial.println("startup sequence complete!\n");
|
||||
Serial.println("startup sequence complete!\n");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user