• Post category:Wemos D1 mini ESP8266
  • Commentaires de la publication :1 commentaire
  • Dernière modification de la publication :mars 12, 2022
  • Temps de lecture :5 min de lecture

Affichage valeurs DHT11 DHT22 avec Wemos D1 mini ESP8266 sur une paje Web *

 

 

    Prérequis :

Matériel :

  • 1 x Carte Wemos D1 mini ESP8266
  • 1 x Résistance 4.7 KΩ
  • 1 x DHT11
  • Fils de connexion
  • 1 x Breadboard

Version IDE :

Bibliothèque :

  • ESP8266WiFi.h
  • ESP8266WebServer.h
  • DHT.h

 

 

Vidéo de démonstration :

 

Schéma de câblage :

 

Code :

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include "DHT.h"

// Selectionner le capteur utilisé
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

/*Vous devez modifier les deux variables suivantes avec vos informations d'identification réseau*/
const char* ssid = "Freebox-blablabla"; // Nom de votre réseau
const char* password = "votre mdp wifi"; //Mot de pass de votre wifi

ESP8266WebServer server(80);

// DHT Sensor
uint8_t DHTPin = 2;

// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);

float t;
float h;

void setup() {
Serial.begin(115200);
delay(100);

pinMode(DHTPin, INPUT);

dht.begin();

Serial.println("Connecting to ");
Serial.println(ssid);

//connection à votre réseau wi-fi local
WiFi.begin(ssid, password);

//vérifie que le wi-fi est connecté au réseau wi-fi
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: "); Serial.println(WiFi.localIP());

server.on("/", handle_OnConnect);
server.onNotFound(handle_NotFound);

server.begin();
Serial.println("HTTP server started");

}
void loop() {

server.handleClient();

}

void handle_OnConnect() {

t = dht.readTemperature();
h = dht.readHumidity();
server.send(200, "text/html", SendHTML(t,h));
}

void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}

String SendHTML(float Temperature,float Humidity){
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>www.robdomo.com</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<div id=\"webpage\">\n";
ptr +="<h1><p style=\"color:red;\">Ma première Station Météo</p></h1>\n";
ptr +="<p>Temperature: ";
ptr +=(int)Temperature;
ptr +="ºC</p>";
ptr +="<p>Humidity: ";
ptr +=(int)Humidity;
ptr +="%</p>";
ptr +="<h1><font color='red'>www.robdomo.com</font></h1>\n";
ptr +="</div>\n";
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
}

 


 

Cette publication a un commentaire

  1. Pascal

    Bonjour, serait il possible de mettre dans la rubrique téléchargement les deux bibliothèques concernant
    l ’ESP8266
    Merci d’avance
    Pascal

Répondre à Pascal Annuler la réponse