Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- #include <AccelStepper.h>
- const int motorPin1 = 2; // Sonstwas Blue - In 1
- const int motorPin2 = 0; // Pink - In 2
- const int motorPin3 = 4; // Yellow - In 3
- const int motorPin4 = 5; // Orange - In 4
- AccelStepper stepper(AccelStepper::FULL4WIRE, motorPin1, motorPin3, motorPin2, motorPin4);
- const char* ssid = "xxx";
- const char* password = "yyy";
- HTTPClient http;
- WiFiServer server(80);
- void setup() {
- Serial.begin(9600);
- pinMode(motorPin1, OUTPUT);
- pinMode(motorPin2, OUTPUT);
- pinMode(motorPin3, OUTPUT);
- pinMode(motorPin4, OUTPUT);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- Serial.print("Connecting");
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println();
- Serial.print("Connected, IP address: ");
- Serial.println(WiFi.localIP());
- if (WiFi.waitForConnectResult() != WL_CONNECTED) {
- Serial.printf("WiFi Failed!\n");
- return;
- }
- Serial.print("IP Address: ");
- Serial.println(WiFi.localIP());
- Serial.print("Hostname: ");
- Serial.println(WiFi.hostname());
- server.begin();
- Serial.println("Server started");
- stepper.setCurrentPosition(0);
- stepper.setMaxSpeed(800);
- stepper.setSpeed(10);
- stepper.setAcceleration(150);
- }
- void loop() {
- if (stepper.distanceToGo() != 0)
- {
- stepper.run();
- }
- WiFiClient client = server.available();
- if (!client) {
- return;
- }
- String request = client.readStringUntil('\r');
- client.flush();
- if (request.indexOf("/TUER=ZU") != -1) {
- Serial.println("Schliesse Tuer.");
- stepper.stop();
- stepper.move(0);
- stepper.setCurrentPosition(0);
- stepper.moveTo(-40000);
- }
- if (request.indexOf("/TUER=AUF") != -1) {
- Serial.println("Oeffne Tuer.");
- stepper.stop();
- stepper.move(0);
- stepper.setCurrentPosition(0);
- stepper.moveTo(40000);
- }
- if (request.indexOf("/TUER=STOP") != -1) {
- Serial.println("STOPP Tuer.");
- stepper.stop();
- stepper.move(0);
- stepper.setCurrentPosition(0);
- }
- // Return the response
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println(""); // do not forget this one
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<br><br>");
- client.println("Click <a href=\"/TUER=ZU\">here</a> Huehnertuer schliessen<br>");
- client.println("Click <a href=\"/TUER=AUF\">here</a> Huehnertur oeffnen<br>");
- client.println("Click <a href=\"/TUER=STOP\">here</a> Huehnertur anhalten<br>");
- client.println("</html>");
- Serial.println("Client disconnected");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement