Micro2 Informe#8
Micro2 Informe#8
“PUERTO DE MEJILLONES”
CARRERA DE ELECTRÓNICA
MICRO CONTROLADOR II
PRACTICA #8
ESP_WIFI_SERV_AP
COCHABAMBA-BOLIVIA
2024
OBJETIVO
MARCO TEORICO
El módulo ESP8266 es un puente de puerto serie a WiFi, incluye un
microcontrolador para manejar el protocolo TCP/IP y el software necesario para la
conexión 802.11, la mayoría de los modelos dispone de entradas/salidas (I/O)
digitales y algunos modelos una entrada analógica al igual que otros
microcontroladores, su punto fuerte es disponer de acceso WIFI y por su bajo precio
el chip ESP8266 parece destinado a dar un gran empujón a lo que se ha llamado
Internet de las cosas.
ESP8266 se puede programar usando el lenguaje interpretado Lua en entornos
como ESPlorer, y el IDE y lenguaje de Arduino Processing/Wiring. Es diseñado por
una compañía china llamada Espressif Systems en su sede en Shangai. Pero su
producción en masa inicio hasta principios del año 2014, donde se anunció que este
chip sería una excelente solución autómata de redes wifi que se ofrece como puente
entre los microcontroladores que hasta ahora existen o que tiene la capacidad de
ejecutar aplicaciones independientes.
Un ESP8266 salido de fábrica no sería de mucha utilidad ya que su producción está
basada en la compactación de un chip SMT (Tecnología de Montaje Superficial por
sus siglas en inglés - Surface Mount Technology) el cual viene en un pequeño
paquete de tan solo cinco milímetros cuadrados. La buena noticia es que gracias a
que diversos fabricantes que construyen placas de circuito impreso prefabricadas
adecuándolos y dejándolos listos para ser usados. Esto permite trabajar con este
dispositivo único acoplado a un microcontrolador, para desarrollar proyectos o como
sistema autónomo para ciertas aplicaciones.
DIAGRAMA CIRCUITO
CODIGO
//Servidor WEB NODEMCU - AP
#include <ESP8266WiFi.h>
//#include <WiFi.h> //esp32
#define L1 16 //GPIO16 D0
#define L2 5 //GPIO5 D1
#define L3 4 //GPIO5 D2
#define L4 0 //GPIO5 D3
#define L5 2 //GPIO5 D4
#define L6 14 //GPIO5 D5
#define L7 12 //GPIO5 D6
WiFiServer server(112);
String header;
String LED1 = "off";
String LED2 = "off";
String LED3 = "off";
String LED4 = "off";
String LED5 = "off";
String LED6 = "off";
String LED7 = "off";
void setup()
{
Serial.begin(115200);
// Initialize the output variables as outputs
pinMode(L1,OUTPUT);
pinMode(L2,OUTPUT);
pinMode(L3,OUTPUT);
pinMode(L4,OUTPUT);
pinMode(L5,OUTPUT);
pinMode(L6,OUTPUT);
pinMode(L7,OUTPUT);
// Set outputs to LOW
digitalWrite(L1,LOW);
digitalWrite(L2,LOW);
digitalWrite(L3,LOW);
digitalWrite(L4,LOW);
digitalWrite(L5,LOW);
digitalWrite(L6,LOW);
digitalWrite(L7,LOW);
// Escribir la direccion IP
IPAddress IP = WiFi.softAPIP();
Serial.print("el IP del AP es: ");
Serial.print(IP);
Serial.println(" >>>>>>><<<<<<<");
server.begin();
Serial.println("Iniciado el servidor WEB CENTINEL");
}
void loop()
{
WiFiClient client = server.available(); // Listen for incoming clients
if (client)
{ // If a new client connects,
Serial.println("NUEVO USUARIO CONECTADO"); // print a message
out in the serial port
String currentLine = ""; // make a String to hold
incoming data from the client
while (client.connected())
{ // loop while the client's connected
if (client.available())
{ // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial
monitor
header += c;
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("Connection: close");
client.println();
client.println("</body></html>");