DPRE - APP Inventor - Control temperatura
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
#include <ESP8266WebServer.h> | |
#include "DHT.h" | |
#define DHTPIN 4 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
const char* ssid = "RED"; | |
const char* password = "CLAVE"; | |
ESP8266WebServer servidor(80); | |
void setup() { | |
Serial.begin(9600); | |
dht.begin(); | |
WiFi.begin(ssid,password); | |
Serial.print("Conectando"); | |
while(WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(100); | |
} | |
Serial.println("Conectado"); | |
Serial.print("Direccion IP: "); | |
Serial.println(WiFi.localIP()); | |
servidor.on("/temperatura", temperatura); | |
servidor.on("/humedad", humedad); | |
servidor.begin(); | |
} | |
void temperatura() { | |
float t = dht.readTemperature(); | |
String respuesta = ""; | |
if (isnan(t)) { | |
Serial.println("Error al leer datos del sensor"); | |
respuesta += "Error"; | |
} else { | |
respuesta = String(t); | |
Serial.println(respuesta); | |
} | |
servidor.send(200, "text/plain", respuesta); | |
} | |
void humedad() { | |
float h = dht.readHumidity(); | |
String respuesta = ""; | |
if (isnan(h)) { | |
Serial.println("Error al leer datos del sensor"); | |
respuesta += "Error"; | |
} else { | |
respuesta = String(h); | |
Serial.println(respuesta); | |
} | |
servidor.send(200, "text/plain", respuesta); | |
} | |
void loop() { | |
servidor.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment