#include <WiFi.h>
const int stepPin = 19;
const int dirPin = 18;
const char* ssid = "CasaVerde-2.4G";
const char* password = "Casa11619@";
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
pinMode (stepPin, OUTPUT);
pinMode (dirPin, OUTPUT); // define pino 5 como saída
delay(10);
// Conectando ao WiFi
Serial.println();
Serial.println();
Serial.print("Conectando à ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
IPAddress ip(10, 0, 0, 123); // IP fixo para o ESP32
IPAddress gateway(10, 0, 0, 1); // IP do seu roteador
IPAddress subnet(255, 255, 255, 0); // máscara da sua rede
WiFi.config(ip, gateway, subnet);
Serial.println("");
Serial.println("WiFi conectado.");
Serial.println("Endereço IP: ");
Serial.println(ip);
server.begin();
}
int value = 0;
void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("New Client.");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
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();
client.println("<center>");
client.println("<br>");
client.println("<a href=\"/bot\"><button>Botão</button></a>");
client.println("<br>");
client.println("</center>");
// 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
}
if (currentLine.endsWith("GET /bot")) {
digitalWrite(dirPin, HIGH);
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
}
}
// close the connection:
client.stop();
Serial.println("Client Disconnected.");
}
delay(10);
}
}