#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <uri/UriBraces.h>
#include <uri/UriRegex.h>
#ifndef STASSID
#define STASSID “"
#define STAPSK "”
#endif
const char *ssid = STASSID;
const char *password = STAPSK;
ESP8266WebServer server(80);
void setup(void) {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin(“esp8266”)) {
Serial.println(“MDNS responder started”);
}
server.on(F("/"), {
server.send(200, “text/html”,F(String html =" Ventilador body { text-align: center; padding-top: 30px; }
Selecione a velocidade
0 %
";));
});
server.on(UriBraces("/change/([0-9]+)"), {
int perc = server.pathArg(0).toInt();
if(perc > 100) perc = 100;
if (perc < 0) perc = 0;
int pwm = (255/100)*perc;
Serial.println(pwm);
server.send(200, “text/plain”, “OK”);
});
server.on(UriRegex("^\/users\/([0-9]+)\/devices\/([0-9]+)$"), {
String user = server.pathArg(0);
String device = server.pathArg(1);
server.send(200, “text/plain”, “User: '” + user + “’ and Device: '” + device + “’”);
});
server.begin();
Serial.println(“HTTP server started”);
}
void loop(void) {
server.handleClient();
}