/********* verändert an eigene Wuensche DL1YAR im Oktober 2020 angepasst an ESP-01 vier einzelne Antenne schaltbar klappt auf dem Steckbrett startet zur Zeit immer mit der vierten Antenne warum ?? blaue LED = 1.0 Board!!!!!!!!!!!!!!!!!!!! Funktioniert!!!!!!!!!! 12.02.2021 *********/ #include // Load Wi-Fi library /* // Replace with your network credentials const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; */ #include"persoenlichShack.h" // Zeile auskommentieren Netzwerdaten int OFF = 0; int ON = 1; // 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 DummyState = "OFF"; String RelaisState = "OFF"; //****** // Assign output variables to GPIO pins //const int Dummy = 0; //const int Relais = 2; const int Dummy = 2; const int Relais = 0; // Current time unsigned long currentTime = millis(); // Previous time unsigned long previousTime = 0; // Define timeout time in milliseconds (example: 2000ms = 2s) const long timeoutTime = 2000; void setup() { Serial.begin(9600); // Initialize the output variables as outputs und LOW setzen pinMode(Dummy, OUTPUT); pinMode(Relais, OUTPUT); digitalWrite(Dummy, OFF); digitalWrite(Relais, OFF); //pinMode(BUILTIN_LED, OUTPUT); // LED festlegen //digitalWrite(BUILTIN_LED, ON); // ausschalten (LED ist an bei 0) // Connect to Wi-Fi network with SSID and password Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // Print local IP address and start web server Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); DummyState = "ON"; RelaisState = "ON"; //########################### } 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 currentTime = millis(); previousTime = currentTime; while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected currentTime = millis(); 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 (currentLine.length() == 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); if (header.indexOf("GET /2/ON") >= 0) { // DummyState = "OFF"; // digitalWrite(Dummy, OFF); RelaisState = "ON"; digitalWrite(Relais, ON);//+++Relais zieht an delay(999); digitalWrite(Relais, OFF);//+++Relais zieht an digitalWrite(Dummy, ON); //########################### // DummyState = "ON"; // delay(999); } else if (header.indexOf("GET /2/OFF") >= 0) { RelaisState = "OFF"; digitalWrite(Relais, OFF); Serial.println("gpio2 on"); delay(10); RelaisState = "ON"; digitalWrite(Relais, ON); delay(999); digitalWrite(Relais, OFF);//+++Relais zieht an //digitalWrite(Dummy, ON); //########################### } // Display the HTML web page client.println(""); client.println(""); client.println(""); client.println(""); //rot **** // Web Page Heading client.println("

Tortaster

"); client.println("

gpio2 - Tor " + RelaisState + "

"); if (RelaisState=="OFF") { //########################### // if (RelaisState=="on") { client.println("

"); } else { client.println("

"); } // The HTTP response ends with another blank line client.println(); 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(""); } }