Cov txheej txheem:

ESP8266 Nodemcu Kev Ntsuas Kub Siv DHT11 ntawm Lub Vev Xaib Hauv Zos - Tau Chav Kub & Vaum ntawm Koj Tus Kheej: 6 Kauj Ruam
ESP8266 Nodemcu Kev Ntsuas Kub Siv DHT11 ntawm Lub Vev Xaib Hauv Zos - Tau Chav Kub & Vaum ntawm Koj Tus Kheej: 6 Kauj Ruam

Video: ESP8266 Nodemcu Kev Ntsuas Kub Siv DHT11 ntawm Lub Vev Xaib Hauv Zos - Tau Chav Kub & Vaum ntawm Koj Tus Kheej: 6 Kauj Ruam

Video: ESP8266 Nodemcu Kev Ntsuas Kub Siv DHT11 ntawm Lub Vev Xaib Hauv Zos - Tau Chav Kub & Vaum ntawm Koj Tus Kheej: 6 Kauj Ruam
Video: Получаем данные из интернета. ESP8266 или NodeMCU V3 2024, Hlis ntuj nqeg
Anonim
ESP8266 Nodemcu Kev Ntsuas Kub Siv DHT11 ntawm Lub Vev Xaib Hauv Zos | Tau Txais Chav Kub & Vaum ntawm Koj Tus browser
ESP8266 Nodemcu Kev Ntsuas Kub Siv DHT11 ntawm Lub Vev Xaib Hauv Zos | Tau Txais Chav Kub & Vaum ntawm Koj Tus browser

Nyob zoo cov menyuam hnub no peb yuav ua qhov ntsuas qhov ntsuas kub thiab txias siv ESP 8266 NODEMCU & DHT11 ntsuas kub. Kub thiab av noo yuav tau los ntawm DHT11 Sensor & nws tuaj yeem pom ntawm qhov browser uas lub vev xaib yuav raug tswj hwm los ntawm esp 8266 los ntawm kev tuav nws ntawm lub vev xaib hauv zos.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

Koj xav tau cov khoom hauv qab no rau txoj haujlwm no: 1x ESP 8266 Nodemcu:

1x DHT11: https://www.utsource.net/itm/p/8831706.html1x breadboard:.:

Ob peb dhia:

Kauj ruam 2: Circuit Court

Circuit Court
Circuit Court

Lub Circuit Court yog qhov yooj yim heev txuas txhua yam Raws li qhia hauv schmatics

Kauj Ruam 3: Tau txais Cov Tsev Qiv Ntawv

Tau cov tsev qiv ntawv
Tau cov tsev qiv ntawv
Tau cov tsev qiv ntawv
Tau cov tsev qiv ntawv

Qhib koj Arduino IDE thiab mus rau Sketch> suav nrog Tsev Kawm Ntawv> Tswj Tsev Qiv. Tus Thawj Saib Xyuas Tsev Qiv Ntawv yuav tsum qhib. Tshawb nrhiav "DHT" ntawm lub npov Tshawb nrhiav thiab teeb tsa DHT lub tsev qiv ntawv los ntawm Adafruit. Qhib txhua txoj hauv kev kom pom lub tsev qiv ntawv thiab nruab nws Tom qab txhim kho cov tsev qiv ntawv, rov pib dua koj li Arduino IDE.

Kauj ruam 4: Code

Code
Code

Tom qab ua cov saum toj no upload cov cai hauv qab no rau ESP8266 nodemcu (thov xaiv qhov chaw nres nkoj & pawg kom raug) & ua ntej rub tawm cov cai thov tso ssid & tus password ntawm koj lub wifi hauv tus lej: // Xws li ESP8266 WiFi lub tsev qiv ntawv #suav nrog #suav nrog "DHT. h "// Tsis pom zoo ib qho ntawm kab hauv qab no rau yam DHT sensor yam koj tab tom siv!#txhais DHTTYPE DHT11 // DHT 11 //#txhais DHTTYPE DHT21 // DHT 21 (AM2301) //#txhais DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 // Hloov nrog koj cov ntsiab lus network sib txuas char* ssid = "YOUR_NETWORK_NAME"; const char* password = "YOUR_NETWORK_PASSWORD"; // Web Server ntawm chaw nres nkoj 80WiFiServer server (80); // DHT Sensorconst int DHTPin = 5; // Initialize DHT sensor. DHT dht (DHTPin, DHTTYPE); // Temporary variablesstatic char c CelsiusTemp [7]; static char fahrenheitTemp [7]; zoo li qub char humidityTemp [7]; // tsuas yog khiav ib zaug ntawm kev teeb tsa bootvoid () { // Initializing serial chaw nres nkoj rau debugging lub hom phiaj Serial.begin (115200); ncua (10); dht.begin (); // Txuas rau WiFi network Serial.println (); Serial.print ("Txuas rau"); Serial.println (ssid); WiFi.begin (ssid, password); thaum (WiFi.status ()! = WL_CONNECTED) {ncua (500); Serial.print ("."); } Serial.println (""); Serial.println ("Txuas nrog WiFi"); // Pib lub web server server.begin (); Serial.println ("Web server khiav. Tos rau ESP IP …"); ncua (10000); // Luam tawm ESP IP chaw nyob Serial.println (WiFi.localIP ());} // sau ntau thiab ntau dua tsis muaj lub voj () {// Mloog rau cov neeg siv tshiab WiFiClient tus neeg siv = server.available (); yog (tus neeg siv khoom) {Serial.println ("Tus neeg siv khoom tshiab"); // bolean mus nrhiav thaum http thov xaus boolean blank_line = tseeb; thaum (client.connected ()) {yog (client.available ()) {char c = client.read (); yog (c == '\ n' && blank_line) {// Sensor nyeem ntawv kuj tseem tuaj yeem ntev txog 2 vib nas this 'qub' (nws lub sensor qeeb heev) ntab h = dht.readHumidity (); // Nyeem kub li Celsius (lub neej ntawd) ntab t = dht.readTemperature (); // Nyeem kub li Fahrenheit (isFahrenheit = true) ntab f = dht.readTemperature (tseeb); // Txheeb xyuas yog tias ib qho twg nyeem tsis tau zoo thiab tawm ntxov (sim dua). yog (isnan (h) || isnan (t) || isnan (f)) {Serial.println ("Ua tsis tau tejyam nyeem los ntawm DHT sensor!"); strcpy (c CelsiusTemp, "Ua tsis tau tejyam"); strcpy (fahrenheitTemp, "Ua tsis tau"); strcpy (humidityTemp, "Ua tsis tau tej yam"); } lwm qhov {// Suav qhov ntsuas kub hauv Celsius + Fahrenheit thiab Vaum ntab hic = dht.computeHeatIndex (t, h, cuav); dtostrf (hic, 6, 2, c CelsiusTemp); ntab hif = dht.computeHeatIndex (f, h); dtostrf (hif, 6, 2, fahrenheitTemp); dtostrf (h, 6, 2, humidityTemp); // Koj tuaj yeem tshem tawm cov Serial.print's hauv qab no, nws tsuas yog siv rau lub hom phiaj debugging Serial.print ("Vaum:"); Serial.print (h); Serial.print (" %\ t Kub:"); Serial.print (t); Serial.print (" *C"); Serial.print (f); Serial.print (" *F / t Kub ntsuas:"); Serial.print (hic); Serial.print (" *C"); Serial.print (hif); Serial.print (" *F"); Serial.print ("Vaum:"); Serial.print (h); Serial.print (" %\ t Kub:"); Serial.print (t); Serial.print (" *C"); Serial.print (f); Serial.print (" *F / t Kub ntsuas:"); Serial.print (hic); Serial.print (" *C"); Serial.print (hif); Serial.println (" *F"); } client.println ("HTTP/1.1 200 OK"); client.println ("Cov ntsiab lus-Hom: ntawv/html"); client.println ("Kev sib txuas: kaw"); client.println (); cov. // koj lub vev xaib tiag uas qhia txog qhov kub thiab txias cov neeg siv khoom

Kauj ruam 5: Tau tus IP

Tau tus IP
Tau tus IP

Koj saib qhov ntsuas kub & av noo peb xav tau kom tau IP ntawm nplooj ntawv webpage. Yog li rau qhov ntawd kom ntseeg tau tias koj tus esp8266 txuas nrog koj lub PC thiab tom qab ntawd qhib lub vijtsam saib thiab ntawm lub vijtsam saib koj tuaj yeem pom tus IP ntawm koj ESP8266 webserver webpage.

Kauj Ruam 6: Txheeb Xyuas Koj Qhov Kub & Vaum ntawm Browser

Txheeb Koj Qhov Kub & Vaum ntawm Browser
Txheeb Koj Qhov Kub & Vaum ntawm Browser

Yog li tom qab tau txais IP ntawm koj ESP8266 nodemcu, tsuas yog qhib browser hauv PC lossis Txawb tab sis xyuas kom tseeb tias koj lub PC/mobile tau txuas nrog tib lub network zoo li koj Nodemcu/ESP8266 thiab tom qab ntawd mus rau koj tus browser (yog tias koj siv mobile thov siv browser ua ntej piv txwv li rau Android siv chrome) thiab tom qab ntawd ntaus tus IP peb tau txais hauv cov kauj ruam dhau los thiab lub vev xaib hauv cheeb tsam yuav b tso tawm nrog cov av noo & kub raws li kuv tau qhia hauv duab.

Pom zoo: