#include #include #define motorInterfaceType 1 const int dirPin1 = 22; const int stepPin1 = 23; const int stepSpeed = 1700; const int stepsPerRevolution = 200; AccelStepper myStepper1(motorInterfaceType, stepPin1, dirPin1); const char* ssid = "ENV_WIFI"; const char* password = "ENV_PASS"; WiFiServer server(80); String header; String valueString = String(5); int pos1 = 0; int pos2 = 0; unsigned long currentTime = millis(); unsigned long previousTime = 0; const long timeoutTime = 2000; void setup() { Serial.begin(115200); 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) { client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println("

Stepper Test

"); client.println("

Stepper 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); myStepper1.setMaxSpeed(1000); myStepper1.setAcceleration(50); myStepper1.setSpeed(200); myStepper1.moveTo(valueString.toInt()); myStepper1.runToPosition(); } client.println(); break; } else { currentLine = ""; } } else if (c != '\r') { currentLine += c; } } } header = ""; client.stop(); Serial.println("Client disconnected."); Serial.println(""); } }