0% found this document useful (0 votes)
86 views5 pages

Tecnologías de La Información: Alumno: José de Jesus Garcia Plascencia

This document contains code to send temperature and humidity sensor data from an ESP8266 microcontroller to a database. The code initializes the DHT11 sensor and connects the ESP8266 to a WiFi network. It then reads the sensor values, connects to the database server, and sends an HTTP GET request with the sensor values as parameters to store in the database. This is done on a loop to continuously monitor and record the sensor readings.

Uploaded by

Yisus Spec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views5 pages

Tecnologías de La Información: Alumno: José de Jesus Garcia Plascencia

This document contains code to send temperature and humidity sensor data from an ESP8266 microcontroller to a database. The code initializes the DHT11 sensor and connects the ESP8266 to a WiFi network. It then reads the sensor values, connects to the database server, and sends an HTTP GET request with the sensor values as parameters to store in the database. This is done on a loop to continuously monitor and record the sensor readings.

Uploaded by

Yisus Spec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Tecnologías de la Información

Alumno : José de Jesus Garcia Plascencia

Profesora: Andrés Ibarra

Tema : Sensor dht11 & esp8266 a Base de datos

Fecha : 19/Mayo/ 2020

Grado y grupo : 5 A
Tarea # 3

Codigo que manda los valores recibidos por el sensor DHT11 A


LA BASE DE DATOS

#include <ESP8266WiFi.h>

#include "DHT.h"

#define DHTTYPE DHT11 // DHT 11

// Sensor DHT

const int DHTPin = 5; //Comunicación de datos en el pin 5 (GPIO 5 -- D1)

// Iniciando sensor

DHT dht(DHTPin, DHTTYPE);

char* ssid = "pape2.0";

char* password = "nomelase";

char* host = "192.168.1.98";

// Iniciando sensor

void setup()

Serial.begin(9600);

Serial.println("DHT11 Output!");

dht.begin();

// We start by connecting to a WiFi network

Serial.println();
Serial.println();

Serial.print("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected");

Serial.println("IP address: ");

Serial.println(WiFi.localIP());

void loop()

float temperature = dht.readTemperature();

float humidity = dht.readHumidity();

if(isnan(temperature) || isnan(humidity)){

Serial.println("Failed to read DHT11");

}else{

Serial.print("Humidity: ");

Serial.print(humidity);

Serial.print(" %\t");

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println(" *C");
delay(3000);

Serial.print("connecting to ");

Serial.println(host);

// Use WiFiClient class to create TCP connections

WiFiClient client;

const int httpPort = 8082;

if (!client.connect(host, httpPort)) {

Serial.println("connection failed");

return;

// This will send the request to the server

client.print(String("GET http://server/dhttoDB/captura.php?") +

("&temperature=") + temperature +

("&humidity=") + humidity +

" HTTP/1.1\r\n" +

"Host: " + host + "\r\n" +

"Connection: close\r\n\r\n");

unsigned long timeout = millis();

while (client.available() == 0) {

if (millis() - timeout > 1000) {

Serial.println(">>> Client Timeout !");

client.stop();
return;

// Read all the lines of the reply from server and print them to Serial

while(client.available()) {

String line = client.readStringUntil('\r');

Serial.print(line);

Serial.println();

Serial.println("closing connection");

You might also like