/* PROGRAMMINFO Funktion: ESP32 WEB Server zur Servo-Steuerung Version: 28.02.2021 (x) C++ Arduino IDE V1.8.13 Board: ESP36 Dev Module Einstellungen: https://dl.espressif.com/dl/package_esp32_index.json http://dan.drown.org/stm32duino/package_STM32duino_index.json https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json Librarys - WiFi.h V0.16.1 - Servo https://github.com/RoboticsBrno/ServoESP32 servoPin = 13; *********/ #include #include Servo myservo; static const int servoPin = 13; //PASSWORT: const char* ssid = "xxx"; const char* password = "xxx"; WiFiServer server(80); String header; String valueString = String(5); int pos1 = 0; int pos2 = 0; unsigned long currentTime = millis(); unsigned long previousTime = 0; // 2000ms = 2s) const long timeoutTime = 2000; void setup() { Serial.begin(115200); myservo.attach(servoPin); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void loop(){ WiFiClient client = server.available(); if (client) { currentTime = millis(); previousTime = currentTime; Serial.println("New Client."); String currentLine = ""; while (client.connected() && currentTime - previousTime <= timeoutTime) { currentTime = millis(); if (client.available()) { char c = client.read(); Serial.write(c); header += c; if (c == '\n') { if (currentLine.length() == 0) { e: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); // HTML 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(""); client.println(""); // Web Page client.println("

ESP32 Servo-Steuerung

"); client.println("

Position:

"); client.println(""); client.println(""); client.println(""); if(header.indexOf("GET /?value=")>=0) { pos1 = header.indexOf('='); pos2 = header.indexOf('&'); valueString = header.substring(pos1+1, pos2); myservo.write(valueString.toInt()); Serial.println(valueString); } 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 } } } header = ""; client.stop(); Serial.println("Client disconnected."); Serial.println(""); } }