comment out all Serialprints to not interrupt timer functions

This commit is contained in:
lukas 2021-03-31 17:03:36 +02:00
parent 5351bcb15d
commit a9671773f3
3 changed files with 54 additions and 48 deletions

View File

@ -55,9 +55,9 @@ void Heating::init(unsigned mode, const SettingState *settings, HeatingInfoServi
digitalWrite(HeizungPin, LOW); digitalWrite(HeizungPin, LOW);
} }
schedule_function([e]() { // schedule_function([e]() {
Serial.printf("Error: %d\n", e); // Serial.printf("Error: %d\n", e);
}); // });
}); });
mHeizungTicker.attach(10, [this]() { mHeizungTicker.attach(10, [this]() {
@ -76,7 +76,7 @@ void Heating::handleHeatingEvents() {
if (mHeatingStatus == false) { if (mHeatingStatus == false) {
// turn off active turnoff timers // turn off active turnoff timers
mLuefterTicker.detach(); mLuefterTicker.detach();
Serial.println("heating should run now!"); ////Serial.println("heating should run now!");
// turn on heating and fan // turn on heating and fan
digitalWrite(LuefterPin, HIGH); digitalWrite(LuefterPin, HIGH);
digitalWrite(HeizungPin, HIGH); digitalWrite(HeizungPin, HIGH);
@ -90,7 +90,7 @@ void Heating::handleHeatingEvents() {
// if humidity too low turn off heating and fan after 60secs // if humidity too low turn off heating and fan after 60secs
if (mHeatingStatus == true) { if (mHeatingStatus == true) {
digitalWrite(HeizungPin, LOW); 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 // add the heat time it took to the total
mheatingservice->addHeatTime(Timer::getSystemSeconds() - mheatingservice->getLastHeatingStartTime()); mheatingservice->addHeatTime(Timer::getSystemSeconds() - mheatingservice->getLastHeatingStartTime());
@ -100,7 +100,7 @@ void Heating::handleHeatingEvents() {
// turn off fan // turn off fan
digitalWrite(LuefterPin, LOW); digitalWrite(LuefterPin, LOW);
schedule_function([]() { schedule_function([]() {
Serial.println("turning off fan"); ////Serial.println("turning off fan");
}); });
}); });
} }
@ -121,18 +121,18 @@ void Heating::handleTimeHeater() {
digitalWrite(LuefterPin, HIGH); digitalWrite(LuefterPin, HIGH);
digitalWrite(HeizungPin, HIGH); digitalWrite(HeizungPin, HIGH);
Serial.println("Turning on heating"); ////Serial.println("Turning on heating");
mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() { mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
digitalWrite(HeizungPin, LOW); digitalWrite(HeizungPin, LOW);
Serial.println("Turned off heating!"); ////Serial.println("Turned off heating!");
}); });
mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() { mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
digitalWrite(LuefterPin, LOW); digitalWrite(LuefterPin, LOW);
Serial.println("Turned off fan!"); ////Serial.println("Turned off fan!");
}); });
}; };

View File

@ -17,12 +17,12 @@ SettingsService::SettingsService(AsyncWebServer *server, SecurityManager *securi
} }
void SettingsService::onConfigUpdated() { void SettingsService::onConfigUpdated() {
Serial.println("switching led!"); ////Serial.println("switching led!");
File settingsFile = ESPFS.open("settings.json", "w+"); File settingsFile = ESPFS.open("settings.json", "w+");
if (settingsFile) { if (settingsFile) {
Serial.println("writing config file!"); ////Serial.println("writing config file!");
StaticJsonDocument<256> doc; StaticJsonDocument<256> doc;
doc["waterOutageWaitDuration"] = _state.waterOutageWaitDuration; doc["waterOutageWaitDuration"] = _state.waterOutageWaitDuration;
@ -46,7 +46,7 @@ void SettingsService::begin() {
// Deserialize the JSON document // Deserialize the JSON document
DeserializationError error = deserializeJson(doc, settingsFile); DeserializationError error = deserializeJson(doc, settingsFile);
if (error) { if (error) {
Serial.println(F("Failed to read file, using default configuration")); ////Serial.println(F("Failed to read file, using default configuration"));
onConfigUpdated(); onConfigUpdated();
return; return;
} }
@ -59,7 +59,7 @@ void SettingsService::begin() {
_state.heatLow = doc["heatLow"] | 65; _state.heatLow = doc["heatLow"] | 65;
_state.fanRuntime = doc["fanRuntime"] | 60; _state.fanRuntime = doc["fanRuntime"] | 60;
Serial.println("read config file!"); ////Serial.println("read config file!");
settingsFile.close(); settingsFile.close();
} }

View File

@ -33,11 +33,11 @@ SettingsService settingsservice = SettingsService(&server, esp8266React.getSecur
void pumpeSchalten(bool on) { void pumpeSchalten(bool on) {
// digitalWrite(4,on); // digitalWrite(4,on);
if (on) { if (on) {
Serial.println("versuche Pumpe EIN zuschalten"); //Serial.println("versuche Pumpe EIN zuschalten");
// refresh last pump counter // refresh last pump counter
generalinfo.setlastPumpTime(Timer::getSystemSeconds()); generalinfo.setlastPumpTime(Timer::getSystemSeconds());
} else { } else {
Serial.println("versuche Pumpe AUS zuschalten"); //Serial.println("versuche Pumpe AUS zuschalten");
} }
if (allow && !error) { if (allow && !error) {
@ -47,9 +47,10 @@ void pumpeSchalten(bool on) {
pumpendauer.once((float) settingsservice.getSettings()->maxpumpduration + 1, []() { pumpendauer.once((float) settingsservice.getSettings()->maxpumpduration + 1, []() {
//erlaube keine einschaltung von mehr als 60 sek //erlaube keine einschaltung von mehr als 60 sek
if (Timer::getSystemSeconds() - turnontime >= (unsigned)settingsservice.getSettings()->maxpumpduration && turnontime != 0) { if (Timer::getSystemSeconds() - turnontime >=
(unsigned) settingsservice.getSettings()->maxpumpduration && turnontime != 0) {
//error zu lange //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); pumpeSchalten(false);
error = true; error = true;
} }
@ -62,30 +63,33 @@ void pumpeSchalten(bool on) {
turnontime = Timer::getSystemSeconds(); turnontime = Timer::getSystemSeconds();
digitalWrite(SchuetzPin, on); digitalWrite(SchuetzPin, on);
Serial.println("[Erfolg] pumpe wird geschalten"); //Serial.println("[Erfolg] pumpe wird geschalten");
} else { } 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; turnontime = -1;
digitalWrite(SchuetzPin, LOW); digitalWrite(SchuetzPin, LOW);
} }
} }
ICACHE_RAM_ATTR void DruckschalterInt() { ICACHE_RAM_ATTR void DruckschalterInt() {
schedule_function([]() {
if (digitalRead(DruckSensorPin) == HIGH) { if (digitalRead(DruckSensorPin) == HIGH) {
//pumpe einschalten //pumpe einschalten
Serial.println("\n\nDruck Sensor EIN"); //Serial.println("\n\nDruck Sensor EIN");
if (digitalRead(WasserSensorPin)) { if (digitalRead(WasserSensorPin)) {
Serial.println("Wasser Sensor EIN"); //Serial.println("Wasser Sensor EIN");
pumpeSchalten(true); pumpeSchalten(true);
} else { } 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); pumpeSchalten(false);
} }
} else { } else {
//pumpe ausschalten //pumpe ausschalten
Serial.println("\n\nDruck Sensor AUS"); //Serial.println("\n\nDruck Sensor AUS");
pumpeSchalten(false); pumpeSchalten(false);
} }
});
} }
// time counter to wait // time counter to wait
@ -93,48 +97,50 @@ int wateroutagewaitduration;
void WasserSensorCheck() { void WasserSensorCheck() {
if (digitalRead(WasserSensorPin) == LOW) { if (digitalRead(WasserSensorPin) == LOW) {
Serial.println("Wasser Sensor AUS"); //Serial.println("Wasser Sensor AUS");
//kein Wasser dh timer auf 10min stellen //kein Wasser dh timer auf 10min stellen
// refresh wateroutage counter // refresh wateroutage counter
generalinfo.setlastWaterOutage(Timer::getSystemSeconds()); generalinfo.setlastWaterOutage(Timer::getSystemSeconds());
allow = false; allow = false;
Serial.println("Schalte pumpe aus"); //Serial.println("Schalte pumpe aus");
pumpeSchalten(false); pumpeSchalten(false);
Serial.println("warte 30min"); //Serial.println("warte 30min");
status.detach(); status.detach();
wateroutagewaitduration = settingsservice.getSettings()->waterOutageWaitDuration; wateroutagewaitduration = settingsservice.getSettings()->waterOutageWaitDuration;
status.attach(5, []() { status.attach(5, []() {
wateroutagewaitduration -= 5; wateroutagewaitduration -= 5;
Serial.print("noch "); //Serial.print("noch ");
Serial.print(wateroutagewaitduration); //Serial.print(wateroutagewaitduration);
Serial.println(" Sekunden verbleibend"); //Serial.println(" Sekunden verbleibend");
if (wateroutagewaitduration <= 0) { if (wateroutagewaitduration <= 0) {
if (digitalRead(WasserSensorPin)) { if (digitalRead(WasserSensorPin)) {
allow = true; allow = true;
Serial.println("Einschalten der Pumpe wieder erlaubt."); //Serial.println("Einschalten der Pumpe wieder erlaubt.");
//pruefen ob drucksensor ein //pruefen ob drucksensor ein
DruckschalterInt(); DruckschalterInt();
} else { } 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(); WasserSensorCheck();
} }
status.detach(); status.detach();
} }
}); });
} else { } else {
Serial.println("Wasser Sensor EIN"); //Serial.println("Wasser Sensor EIN");
} }
} }
ICACHE_RAM_ATTR void WasserSensorInt() { ICACHE_RAM_ATTR void WasserSensorInt() {
schedule_function([]() {
WasserSensorCheck(); WasserSensorCheck();
});
} }
void setup() { void setup() {
@ -155,9 +161,9 @@ void setup() {
// initilize serial connection // initilize serial connection
Serial.begin(115200); Serial.begin(115200);
Serial.println("\n\n\n\nstartup of ESP"); //Serial.println("\n\n\n\nstartup of ESP");
Serial.print("Version: "); //Serial.print("Version: ");
Serial.println(VERSION); //Serial.println(VERSION);
//initial measurement of water state //initial measurement of water state
@ -179,16 +185,16 @@ void setup() {
// initialize wifi // initialize wifi
Serial.println("Initializing wifi"); //Serial.println("Initializing wifi");
esp8266React.begin(); esp8266React.begin();
settingsservice.begin(); settingsservice.begin();
server.begin(); server.begin();
// initialize heating control // initialize heating control
Serial.println("initializing heating service"); //Serial.println("initializing heating service");
mHeat.init(Heating::HUMIDITY, settingsservice.getSettings(), &heatinginfo); mHeat.init(Heating::HUMIDITY, settingsservice.getSettings(), &heatinginfo);
Serial.println("startup sequence complete!\n"); //Serial.println("startup sequence complete!\n");
} }