start:arduino:esp32:temperature
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:esp32:temperature [2021/03/16 11:30] – [Branchement] gerardadmin | start:arduino:esp32:temperature [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 23: | Ligne 23: | ||
| - | ==== Test en Reel sur carte ESP32 ==== | + | ==== Test en réel sur carte ESP32 ==== |
| + | |||
| + | |||
| + | === Matériel === | ||
| + | |||
| + | |||
| + | **ESP32 TTGO LORA 32 V2.0** | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | ** DHT 22 ** | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| - | === Materiel === | ||
| === Branchement === | === Branchement === | ||
| + | |||
| + | ESP32 Lora32 V2 + DHT22 | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | === Librairies à installer=== | ||
| + | |||
| + | ** DHT ** | ||
| + | [[https:// | ||
| + | |||
| + | |||
| + | **ESPAsyncWebServer** | ||
| + | [[https:// | ||
| + | |||
| + | **AsyncTCP** | ||
| + | [[https:// | ||
| + | |||
| + | **Adafruit_Sensor** | ||
| + | [[https:// | ||
| + | |||
| + | |||
| + | |||
| === Programmes === | === Programmes === | ||
| + | <code c ESP32_Temperature_serveur_Web.ino> | ||
| + | /********* | ||
| + | Rui Santos | ||
| + | Complete project details at https:// | ||
| + | *********/ | ||
| - | ==== Broches | + | // Import required libraries |
| + | #include " | ||
| + | #include " | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Replace with your network credentials | ||
| + | const char* ssid = " | ||
| + | const char* password | ||
| + | |||
| + | #define DHTPIN 13 // Digital pin connected to the DHT sensor | ||
| + | |||
| + | // Uncomment the type of sensor in use: | ||
| + | //#define DHTTYPE | ||
| + | #define DHTTYPE | ||
| + | //#define DHTTYPE | ||
| + | |||
| + | DHT dht(DHTPIN, DHTTYPE); | ||
| + | |||
| + | // Create AsyncWebServer object on port 80 | ||
| + | AsyncWebServer server(80); | ||
| + | |||
| + | String readDHTTemperature() { | ||
| + | // Sensor readings may also be up to 2 seconds ' | ||
| + | // Read temperature as Celsius (the default) | ||
| + | float t = dht.readTemperature(); | ||
| + | // Read temperature as Fahrenheit (isFahrenheit | ||
| + | //float t = dht.readTemperature(true); | ||
| + | // Check if any reads failed and exit early (to try again). | ||
| + | if (isnan(t)) { | ||
| + | Serial.println(" | ||
| + | return " | ||
| + | } | ||
| + | else { | ||
| + | Serial.println(t); | ||
| + | return String(t); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | String readDHTHumidity() { | ||
| + | // Sensor readings may also be up to 2 seconds ' | ||
| + | float h = dht.readHumidity(); | ||
| + | if (isnan(h)) { | ||
| + | Serial.println(" | ||
| + | return " | ||
| + | } | ||
| + | else { | ||
| + | Serial.println(h); | ||
| + | return String(h); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | const char index_html[] PROGMEM = R" | ||
| + | < | ||
| + | < | ||
| + | <meta name=" | ||
| + | <link rel=" | ||
| + | < | ||
| + | html { | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | h2 { font-size: 3.0rem; } | ||
| + | p { font-size: 3.0rem; } | ||
| + | .units { font-size: 1.2rem; } | ||
| + | .dht-labels{ | ||
| + | font-size: 1.5rem; | ||
| + | vertical-align: | ||
| + | padding-bottom: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <h2>ESP32 Serveur DHT 22</ | ||
| + | <p> | ||
| + | <i class=" | ||
| + | <span class=" | ||
| + | <span id=" | ||
| + | <sup class=" | ||
| + | </ | ||
| + | <p> | ||
| + | <i class=" | ||
| + | <span class=" | ||
| + | <span id=" | ||
| + | <sup class=" | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | setInterval(function ( ) { | ||
| + | var xhttp = new XMLHttpRequest(); | ||
| + | xhttp.onreadystatechange = function() { | ||
| + | if (this.readyState == 4 && this.status == 200) { | ||
| + | document.getElementById(" | ||
| + | } | ||
| + | }; | ||
| + | xhttp.open(" | ||
| + | xhttp.send(); | ||
| + | }, 10000 ) ; | ||
| + | |||
| + | setInterval(function ( ) { | ||
| + | var xhttp = new XMLHttpRequest(); | ||
| + | xhttp.onreadystatechange = function() { | ||
| + | if (this.readyState == 4 && this.status == 200) { | ||
| + | document.getElementById(" | ||
| + | } | ||
| + | }; | ||
| + | xhttp.open(" | ||
| + | xhttp.send(); | ||
| + | }, 10000 ) ; | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | // Replaces placeholder with DHT values | ||
| + | String processor(const String& var){ | ||
| + | // | ||
| + | if(var == " | ||
| + | return readDHTTemperature(); | ||
| + | } | ||
| + | else if(var == " | ||
| + | return readDHTHumidity(); | ||
| + | } | ||
| + | return String(); | ||
| + | } | ||
| + | |||
| + | void setup(){ | ||
| + | // Serial port for debugging purposes | ||
| + | Serial.begin(115200); | ||
| + | |||
| + | dht.begin(); | ||
| + | |||
| + | // Connect to Wi-Fi | ||
| + | WiFi.begin(ssid, | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(1000); | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | // Print ESP32 Local IP Address | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | |||
| + | // Route for root / web page | ||
| + | server.on("/", | ||
| + | request-> | ||
| + | }); | ||
| + | server.on("/ | ||
| + | request-> | ||
| + | }); | ||
| + | server.on("/ | ||
| + | request-> | ||
| + | }); | ||
| + | |||
| + | // Start server | ||
| + | server.begin(); | ||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | === Ecran serveur web === | ||
| + | |||
| + | {{ : | ||
| - | **ESP32 TTGO LORA 32 V2.0** | ||
| - | {{ : | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/temperature.1615890656.txt.gz · Dernière modification : (modification externe)
