/* Kuehlkoffer006 Ganz was neues: Die Steuer-Ausgänge mit Handy steuern */ // Load Wi-Fi library #include // Replace with your network credentials const char* ssid = "Augustiner"; const char* password = "13281328"; // Set web server port number to 80 WiFiServer server(80); // Variable to store the HTTP request String header; // Auxiliar variables to store the current output state String LuefterState = "aus"; String InnenluefterState = "aus"; String KompressorState = "aus"; String TurboState = "aus"; // Assign output variables to GPIO pins const int Luefter = 20; const int Innenluefter = 21; const int Kompressor = 1; const int Turbo = 3; void setup() { Serial.begin(115200); // Initialize the output variables as outputs pinMode(Luefter, OUTPUT); pinMode(Innenluefter, OUTPUT); pinMode(Kompressor, OUTPUT); pinMode(Turbo, OUTPUT); // Set outputs to LOW digitalWrite(Luefter, LOW); digitalWrite(Innenluefter, LOW); digitalWrite(Kompressor, LOW); digitalWrite(Turbo, LOW); // Connect to Wi-Fi network with SSID and password Serial.print("Setting AP (Access Point)…"); // Remove the password parameter, if you want the AP (Access Point) to be open WiFi.softAP(ssid, password); IPAddress IP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(IP); server.begin(); } void loop(){ WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); // turns the GPIOs on and off if (header.indexOf("GET /Luefter/on") >= 0) { Serial.println("Lüfter an"); LuefterState = "an"; digitalWrite(Luefter, HIGH); } else if (header.indexOf("GET /Luefter/off") >= 0) { Serial.println("Lüfter aus"); LuefterState = "aus"; digitalWrite(Luefter, LOW); } else if (header.indexOf("GET /Innenluefter/on") >= 0) { Serial.println("Innenlüfter an"); InnenluefterState = "an"; digitalWrite(Innenluefter, HIGH); } else if (header.indexOf("GET /Innenluefter/off") >= 0) { Serial.println("Innenlüfter aus"); InnenluefterState = "aus"; digitalWrite(Innenluefter, LOW); } else if (header.indexOf("GET /Kompressor/on") >= 0) { Serial.println("Kompressor an"); KompressorState = "an"; digitalWrite(Kompressor, HIGH); } else if (header.indexOf("GET /Kompressor/off") >= 0) { Serial.println("Kompressor aus"); KompressorState = "aus"; digitalWrite(Kompressor, LOW); } else if (header.indexOf("GET /Turbo/on") >= 0) { Serial.println("Turbo an"); TurboState = "an"; digitalWrite(Turbo, HIGH); } else if (header.indexOf("GET /Turbo/off") >= 0) { Serial.println("Turbo aus"); TurboState = "aus"; digitalWrite(Turbo, LOW); } // Display the HTML web page client.println(""); client.println(""); client.println(""); // CSS to style the on/off buttons // Feel free to change the background-color and font-size attributes to fit your preferences client.println(""); // Web Page Heading client.println("

Augustiner

"); // Display current state, and ON/OFF buttons for Luefter client.println("

Lüfter " + LuefterState + "

"); if (LuefterState=="aus") { client.println("

"); } else { client.println("

"); } // Display current state, and ON/OFF buttons for Innenluefter client.println("

Innenlüfter " + InnenluefterState + "

"); if (InnenluefterState=="aus") { client.println("

"); } else { client.println("

"); } client.println(""); // Display current state, and ON/OFF buttons for Kompressor client.println("

Kompressor " + KompressorState + "

"); if (KompressorState=="aus") { client.println("

"); } else { client.println("

"); } client.println(""); // Display current state, and ON/OFF buttons for Turbo client.println("

Turbo " + TurboState + "

"); if (TurboState=="aus") { client.println("

"); } else { client.println("

"); } client.println(""); // The HTTP response ends with another blank line client.println(); // Break out of the while loop break; } else { // if you got a newline, then clear currentLine currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } } } // Clear the header variable header = ""; // Close the connection client.stop(); Serial.println("Client disconnected."); Serial.println(""); } }