Cov txheej txheem:

THINGSPEAK TEMPERATURE THIAB HUMIDITY APP Siv ESP8266: 9 Cov Kauj Ruam
THINGSPEAK TEMPERATURE THIAB HUMIDITY APP Siv ESP8266: 9 Cov Kauj Ruam

Video: THINGSPEAK TEMPERATURE THIAB HUMIDITY APP Siv ESP8266: 9 Cov Kauj Ruam

Video: THINGSPEAK TEMPERATURE THIAB HUMIDITY APP Siv ESP8266: 9 Cov Kauj Ruam
Video: DHT11 & NodeMCU Tutorial || Humidity & Temperature Monitoring over Thingspeak 2024, Kaum ib hlis
Anonim
THINGSPEAK TEMPERATURE THIAB HUMIDITY APP siv ESP8266
THINGSPEAK TEMPERATURE THIAB HUMIDITY APP siv ESP8266

Thaum tinkering nrog kuv cov khoom siv hluav taws xob, Kuv tau txais lub tswv yim no los ua web-based huab cua app. Lub vev xaib no siv SHT31 lub ntsuas kom tau txais cov ntaub ntawv ntsuas kub thiab huab cua lub sijhawm. Peb tau xa peb txoj haujlwm ntawm ESP8266 WiFi module. Online lossis offline! Tsis tas yuav txhawj xeeb, txawm tias koj online lossis offline koj yuav tau txais huab cua hloov tshiab los ntawm txhua qhov chaw thiab txhua lub sijhawm. Lub vev xaib app no tshaj tawm cov ntaub ntawv rau lub vev xaib hauv cheeb tsam nrog rau huab. Rau huab ua haujlwm, peb siv ThingSpeak API. SHT31 siv I2C kom tau txais cov ntaub ntawv los ntawm lub ntsuas cua.

SHT 31 yog Cov ntsuas kub thiab av noo ua los ntawm Sensirion. SHT31 muab qib siab ntawm ib puag ncig ± 2% RH. Nws cov av noo nyob nruab nrab ntawm 0 txog 100% thiab Kub ntau yog nyob nruab nrab ntawm -40 txog 125 ° C. Nws muaj kev ntseeg tau ntau dua thiab nrawm nrog 8 sec ntawm Sensor lub sijhawm teb. Nws lub luag haujlwm suav nrog txhim kho cov teeb liab ua haujlwm thiab I2C sib xws. Nws muaj ntau hom kev ua haujlwm uas ua rau nws lub zog muaj txiaj ntsig.

Hauv qhov kev qhia no, peb tau cuam tshuam SHT 31 nrog Adafruit Huzzah board. Rau kev nyeem Cov ntsuas Kub thiab Vaum peb tau siv ESP8266 I2C daim ntaub thaiv. Tus adapter no ua rau txhua tus pin nkag tau rau tus neeg siv thiab muab cov neeg siv-phooj ywg I2C ib puag ncig.

Kauj ruam 1: Yuav tsum kho vajtse

Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse

Kho vajtse siv los ua txoj haujlwm no:

  1. TSH 31
  2. Adafruit Huzzah ESP8266
  3. ESP8266 I2C adapter
  4. I2C Kab

Kauj Ruam 2: Kev Sib Txuas Kho Vajtse

Kho vajtse sib txuas
Kho vajtse sib txuas

Cov kauj ruam no suav nrog phau ntawv qhia kho vajtse sib txuas. Tshooj lus no piav qhia qhov txuas txuas uas xav tau ntawm lub ntsuas cua thiab ESP8266. Cov kev sib txuas yog raws li hauv qab no.

  1. SHT31 ua haujlwm dhau I2C. Cov duab saum toj no qhia txog kev sib txuas ntawm ESP8266 thiab SHT31 module. Peb tab tom siv I2C cable rau nws txawm tias peb tuaj yeem siv 4 F rau F jumper xov hlau.
  2. ib txoj hlua siv rau Vcc, ob txoj hlua rau GND thiab lwm ob rau SDA thiab SCL feem
  3. Raws li I2C adapter pin2 thiab tus pin 14 ntawm ESP8266 pawg thawj coj tau siv ua SDA thiab SCL feem

Kauj Ruam 3: Txoj Cai rau Teem Sijhawm

Code rau Teem Sijhawm
Code rau Teem Sijhawm

Hauv qhov kev qhia no, peb tab tom ua peb txoj haujlwm

  • Nyeem cov ntaub ntawv los ntawm SHT11 siv I2C raws tu qauv
  • host lub web server thiab tshaj tawm lub sensor nyeem rau lub vev xaib
  • tshaj tawm cov ntawv nyeem sensor rau ThingSpeak API

Txhawm rau ua tiav qhov no peb siv TaskScheduler lub tsev qiv ntawv. Peb tau teem sijhawm peb txoj haujlwm sib txawv hais txog peb qhov kev tswj hwm sib txawv. qhov no yog ua raws li hauv qab no

  • Kev Ua Haujlwm 1 yog txhawm rau nyeem tus nqi ntsuas lub luag haujlwm no ua haujlwm rau 1 thib ob txog thaum nws mus txog sijhawm 10 feeb.
  • Thaum Task1 mus txog nws lub sijhawm tawm Task 2 tau qhib thiab Task1 tau xiam.
  • Peb txuas rau AP hauv qhov kev hu rov qab no, Ob qhov boolean hloov pauv tau coj los saib xyuas kev hloov pauv ntawm STA thiab AP
  • Hauv Task 2 peb tab tom tuav lub vev xaib ntawm 192.168.1.4. Txoj haujlwm no ua haujlwm rau txhua 5 vib nas this txog thaum nws mus txog qhov nws siv sijhawm 50 feeb
  • Thaum Task 2 mus txog sijhawm sijhawm Task 3 tau qhib thiab Task2 raug xiam oob khab.

  • Peb txuas mus rau STA (IP tus hauv zos) hauv no calbackIn Task 3 peb tab tom tshaj tawm lub sensor nyeem rau huab ThingSpeak API
  • Task 3 khiav rau txhua tsib vib nas this txog thaum nws mus txog nws lub sijhawm tas li 50 feeb
  • Thaum Task3 mus txog nws lub sijhawm tawm Ua Haujlwm 1 tau qhib dua thiab Task3 tau xiam.
  • Thaum tsis muaj kev hu rov qab los lossis lub cuab yeej tsis ua haujlwm nws mus rau Lub Teeb Txias yog li txuag lub zog.

void taskI2CCallback ();

void taskI2CDisable (); void taskAPCallback (); void taskAPDisable (); tsis muaj dab tsi taskWiFiCallback (); void taskWiFiDisable (); // Cov haujlwm rau i2c, hosting lub web server thiab tshaj tawm ntawm yam hais lus Task tI2C (1 * TASK_SECOND, TASK_FOREVER, & taskI2CCallback, & ts, cuav, NULL, & taskI2CDisable); Task tI2C (1 * TASK_SECOND, TASK_FOREVER, & taskI2CCallback, & ts, cuav, NULL, & taskI2CDisable); Task tAP (5*TASK_SECOND, TASK_FOREVER, & taskAPCallback, & ts, cuav, NULL, & taskAPDisable); Task tWiFi (5* TASK_SECOND, TASK_FOREVER, & taskWiFiCallback, & ts, cuav, NULL, & taskWiFiDisable); // sijhawm tas rau cov haujlwm tI2C.setTimeout (10 * TASK_SECOND); tAP.setTimeout (50 * TASK_SECOND); tWiFi.setTimeout (50 * TASK_SECOND); // pab kom I2C ua haujlwm tI2C.enable ();

Kauj Ruam 4: Txoj Cai Nyeem Ntawv Kub thiab Qhov Ntsuas Qhov Ntsuas

Txoj Cai Nyeem Ntawv Kub thiab Vaum Qhov Ntsuas
Txoj Cai Nyeem Ntawv Kub thiab Vaum Qhov Ntsuas

Peb tab tom siv Wire.h lub tsev qiv ntawv los nyeem qhov ntsuas kub thiab av noo. Lub tsev qiv ntawv no pabcuam i2c kev sib txuas lus ntawm lub ntsuas cua thiab tus cuab yeej siv. 0x44 yog I2C chaw nyob rau SHT31.

SHT31 ua haujlwm sib txawv ntawm kev ua haujlwm. Koj tuaj yeem xa mus rau daim ntawv rau qhov ntawd. Peb siv 0x2C thiab 0x06 ua MSB thiab LSB feem rau kev txhaj tshuaj ib leeg.

// I2C ua haujlwm hu rov qab tsis muaj dabtsisI2CCallback () {Serial.println ("taskI2CStarted"); unsigned int hauv paus [6]; // pib kis los ntawm 0x44; Wire.beginTransmission (Addr); // rau kev txhaj tshuaj ib zaug nrog kev rov ua tau zoo peb siv 0x2C (MSB) thiab 0x06 (LSB) Wire.write (0x2C); Hlau.write (0x06); // kawg kis Wire.endTransmission (); // thov bytes los ntawm 0x44 Wire.beginTransmission (Addr); Wire.endTransmission (); Wire.requestFrom (Addr, 6); yog (Wire.available () == 6) {// data [0] thiab data [1] muaj 16 ntsis kub. hauv paus [0] = Wire.read (); hauv paus [1] = Wire.read (); // cov ntaub ntawv [2] muaj 8 ntsis ntawm CRC hauv paus [2] = Wire.read (); // cov ntaub ntawv [3] thiab cov ntaub ntawv [4] muaj 16 ntsis ntawm cov hauv paus av noo [3] = Wire.read (); hauv paus [4] = Wire.read (); // cov ntaub ntawv [5] muaj 8 ntsis CRC hauv paus [5] = Wire.read (); } int temp = (hauv paus [0] * 256) + hauv paus [1]; // hloov MSB los ntawm 8 khoom ntxiv LSB ntab cTemp = -45.0 + (175.0 * temp /65535.0); ntab fTemp = (cTemp * 1.8) + 32.0; // hloov MSB los ntawm 8 cov khoom ntxiv LSB rau nws cais los ntawm kev daws teeb meem tag nrho thiab * 100 rau feem pua ntab av noo = (100.0 * ((hauv paus [3] * 256.0) + hauv paus [4])) /65535.0; tempC = cTemp; tempF = fTemp; vaum = vaum; Serial.print ("Kub hauv C: / t"); Serial.println (Txoj hlua (cTemp, 1)); Serial.print ("Kub hauv F: / t"); Serial.println (Txoj hlua (fTemp, 1)); Serial.print ("Vaum: / t"); Serial.println (Txoj hlua (av noo, 1)); }

Kauj Ruam 5: Txoj Cai rau Hosting Lub Vev Xaib

Code rau Hosting Lub Vev Xaib
Code rau Hosting Lub Vev Xaib
Code rau Hosting Lub Vev Xaib
Code rau Hosting Lub Vev Xaib

Peb tau tuav lub vev xaib server los ntawm peb lub cuab yeej ntawm tus IP zoo li qub.

ESP8266WebServer lub tsev qiv ntawv tau siv los tuav lub vev xaib

  • Ua ntej peb yuav tsum tshaj tawm IP chaw nyob, Rooj vag thiab subnet daim npog los tsim peb tus IP zoo li qub
  • Tam sim no tshaj tawm ssid thiab password rau koj li Access point.connect mus rau Access point los ntawm ib qho khoom siv STA
  • host tus neeg rau zaub mov ntawm chaw nres nkoj 80 uas yog lub chaw nres nkoj rau kev sib txuas lus hauv internet, Hypertext Transfer Protocol (HTTP) nkag 192.168.1.4 ntawm koj lub vev xaib rau intro webpage thiab 192.168.1.4/Value rau sensor nyeem webpage

// IP zoo li qub rau APIPAddress ap_local_IP (192, 168, 1, 4); IPAddress ap_gateway (192, 168, 1, 254); IPAddress ap_subnet (255, 255, 255, 0); // ssid thiab AP rau WiFi hauv cheeb tsam hauv STA hom const char WiFissid = "*********"; const char WiFipass = "*********"; // ssid thiab dhau rau AP const char APssid = "********"; const char APpass = "********"; ESP8266WebServer server (80); tsis muaj teeb meem teeb tsa {server.on ("/", onHandleDataRoot); server.on ("/Tus nqi", onHandleDataFeed); server.onNotFound (onHandleNotFound);} void taskAPCallback () {Serial.println ("taskAP pib"); server.handleClient (); } tsis muaj dab tsi onHandleDataRoot () {server.send (200, "text/html", PAGE1); } void onHandleDataFeed () {server.send (200, "ntawv/html", PAGE2); } void onHandleNotFound () {String message = "File Not Found / n / n"; lus += "URI:"; lus += server.uri (); lus += "\ nMethod:"; lus += (server.method () == HTTP_GET)? "GET": "POST"; lus += "\ n Cov ntaub ntawv:"; lus += server.args (); lus += "\ n"; server.send (404, "text/plain", message); } void reconnectAPWiFi () {WiFi.mode (WIFI_AP_STA); ncua (100); WiFi.disconnect (); boolean xwm txheej = WiFi.softAPConfig (ap_local_IP, ap_gateway, ap_subnet); yog (xwm txheej == muaj tseeb) {Serial.print ("teeb tsa mos-AP …"); boolean ap = WiFi.softAP (APssid, APpass); yog (ap == muaj tseeb) {Serial.print ("txuas nrog: / t"); // IPAddress myIP = WiFi.softAPIP (); Serial.println (WiFi.softAPIP ()); } server.begin ();

}

Kauj Ruam 6: teeb tsa Thingspeak

Kev teeb tsa Thingspeak
Kev teeb tsa Thingspeak
Kev teeb tsa Thingspeak
Kev teeb tsa Thingspeak
Teeb tsa Thingspeak
Teeb tsa Thingspeak

ThingSpeak yog IoT platform. ThingSpeak yog lub vev xaib pub dawb uas tso cai rau koj sau thiab khaws cov ntaub ntawv sensor hauv huab.

Hauv Cov Kauj Ruam no, Kuv yuav muab txoj hauv kev luv luv rau koj los teeb tsa koj li Lus Hais Tias tus account

  • Sau npe rau Tus Neeg Siv Nyiaj Tshiab hauv ThingSpeak
  • Tsim Channel tshiab los ntawm kev xaiv Raws, Kuv Raws, thiab Tom Qab Tshiab Channel
  • Kho koj cov teb
  • Cov teb no muaj koj cov ntaub ntawv sensor
  • Nco ntsoov Sau API Key thiab Channel ID
  • Ntawm koj daim duab Arduino, koj tuaj yeem siv ThingSpeak lub tsev qiv ntawv rau Arduino lossis koj tuaj yeem ncaj qha POST cov ntaub ntawv mus rau ThingSpeak API
  • cov kauj ruam tom ntej piav qhia txog kev tshaj tawm cov ntsiab lus rau Thing Hais API

Kauj Ruam 7: Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais

Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais
Code rau Tshaj Tawm Cov Ntaub Ntawv rau Yam Hais

Ntawm no peb tab tom tshaj tawm cov ntawv nyeem sensor rau Yam Hais. cov theem hauv qab no xav tau kom ua tiav txoj haujlwm no-

  • Tsim koj tus lej hauv kev hais lus Tsim cov channel thiab cov teb los khaws koj cov ntaub ntawv sensor
  • peb tuaj yeem tau txais thiab tshaj tawm cov ntaub ntawv los ntawm ESP rau thingSpeak thiab hloov pauv siv GET thiab POST thov mus rau api.
  • peb tuaj yeem tshaj tawm peb cov ntaub ntawv rau ThingSpeak raws li hauv qab no

id taskWiFiCallback () {WiFiClient wifiClient; yog (wifiClient.connect (hostId, 80)) {String postStr = apiKey; postStr += "& field1 ="; postStr += Txoj hlua (ntub); postStr += "& field2 ="; postStr += Txoj hlua (tempC); postStr += "& teb 3 ="; postStr += Txoj hlua (tempF); postStr += "\ r / n / r / n"; wifiClient.print ("POST /hloov tshiab HTTP /1.1 / n"); wifiClient.print ("Tus tswv tsev: api.thingspeak.com / n"); wifiClient.print ("Kev sib txuas: kaw / n"); wifiClient.print ("X-THINGSPEAKAPIKEY:"+apiKey+"\ n"); wifiClient.print ("Cov ntsiab lus-Hom: thov/x-www-form-urlencoded / n"); wifiClient.print ("Cov ntsiab lus-Ntev:"); wifiClient.print (postStr.length ()); wifiClient.print ("\ n / n"); wifiClient.print (postStr); } wifiClient.stop (); cov. }

Kauj Ruam 8: Txoj Cai Tag Nrho

Cov lej tag nrho muaj nyob hauv kuv GitHub chaw cia khoom

Kauj Ruam 9: Khab nias

  • Arduino JSON
  • ESP826WebServer
  • Teem Sijhawm
  • TSH 31
  • I2C Luam theej duab
  • HIH6130 cov lus qhia qhia
  • Hlau
  • NCO.io

Pom zoo: