0% encontró este documento útil (0 votos)
12 vistas13 páginas

Micro2 Informe#8

Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
12 vistas13 páginas

Micro2 Informe#8

Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 13

INSTITUTO TECNOLÓGICO INDUSTRIAL COMERCIAL

“PUERTO DE MEJILLONES”
CARRERA DE ELECTRÓNICA
MICRO CONTROLADOR II

PRACTICA #8
ESP_WIFI_SERV_AP

DOCENTE: Ing. Erick Benitez Gareca


ESTUDIANTE: Jose Antonio Cossio Nogales
NIVEL: 500

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

// datos de configuracion como AP


const char* ssidAP = "piopio";
const char* paswdAP = "crocante";

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);

// Connect to Wi-Fi network with SSID and password


delay(500);
Serial.println("Configurando AP (Access Point) . . . ");
WiFi.softAP(ssidAP,paswdAP);

// 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();

// turns the GPIOs on and off


if (header.indexOf("GET /L1/on") >= 0)
{
Serial.println("LED1 on");
LED1 = "on";
digitalWrite(L1,HIGH);
}
else if (header.indexOf("GET /L1/off") >= 0)
{
Serial.println("LED1 off");
LED1 = "off";
digitalWrite(L1, LOW);
}
else if (header.indexOf("GET /L2/on") >= 0)
{
Serial.println("LED2 on");
LED2 = "on";
digitalWrite(L2, HIGH);
}
else if (header.indexOf("GET /L2/off") >= 0) {
Serial.println("LED2 off");
LED2 = "off";
digitalWrite(L2,LOW);
}
else if (header.indexOf("GET /L3/on") >= 0)
{
Serial.println("LED3 on");
LED3 = "on";
digitalWrite(L3, HIGH);
}
else if (header.indexOf("GET /L3/off") >= 0) {
Serial.println("LED3 off");
LED3 = "off";
digitalWrite(L3,LOW);
}
else if (header.indexOf("GET /L4/on") >= 0)
{
Serial.println("LED4 on");
LED4 = "on";
digitalWrite(L4, HIGH);
}
else if (header.indexOf("GET /L4/off") >= 0) {
Serial.println("LED4 off");
LED4 = "off";
digitalWrite(L4,LOW);
}
else if (header.indexOf("GET /L5/on") >= 0)
{
Serial.println("LED5 on");
LED5 = "on";
digitalWrite(L5, HIGH);
}
else if (header.indexOf("GET /L5/off") >= 0) {
Serial.println("LED5 off");
LED5 = "off";
digitalWrite(L5,LOW);
}
else if (header.indexOf("GET /L6/on") >= 0)
{
Serial.println("LED6 on");
LED6 = "on";
digitalWrite(L6, HIGH);
}
else if (header.indexOf("GET /L6/off") >= 0) {
Serial.println("LED6 off");
LED6 = "off";
digitalWrite(L6,LOW);
}
else if (header.indexOf("GET /L7/on") >= 0)
{
Serial.println("LED7 on");
LED7 = "on";
digitalWrite(L7, HIGH);
}
else if (header.indexOf("GET /L7/off") >= 0) {
Serial.println("LED7 off");
LED7 = "off";
digitalWrite(L7,LOW);
}

// Display the HTML web page


client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\"
content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size
attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display:
inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #4CAF50; border:
none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin:
2px; cursor: pointer;}");
client.println(".button2 {background-color:
#555555;}</style></head>");

// Web Page Heading


client.println("<body><h1>servidor web MIC II - 2024</h1>");

client.println("<p>led1 - Estado " + LED1 + "</p>");


if (LED1=="off")
{
client.println("<p><a href=\"/L1/on\"><button
class=\"button\">ON</button></a></p>");
}
else
{
client.println("<p><a href=\"/L1/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("<p>;led2 - Estado " + LED2 + "</p>");


if (LED2=="off") {
client.println("<p><a href=\"/L2/on\"><button
class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/L2/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("<p>led3 - Estado " + LED3 + "</p>");


if (LED3=="off") {
client.println("<p><a href=\"/L3/on\"><button
class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/L3/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("<p>led4 - Estado " + LED4 + "</p>");


if (LED4=="off")
{
client.println("<p><a href=\"/L4/on\"><button
class=\"button\">ON</button></a></p>");
}
else
{
client.println("<p><a href=\"/L4/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("<p>led5 - Estado " + LED5 + "</p>");


if (LED5=="off")
{
client.println("<p><a href=\"/L5/on\"><button
class=\"button\">ON</button></a></p>");
}
else
{
client.println("<p><a href=\"/L5/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("<p>led6 - Estado " + LED6 + "</p>");


if (LED6=="off")
{
client.println("<p><a href=\"/L6/on\"><button
class=\"button\">ON</button></a></p>");
}
else
{
client.println("<p><a href=\"/L6/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("<p>led7 - Estado " + LED7 + "</p>");


if (LED7=="off")
{
client.println("<p><a href=\"/L7/on\"><button
class=\"button\">ON</button></a></p>");
}
else
{
client.println("<p><a href=\"/L7/off\"><button class=\"button
button2\">OFF</button></a></p>");
}

client.println("</body></html>");

// 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
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}

Configurando AP (Access Point) . . .


el IP del AP es: 192.168.4.1 >>>>>>><<<<<<<
Iniciado el servidor WEB CENTINEL
IMPLEMENTACION
CONCLUSIONES

También podría gustarte