Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 12, 2020 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c01c10ccb83b139eed3b6ba224ec133e to your computer and use it in GitHub Desktop.
Save parzibyte/c01c10ccb83b139eed3b6ba224ec133e to your computer and use it in GitHub Desktop.
/*
Programado por Luis Cabrera Benito
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char *NOMBRE_RED = "Parzibyte",
*CLAVE_RED = "00000000"; // Son 8 ceros
const int PUERTO = 80;
IPAddress ip(192, 168, 1, 1);
IPAddress puertaDeEnlace(192, 168, 1, 1);
IPAddress mascaraDeRed(255, 255, 255, 0);
ESP8266WebServer servidor(PUERTO);
/*
Definimos funciones que serán invocadas cuando la URL solicitada
cumpla con cierta característica
*/
void rutaRaiz()
{
const char *HtmlRespuesta = "<h1>ESP8266 como servidor web</h1>"
"<p>Podemos tener c&oacute;digo HTML</p>"
"<a href='https://parzibyte.me/blog'>By parzibyte</a>";
servidor.send(200, "text/html", HtmlRespuesta);
}
void rutaNoEncontrada()
{
servidor.send(404, "text/plain", "404");
}
void setup()
{
// Configurar como un access point
WiFi.softAP(NOMBRE_RED, CLAVE_RED);
WiFi.softAPConfig(ip, puertaDeEnlace, mascaraDeRed);
delay(100);
// Configuramos la ruta y la función que responderá a la solicitud de dicha ruta
servidor.on("/", rutaRaiz);
servidor.onNotFound(rutaNoEncontrada);
// Empezar a escuchar
servidor.begin();
}
// En el loop manejamos al cliente conectado y eso es todo ;)
void loop()
{
servidor.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment