Cov txheej txheem:

ESP8266 NodeMCU Access Point (AP) rau Web Server Nrog DT11 Kub Sensor thiab Luam Ntawv Kub & Vaum Hauv Browser: 5 Kauj Ruam
ESP8266 NodeMCU Access Point (AP) rau Web Server Nrog DT11 Kub Sensor thiab Luam Ntawv Kub & Vaum Hauv Browser: 5 Kauj Ruam

Video: ESP8266 NodeMCU Access Point (AP) rau Web Server Nrog DT11 Kub Sensor thiab Luam Ntawv Kub & Vaum Hauv Browser: 5 Kauj Ruam

Video: ESP8266 NodeMCU Access Point (AP) rau Web Server Nrog DT11 Kub Sensor thiab Luam Ntawv Kub & Vaum Hauv Browser: 5 Kauj Ruam
Video: ESP8266 AJAX WebServer (Wi-FI точка доступа) 2024, Hlis ntuj nqeg
Anonim
ESP8266 NodeMCU Access Point (AP) rau Web Server Nrog DT11 Kub Sensor thiab Luam Ntawv Kub & Vaum Hauv Browser
ESP8266 NodeMCU Access Point (AP) rau Web Server Nrog DT11 Kub Sensor thiab Luam Ntawv Kub & Vaum Hauv Browser

Nyob zoo cov menyuam hauv feem ntau ntawm cov haujlwm peb siv ESP8266 thiab feem ntau ntawm cov haujlwm peb siv ESP8266 ua lub vev xaib kom cov ntaub ntawv tuaj yeem nkag tau ntawm txhua lub cuab yeej hla wifi los ntawm kev nkag mus rau Webserver hosted los ntawm ESP8266 tab sis qhov teeb meem tsuas yog peb xav tau lub router ua haujlwm rau qhov ntawd thiab peb lub cuab yeej tseem xav tau txuas nrog lub router thiab peb yuav tsum tso peb cov ntawv pov thawj wifi hauv tus lej yog li yog tias koj hloov pauv wifi ces koj yuav tsum hloov daim ntawv pov thawj hauv tus lej thiab koj yuav tsum tau rov thim nws dua.: 1- peb xav tau kev sib txuas wifi los ua tus tswv ntawm lub vev xaib (router) 2- txhua lub sijhawm yog tias kev sib txuas wifi xav tau hloov peb xav tau cov ntaub ntawv pov thawj thiab rov ua dua tus lej. wifi nkag mus peb tuaj yeem ua ESP8266 los tsim kev sib txuas wifi ntawm nws tus kheej yog li yog peb txuas mus rau qhov kev txuas wifi peb tuaj yeem nkag mus rau lub vev xaib ntawm ESP8266. Yog li ntawd, peb yuav ua tus tswv webserver nrog ESP8266 nrog kev nkag mus. Yog li hauv cov lus qhia no peb yuav tsim ib lub vev xaib siv qhov Point Access nrog ESP8266 thiab peb yuav txuas DHT11 lub ntsuas cua thiab luam tawm qhov kub thiab qhov av noo ntawm nplooj ntawv webserver.

Kauj Ruam 1: Yam Koj Xav Tau

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

1x ESP 8266 Nodemcu: 1x DHT11: 1x breadboard:.: Ob peb jumpers:

Kauj Ruam 2: Tau DHT11 Tsev Qiv Ntawv

Tau txais lub Tsev Qiv Ntawv DHT11
Tau txais lub Tsev Qiv Ntawv DHT11
Tau txais lub Tsev Qiv Ntawv DHT11
Tau txais lub Tsev Qiv Ntawv DHT11

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 3: Kev Sib Txuas

Kev sib txuas
Kev sib txuas

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

Kauj Ruam 4: Nkag Mus Rau Txoj Cai Code

Access Point Code
Access Point Code

Los ntawm kuv cov ntawv qhia yav dhau los Kuv yuav hloov kho lub vev xaib cov cai ntawm cov lus qhia no:

Thiab tig nws mus rau hauv qhov chaw nkag rau tus lej webserver. Please luam cov cai hauv qab no:

#suav nrog "Arduino.h"#suav nrog "ESP8266WiFi.h"

#suav nrog "Hash.h"

#suav nrog "ESPAsyncTCP.h"

#suav nrog "ESPAsyncWebServer.h"

#suav nrog "Adafruit_Sensor.h"

#suav nrog "DHT.h"

const char* ssid = "ESP8266"; const char* password = "password";#txhais DHTPIN 5 // Cov lej txuas nrog DHT sensor // Tsis pom zoo hom sensor siv: //#txhais DHTTYPE DHT11 // DHT 11#txhais DHTTYPE DHT22 // DHT 22 (AM2302) //#txhais DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht (DHTPIN, DHTTYPE); // tam sim no kub & av noo, hloov kho hauv voj () ntab t = 0.0; ntab h = 0.0; // Tsim cov khoom AsyncWebServer ntawm chaw nres nkoj 80AsyncWebServer server (80); // Feem ntau, koj yuav tsum siv "tsis tau kos npe ntev" rau qhov hloov pauv uas tuav lub sijhawm // Tus nqi yuav sai sai dhau los ua qhov loj rau kev nkag mus rau qhov chaw khaws cia ntev dhau los = 0; // yuav khaws zaum kawg DHT tau hloov tshiab // Hloov kho DHT nyeem txhua 10 vib nas this sib nrug ntev = 10000; const char index_html PROGMEM = R "rawliteral (ESP8266 DHT Server

Kub % TEMPERATURE % ° C

Vaum % HUMIDITY % %) rawliteral "; // Hloov chaw tso nrog DHT qhov tseem ceeb String processor (const String & var) {//Serial.println(var); if (var ==" TEMPERATURE ") {return String (t);} else if (var == "HUMIDITY") {return String (h);} return String ();} void setup () {// Serial port for debugging purpose Serial.begin (115200); dht.begin (); Serial.print ("Teeb tsa AP (Access Point)… "); // Tshem tus password tus lej, yog tias koj xav kom AP (Access Point) qhib WiFi.softAP (ssid, password); IPAddress IP = WiFi.softAPIP (); Serial.print (" AP IP chaw nyob: "); Serial.println (IP); // Sau ESP8266 Local IP Address Serial.println (WiFi.localIP ()); // Txoj hauv kev rau hauv paus / web page server.on (" / ", HTTP_GET, (AsyncWebServerRequest *thov) {thov-> xa_P (200, "ntawv/html", index_html, processor);}); server.on ("/kub", HTTP_GET, (AsyncWebServerRequest *thov) {thov- > xa_P (200, "ntawv nyeem/ntsiab lus", String (t).c_str ());}); server.on ("/humidity", HTTP_GET, (AsyncWebServerRequest *thov) {thov-> xa_P (200, "text/dawb", Txoj hlua (h).c_str ()); }); // Pib server server.begin ();} void loop () {unsigned ntev currentMillis = millis (); yog (currentMillis - previousMillis> = luv) {// txuag lub sijhawm kawg koj hloov kho DHT qhov txiaj ntsig yav dhau losMillis = currentMillis; // Nyeem kub li Celsius (lub neej ntawd) ntab newT = dht.readTemperature (); // Nyeem qhov kub raws li Fahrenheit (isFahrenheit = true) // ntab newT = dht.readTemperature (tseeb); // yog ntsuas kub tsis ua tiav, tsis txhob hloov t tus nqi yog (isnan (newT)) {Serial.println ("Ua tsis tau tejyam nyeem los ntawm DHT sensor! "); } lwm {t = newT; Serial.println (t); } // Nyeem Ntub dej ntab newH = dht.readHumidity (); // yog cov av noo nyeem tsis tau, tsis txhob hloov tus nqi h yog (isnan (newH)) {Serial.println ("Ua tsis tau zoo nyeem los ntawm DHT sensor!"); } lwm {h = newH; Serial.println (h); }}} Ua ntej koj upload cov cai kom ntseeg tau tias koj tso cov khoom hauv qab no: const char* ssid = "ESP8266"; // xijpeem ssid ntawm wifi koj xav tau char* password = "password"; // dhau mus txuas rau saum ssidSet Tus ESP8266 ua qhov Chaw Nkag Mus: Txhawm rau teeb tsa esp8266 ua qhov chaw nkag peb yuav siv softAP hais kom ua raws li qhia hauv qab no; los tsim ib qho chaw nkag. WiFi.softAP (ssid, password); Tseem muaj lwm yam kev xaiv uas koj tuaj yeem hla mus rau softAP () txoj kev. Nov yog txhua qhov ntsuas: Yog tias koj qhib lub koos pij tawj koj tuaj yeem pom tus IP ntawm qhov nkag mus. Uas ua tiav los ntawm kev ua raws ib feem ntawm txoj cai. IPAddress IP = WiFi.softAPIP (); Serial.print ("AP IP chaw nyob:"); Serial.println (IP); Los ntawm lub neej ntawd IP chaw nyob yog: 192.168.4.1

Kauj Ruam 5: Kauj Ruam Kawg: Xeem

Kauj Ruam Kawg: Xeem
Kauj Ruam Kawg: Xeem

Tom qab rub tawm cov cai ces qhib koj lub xov tooj ntawm tes/pc wifi thiab txuas rau lub wifi esp8266 (xijpeem ssid & password koj tau nkag rau hauv txoj cai siv qhov ntawd). Tom qab txuas tsuas qhib IP hauv koj tus browser uas peb tau txais los ntawm tus saib xyuas (https://192.168.4.1.) thiab koj yuav tuaj yeem pom qhov kub thiab av noo hauv koj tus browser li kuv li. Thiab peb tsis tau siv ib lub network wifi kom ua tiav qhov no yog li cas thiaj nkag tau ntawm esp8266 ua haujlwm.

Pom zoo: