Criar um servidor WEB no ESP8266 dentro de um AP
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "Radiola";
const char* password = "";
ESP8266WebServer server(80);
void getsenha() {
String pagina1 = "<html><head><title>Radiola</title>";
pagina1 += "<meta http-equiv=Content-Type ='text / html'; charset = 'utf - 8'></head>";
pagina1 += "<body bgcolor='Aqua'>";
pagina1 += "<form action='/putsenha' method='post' enctype='text/plain' id='liga'>";
pagina1 += "<h1><label for='rede'>Nome da rede:</label>";
pagina1 += "<input type='text' id='rede' style='font-size:36px'/>";
pagina1 += "<br><label for='senha'>Senha Rede: </label>";
pagina1 += "<input type='text' id='senha' style='font-size:36px'/>";
pagina1 += "<br><button type='submit'><h1>Conectar</h1>";
pagina1 += "</button ></form ></body ></html>";
server.send(200, "text/html", pagina1);
}
void putsenha() {
String pagina2 = "<html><head><title>Radiola</title>";
pagina2 += "<meta http-equiv=Content-Type ='text / html'; charset = 'utf - 8'></head>";
pagina2 += "<body bgcolor='Aqua'>";
pagina2 += "<form action='/getsenha' method='post' enctype='text/plain' id='liga'>";
pagina2 += "<h1><label for='rede'>Nome da rede:</label>";
pagina2 += "<input type='text' id='rede' style='font-size:36px'/>";
pagina2 += "<br><label for='senha'>Senha Rede: </label>";
pagina2 += "<input type='text' id='senha' style='font-size:36px'/>";
pagina2 += "<br><button type='submit'><h1>Conectar</h1>";
pagina2 += "</button ></form ></body ></html>";
server.send(200, "text/html", pagina2);
}
//===============================================================
// SETUP
//===============================================================
void setup(void) {
Serial.begin(1000);
Serial.println("inicio...");
WiFi.mode(WIFI_AP); //Only Access point
WiFi.softAP(ssid, password); //Start HOTspot removing password will disable security
IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");
Serial.println(myIP);
server.on("/",getsenha);
server.on("/",putsenha);
server.begin(); //Start server
Serial.println("HTTP server started");
}
//===============================================================
// LOOP
//===============================================================
void loop(void) {
server.handleClient(); //Handle client requests
}
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "Radiola";
const char* password = "";
ESP8266WebServer server(80);
void getsenha() {
String pagina1 = "<html><head><title>Radiola</title>";
pagina1 += "<meta http-equiv=Content-Type ='text / html'; charset = 'utf - 8'></head>";
pagina1 += "<body bgcolor='Aqua'>";
pagina1 += "<form action='/putsenha' method='post' enctype='text/plain' id='liga'>";
pagina1 += "<h1><label for='rede'>Nome da rede:</label>";
pagina1 += "<input type='text' id='rede' style='font-size:36px'/>";
pagina1 += "<br><label for='senha'>Senha Rede: </label>";
pagina1 += "<input type='text' id='senha' style='font-size:36px'/>";
pagina1 += "<br><button type='submit'><h1>Conectar</h1>";
pagina1 += "</button ></form ></body ></html>";
server.send(200, "text/html", pagina1);
}
void putsenha() {
String pagina2 = "<html><head><title>Radiola</title>";
pagina2 += "<meta http-equiv=Content-Type ='text / html'; charset = 'utf - 8'></head>";
pagina2 += "<body bgcolor='Aqua'>";
pagina2 += "<form action='/getsenha' method='post' enctype='text/plain' id='liga'>";
pagina2 += "<h1><label for='rede'>Nome da rede:</label>";
pagina2 += "<input type='text' id='rede' style='font-size:36px'/>";
pagina2 += "<br><label for='senha'>Senha Rede: </label>";
pagina2 += "<input type='text' id='senha' style='font-size:36px'/>";
pagina2 += "<br><button type='submit'><h1>Conectar</h1>";
pagina2 += "</button ></form ></body ></html>";
server.send(200, "text/html", pagina2);
}
//===============================================================
// SETUP
//===============================================================
void setup(void) {
Serial.begin(1000);
Serial.println("inicio...");
WiFi.mode(WIFI_AP); //Only Access point
WiFi.softAP(ssid, password); //Start HOTspot removing password will disable security
IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");
Serial.println(myIP);
server.on("/",getsenha);
server.on("/",putsenha);
server.begin(); //Start server
Serial.println("HTTP server started");
}
//===============================================================
// LOOP
//===============================================================
void loop(void) {
server.handleClient(); //Handle client requests
}
Comentários
Postar um comentário