#include "WiFi.h"
#include <WebServer.h>
#include <DHT.h>
const char ssid[]="ESP32";
const char pass[]="12345678";
IPAddress ip(192,168,7,1);
IPAddress sn(255,255,255,0);
IPAddress gw(192,168,7,1);
WebServer servidor;
DHT dht27(27,DHT11);
void servidor_on__NOTFOUND__(){
servidor.send(200,String("text/html"),String("Código no válido"));
}
void servidor_on_(){
servidor.send(200,String("text/html"),String("<!DOCTYPE html><HTML><HEAD>")
+String("<META ")
+String("charset=\"utf-8\"")
+String(" >")
+String("<STYLE>")
+String("h2 { color:red; text-align:center; }")
+String("</STYLE>")
+String("<TITLE>")
+String("DHT-11")
+String("</TITLE>")
+String("</HEAD><BODY>")
+String("<H2>")
+String("Temperatura: ")
+String("</H2>")
+String("<H2>")
+dht27.readTemperature()
+String("</H2>")
+String("<HR>")
+String("<H2>")
+String("Humedad: ")
+String("</H2>")
+String("<H2>")
+dht27.readHumidity()
+String("</H2>")
+String("</BODY></HTML>"));
}
void setup()
{
pinMode(27, INPUT);
dht27.begin();
WiFi.softAP(ssid, pass);
WiFi.softAPConfig(ip, gw, sn);
delay(100);
servidor.begin(80);
servidor.onNotFound(servidor_on__NOTFOUND__);
servidor.on("/",HTTP_GET,servidor_on_);
}
void loop(){
yield();
servidor.handleClient();
}