From f4391a7b4a6212e1b52e1c0defb98a814cfd24a7 Mon Sep 17 00:00:00 2001 From: sven Date: Mon, 28 Aug 2023 23:15:14 +0200 Subject: [PATCH] =?UTF-8?q?Steuerung=20inkl.=20Webserver=20zugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +- TankCool.ino | 284 ++++++++++++++++++++++++++++++++++++++++++++------- serial.txt | 0 3 files changed, 254 insertions(+), 38 deletions(-) create mode 100644 serial.txt diff --git a/README.md b/README.md index 82c5441..c987d8b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ * 0x28, 0x70, 0x21, 0x80, 0xE3, 0xE1, 0x3C, 0xE5 ### Adressen der Relais für Tanks -* T1: R0, Arduino Mega 22 -* T2: R1, Arduino Mega 23 - +* Bypass: R0, Arduino Mega 22 +* T1: R1, Arduino Mega 23 +* T2: R2, Arduino Mega 24 +* KW: R8, Arduino Mega 30 +* KW_Pumpe: R8, Arduino Mega 31 diff --git a/TankCool.ino b/TankCool.ino index afc5179..0f80c1a 100644 --- a/TankCool.ino +++ b/TankCool.ino @@ -7,7 +7,9 @@ /********************************************************************/ // Data wire is plugged into pin 2 on the Arduino -#define ONE_WIRE_BUS 20 +#define ONE_WIRE_BUS 2 +#define TEMPERATURE_PRECISION 11 + /********************************************************************/ // Setup a oneWire instance to communicate with any OneWire devices // (not just Maxim/Dallas temperature ICs) @@ -16,27 +18,153 @@ OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); /********************************************************************/ -byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x09, 0x70 }; -IPAddress ip(192,168,178,57); -EthernetServer server(80); +DeviceAddress adT1 = { 0x28, 0xF8, 0xE2, 0x80, 0xE3, 0xE1, 0x3C, 0xC2 }; +DeviceAddress adT2 = { 0x28, 0x89, 0x9F, 0x80, 0xE3, 0xE1, 0x3C, 0xEC }; +DeviceAddress adKW = { 0x28, 0x3B, 0x58, 0x80, 0xE3, 0xE1, 0x3C, 0xF6 }; -void setup() { - // start serial port - Serial.begin(9600); - // Start up the library - sensors.begin(); +float TT1_Sp = 30.0; +float TT2_Sp = 30.0; +float TKW_Sp = 0.0; +float Hyst_Sp = 0.5; + +float TT1_AV; +float TT2_AV; +float TKW_AV; + +byte Act_T1; +byte Act_T2; +byte Act_KW; + +byte State_Bypass = 0; +unsigned long previousMillisBypass = 0; +byte State_T1 = 0; +unsigned long previousMillisT1 = 0; +byte State_T2 = 0; +unsigned long previousMillisT2 = 0; + +// Variables for Webserver +byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x09, 0x70 }; +IPAddress ip(192,168,1,57); +EthernetServer server(80); +String readString; +int b_str; +int e_str; +String t1_str; +String t2_str; +float t1_float; +float t2_float; + +void setup(void) +{ + Serial.begin(9600); + sensors.begin(); + pinMode(22, OUTPUT); + pinMode(23, OUTPUT); + pinMode(24, OUTPUT); + pinMode(30, OUTPUT); + pinMode(31, OUTPUT); +// set the resolution per device + sensors.setResolution(adT1, TEMPERATURE_PRECISION); + sensors.setResolution(adT2, TEMPERATURE_PRECISION); + sensors.setResolution(adKW, TEMPERATURE_PRECISION); + + // Ethernet Verbindung und Server starten Ethernet.begin(mac, ip); server.begin(); + Serial.print("Server gestartet. IP: "); + // IP des Arduino-Servers ausgeben + Serial.println(Ethernet.localIP()); } -void loop() { - // put your main code here, to run repeatedly: +void loop(void) +{ + // Versorge Zeit + unsigned long currentMillis = millis(); + // Hole Temperaturen + sensors.requestTemperatures(); + TT1_AV = sensors.getTempC(adT1); + //TT1_AV = sensors.getTempCByIndex(0); + TT2_AV = sensors.getTempC(adT2); + //TT2_AV = sensors.getTempCByIndex(1); + TKW_AV = sensors.getTempC(adKW); + //TKW_AV = sensors.getTempCByIndex(2); + + // Vergleiche Aktualtemperaturen mit Setpoint + // Tank 1 + if (TT1_AV >= TT1_Sp + Hyst_Sp){ + Act_T1 = 1; + } + if (TT1_AV <= TT1_Sp){ + Act_T1 = 0; + } + if (TT2_AV >= TT2_Sp + Hyst_Sp){ + Act_T2 = 1; + } + if (TT2_AV <= TT2_Sp){ + Act_T2 = 0; + } + if (TKW_AV >= TKW_Sp + Hyst_Sp){ + Act_KW = 1; + } + if (TKW_AV <= TKW_Sp){ + Act_KW = 0; + } + + // Bypass Ventil schließen, wenn T1 oder T2 offen, delay 2s + if ((Act_T1 == 1|| Act_T2 == 1) && State_Bypass == 0){ + State_Bypass = 1; + previousMillisBypass = currentMillis; + } + if (currentMillis - previousMillisBypass >= 2000 && State_Bypass == 1) { + digitalWrite (22, HIGH); + } + if (Act_T1 == 0 && Act_T2 == 0){ + digitalWrite (22, LOW); + State_Bypass = 0; + } + // Kühlung Tank 1, Ausschaltverzögerung 2s + if (Act_T1 == 1){ + digitalWrite (23, HIGH); + State_T1 = 1; + } + if (Act_T1 == 0 && State_T1 == 1){ + previousMillisT1 = currentMillis; + State_T1 = 0; + } + if (Act_T1 == 0 && State_T1 == 0 && currentMillis - previousMillisT1 >= 2000){ + previousMillisT1 = currentMillis; + digitalWrite (23, LOW); + } + + // Kühlung Tank 2, Ausschaltverzögerung 2s + if (Act_T2 == 1){ + digitalWrite (24, HIGH); + State_T2 = 1; + } + if (Act_T2 == 0 && State_T2 == 1){ + previousMillisT2 = currentMillis; + State_T2 = 0; + } + if (Act_T2 == 0 && State_T2 == 0 && currentMillis - previousMillisT2 >= 2000){ + previousMillisT2 = currentMillis; + digitalWrite (24, LOW); + } + + webserver(); } -void WebServer(){ -// ETHERNET - EthernetClient client = server.available(); + + + + + + +void webserver() { + // server.available() schaut, ob ein Client verfügbar ist und Daten + // an den Server schicken möchte. Gibt dann eine Client-Objekt zurück, + // sonst false + EthernetClient client = server.available(); // Wenn es einen Client gibt, dann... if (client) { Serial.println("Neuer Client"); @@ -48,40 +176,124 @@ void WebServer(){ // client.available() gibt die Anzahl der Zeichen zurück, die zum Lesen // verfügbar sind if (client.available()) { + // Ein Zeichen lesen und am seriellen Monitor ausgeben char c = client.read(); - Serial.write(c); + if (readString.length() < 100) { + + //store characters to string + readString += c; + //Serial.print(c); + } + // In currentLineIsBlank merken wir uns, ob diese Zeile bisher leer war. // Wenn die Zeile leer ist und ein Zeilenwechsel (das \n) kommt, // dann ist die Anfrage zu Ende und wir können antworten if (c == '\n' && currentLineIsBlank) { - client.println("HTTP/1.1 200 OK"); + Serial.println(readString); + // Wertänderung T 1 + b_str = readString.indexOf("T1_Sp="); + e_str = readString.indexOf(" HTTP/"); + t1_str = ""; + if (b_str != -1){ + b_str = b_str + 6; + for (int i=b_str; i < e_str; i++){ + t1_str += readString.charAt(i); + t1_float = t1_str.toFloat(); + if (t1_float != 0){ + TT1_Sp = t1_float; + } + } + } + // Wertänderung T 1 + b_str = readString.indexOf("T2_Sp="); + e_str = readString.indexOf(" HTTP/"); + t2_str = ""; + if (b_str != -1){ + b_str = b_str + 6; + for (int i=b_str; i < e_str; i++){ + t2_str += readString.charAt(i); + t2_float = t2_str.toFloat(); + if (t2_float != 0){ + TT2_Sp = t2_float; + } + } + } + + // HTTP Header 200 an den Browser schicken + client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // Verbindung wird nach Antwort beendet - client.println("Refresh: 30"); // Seite alle 25 Sekunden neu abfragen + client.println("Refresh: 60"); // Seite alle 60 Sekunden neu abfragen client.println(); // Ab hier berginnt der HTML-Code, der an den Browser geschickt wird client.println(""); client.println(""); - client.println("CONTROLLINO Analog Input"); - client.println("

CONTROLLINO

"); + client.println("Temperatursteuerung"); + client.println("

Temperatursteuerung

"); - client.println("

"); - client.print("Aktuelle Temperatur: "); - client.println(temperatureA); - client.println("

"); - client.println("

"); - client.print("Sollwert Temperatur: "); - client.println(temperatureSP); - client.println("

"); - client.println("

"); - client.print("Delta Temperatur: "); - client.println(DeltaT); - client.println("

"); - client.write("
T: "); - client.write("R:
"); - client.println(r,t); - client.println(""); + client.println(""); + client.println(" "); + client.println(" "); + client.println(" "); + client.println(""); + +client.print(""); +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +if (State_T1 == 1){ +client.print(" "); +} +else{ +client.print(" "); +} +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +if (State_T2 == 1){ +client.print(" "); +} +else{ +client.print(" "); +} +client.print(" "); +client.print(" "); +client.print(" "); +client.print(" "); +if (State_Bypass== 0){ +client.print(" "); +} +else{ +client.print(" "); +} +client.print(" "); +client.print(" "); + +client.print(" "); +client.print("
Istwert Sollwert
Tank 1"); client.print(TT1_AV); client.print("°C"); client.print(TT1_AV); client.print("°C"); client.print(TT1_Sp); client.print("°C"); +client.print("
"); +client.print(" "); +client.print(" "); +client.print(" "); +client.print("
"); +client.print("
Tank 2"); client.print(TT2_AV); client.print("°C"); client.print(TT2_AV); client.print("°C"); client.print(TT2_Sp); client.print("°C"); +client.print("
"); +client.print(" "); +client.print(" "); +client.print(" "); +client.print("
"); +client.print("
Bypass
"); +client.println(""); break; } if (c == '\n') { @@ -98,6 +310,8 @@ void WebServer(){ delay(1); // Verbindung schliessen client.stop(); + //clearing string for next read + readString=""; Serial.println("Verbindung mit Client beendet."); Serial.println(""); } diff --git a/serial.txt b/serial.txt new file mode 100644 index 0000000..e69de29