Cov txheej txheem:

Daim Ntawv Qhia Txog Huab Cua Siv ThingSpeak MQTT thiab IFTTT Applets: 8 Kauj Ruam
Daim Ntawv Qhia Txog Huab Cua Siv ThingSpeak MQTT thiab IFTTT Applets: 8 Kauj Ruam

Video: Daim Ntawv Qhia Txog Huab Cua Siv ThingSpeak MQTT thiab IFTTT Applets: 8 Kauj Ruam

Video: Daim Ntawv Qhia Txog Huab Cua Siv ThingSpeak MQTT thiab IFTTT Applets: 8 Kauj Ruam
Video: QHIA QHOV TSEEB - KUB VAJ LOOG TSUA NEW MUSIC VIDEO 2022 2024, Kaum ib hlis
Anonim
Tshaj Qhia Huab Cua Siv ThingSpeak MQTT thiab IFTTT Applets
Tshaj Qhia Huab Cua Siv ThingSpeak MQTT thiab IFTTT Applets

Taw qhia

Daim ntawv thov huab cua raws huab cua muab kev qhia huab cua txhua hnub raws li email ceeb toom. Lub vev xaib no Thov ntsuas Kub thiab Vaum siv SHT25 thiab Adafruit Huzzah ESP8266. Nws muab peb nrog Cov Sijhawm Kub Kub thiab Ntiag Tug cov ntaub ntawv thiab kev tshuaj xyuas ib teev. Cov ntaub ntawv raug xa mus siv ThingSpeak MQTT API thiab tom qab ntawd peb tau muab email ceeb toom rau tus neeg siv thaum twg qhov kub tau nce mus txog qib uas tau siv IFTTT raws tu qauv. SHT25 yog Cov ntsuas kub thiab av noo ua los ntawm Sensirion. SHT25 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.

Nta

  • Muab sijhawm rau koj txheeb xyuas thiab txheeb cais siv Qhov Hais Lus MQTT API
  • Kev ceeb toom email tau muab rau tus neeg siv ntawm lub sijhawm siv IFTTT
  • Tus Teem Sijhawm tau siv los Teem sijhawm ua haujlwm zoo li nqa cov ntaub ntawv los ntawm cov ntsuas, Tshaj tawm cov ntawv nyeem sensor, Sau npe rau MQTT lub ncauj lus
  • Nws siv I2C cov txheej txheem los nqa lub ntsuas nyeem ntawv uas yog qhov tseeb dua, nthuav dav thiab nthuav dav
  • hom pw tsaug zog thaum lub cuab yeej tsis ua haujlwm lossis tsis muaj lub luag haujlwm hu rov qab.
  • kev teem sijhawm ua haujlwm tau zoo muab kev siv yooj yim
  • Ib lub vev xaib sib cais tau teeb tsa qhov chaw uas tus neeg siv yuav tsum muab nws daim ntawv pov thawj rau tus neeg siv kom tsis txhob nyem koj lub cuab yeej txhua lub sijhawm thaum mus txog ntawm lwm lub network wifi
  • SPIFFS tau siv los khaws peb lub vev xaib kom ua rau peb cov lej nyeem tau thiab tsis meej pem

Kauj Ruam 1: Kev Kho Vajtse thiab Software Tshwj Xeeb

Kho vajtse thiab Software Specification
Kho vajtse thiab Software Specification
Kho vajtse thiab Software Specification
Kho vajtse thiab Software Specification

Kho vajtse Specification

  • Adafruit esp8266 Huzzah board
  • Huzzah Board Shield
  • SHT25 Sensor module
  • I2C kab

Specification ntawm Software

  • Arduino IDE Cov
  • IFTTT Yam Hais Lus
  • MQTT API

Kauj Ruam 2: Khaws Cov Ntawv Pov Thawj Tus Neeg Siv

Khaws Cov Ntawv Pov Thawj Cov Neeg Siv
Khaws Cov Ntawv Pov Thawj Cov Neeg Siv
Khaws Cov Ntawv Pov Thawj Cov Neeg Siv
Khaws Cov Ntawv Pov Thawj Cov Neeg Siv

Ntawm no peb tab tom siv SHT25 I2C sensor los nyeem lub sijhawm tiag tiag ntawm Qhov Kub thiab Txheeb Ze Cov Vaum thiab tshaj tawm cov txiaj ntsig no rau huab. Txhawm rau kom tau txais qhov hloov kho tshiab tus nqi ib ntus thiab tshaj tawm cov kev hloov tshiab no ib txhij peb tab tom siv Arduino Cov Haujlwm Teem Sijhawm Qub. Rau huab ua haujlwm, peb tab tom siv ThingSpeak MQTT API. Tom qab ntawd peb tab tom muab daim ntawv qhia huab cua raws sijhawm rau tus neeg siv siv IFTTT applets. Koj tuaj yeem ua raws cov kauj ruam no los ua koj lub chaw nres tsheb huab cua. Yog li, DIY.

Ua ntej mus ntxiv. Peb yuav tsum khaws cov neeg siv daim ntawv pov thawj. Rau lub hom phiaj no, peb tab tom tuav lub web server ntawm 192.169.1.4. Peb tau khaws peb lub vev xaib hauv SPIFFS. Thaum lub cuab yeej pib nws muaj lub web server rau 60 secs. Tus neeg siv yuav tsum ua raws cov theem no.

  • Txuas mus rau AP ESPuser, Qhov no tau teev nyob hauv koj cov npe wifi network muaj. Txuas rau AP thiab sau tus password "*******"
  • Thaum nws tau txuas nrog, Mus rau koj tus browser nkag mus rau tus IP 192.168.1.4.
  • Nkag mus rau SSID thiab tus lej zais ntawm koj lub WiFi hauv zos hauv cov teb nkag thiab nkag mus SUBMIT
  • Cov ntawv pov thawj no yuav raug cawm hauv EEPROM
  • Tom qab 60-sec Ntaus Ntawv yuav txiav tawm ntawm AP
  • Lub sijhawm tom ntej thaum koj qhib lub cuab yeej, Tus neeg siv tsis tas yuav ua raws cov txheej txheem no, Lub cuab yeej yuav cia li nqa tus neeg siv daim ntawv pov thawj los ntawm EEPROM thiab txuas ntxiv nrog kom tau txais lub sensor nyeem los ntawm I2C Interface thiab tshaj tawm nws mus rau huab

// --------- AP teeb tsa ------------ // IPAddress ap_local_IP (192, 168, 1, 4); IPAddress ap_gateway (192, 168, 1, 254); IPAddress ap_subnet (255, 255, 255, 0);

Serial.print ("Kho qhov chaw nkag …");

WiFi.softAPConfig (ap_local_IP, ap_gateway, ap_subnet);

Serial.print ("Teeb Tus Neeg Siv Cov Ntawv Pov Thawj");

WiFi.softAP (ssidAP, passAP);

server.on ("/", handleRoot);

server.onNotFound (onHandleNotFound);

server.begin ();

APTimer = millis ();

thaum (millis ()-APTimer <APInterval) {

server.handleClient ();

}

// **************************** HAIS TXOG ROOT ****************** ********* // tsis muaj dab tsi handleRoot () {

yog (server.hasArg ("ssid") && server.hasArg ("password"))

{

// Yog tias txhua daim teb muaj cov ntaub ntawv hu

HandelSubmit ()

handleSubmit (); }

lwm tus {

// Rov ua dua daim ntawv

// nyeem cov ntawv uas muaj nyob hauv spiff

Cov ntaub ntawv cov ntaub ntawv = SPIFFS.open ("/webform.html", "r");

server.streamFile (ntaub ntawv, "ntawv nyeem/html");

// tsis txhob hnov qab kaw cov ntawv

file.close (); cov.

}}

// Txheeb xyuas qhov xwm txheej uas nws muaj kev sib cav ssid thiab password

// Tom qab ntawv sau daim ntawv pov thawj rau ROM

ROMwrite (Txoj hlua (server.arg ("ssid")), Txoj hlua (server.arg ("password")))

Kauj Ruam 3: Teeb Koj Lub Vev Xaib hauv SPIFFS

SPIFFS

Serial Peripheral Interface Flash File System, lossis SPIFFS kom luv. Nws yog lub teeb-hnyav cov ntaub ntawv kaw lus rau microcontrollers nrog SPI flash nti. Onboard flash nti ntawm ESP8266 muaj chaw txaus rau koj nplooj ntawv web, tshwj xeeb tshaj yog tias koj muaj 1MB, 2MB lossis 4MB version. Peb kuj tseem khaws peb lub vev xaib hauv Flash System. Muaj ob peb kauj ruam peb yuav tsum ua raws txhawm rau xa cov ntaub ntawv mus rau spiff

  1. Rub lub cuab yeej:
  2. Hauv koj phau ntawv teev npe Arduino sketchbook, tsim cov npe khoom yog tias nws tseem tsis tau muaj
  3. Unpack cov cuab yeej rau hauv cov cuab yeej phau ntawv (txoj kev yuav zoo li /Arduino/tools/ESP8266FS/tool/esp8266fs.jar)
  4. Rov pib dua Arduino IDE
  5. Qhib cov duab kos (lossis tsim ib qho tshiab thiab txuag nws)
  6. Mus rau daim duab qhia chaw (xaiv Sketch> Qhia Sketch Folder)
  7. Tsim cov npe npe cov ntaub ntawv thiab txhua cov ntaub ntawv koj xav tau hauv cov kab ke system nyob ntawd. Peb tau tshaj tawm peb nplooj ntawv HTML nrog lub npe webform.html
  8. Nco ntsoov tias koj tau xaiv pawg thawj coj, chaw nres nkoj, thiab kaw Serial Monitor
  9. Xaiv Cov Cuab Yeej> ESP8266 Sketch Data Upload. Qhov no yuav tsum pib rub cov ntawv mus rau hauv ESP8266 flash file system. Thaum ua tiav, IDE xwm txheej bar yuav tso saib SPIFFS Duab Tshaj tawm cov lus.

Cov ntaub ntawv cov ntaub ntawv = SPIFFS.open ("/webform.html", "r");

server.streamFile (ntaub ntawv, "ntawv nyeem/html");

// tsis txhob hnov qab kaw cov ntawv

file.close (); cov.

Kauj Ruam 4: Teem Sijhawm Ua Haujlwm

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

  • Nyeem cov ntaub ntawv los ntawm SHT25 siv I2C raws tu qauv
  • Tshaj tawm cov ntaub ntawv hloov tshiab rau huab siv ThingSpeak MQTT API

Txhawm rau ua tiav qhov no peb siv TaskScheduler lub tsev qiv ntawv. Peb tau teem sijhawm ob txoj haujlwm sib txawv hais txog ob 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 tas lawm Peb tab tom txuas rau Wifi hauv zos thiab MQTT tus tswv lag luam.
  • Tam sim no Ua Haujlwm 2 tau qhib thiab peb tabtom ua haujlwm Task 1Task 2 yog rau tshaj tawm cov ntaub ntawv ntsuas mus rau Qhov Hais Lus MQTT tus neeg ua haujlwm cov haujlwm no ua haujlwm rau 20 vib nas this txog thaum nws mus txog 20 lub sijhawm
  • Thaum Task2 mus txog nws lub sijhawm Task 1 tau qhib dua thiab Task2 tau xiam oob khab. nov dua, peb tau txais tus nqi hloov kho tshiab thiab cov txheej txheem txuas ntxiv mus
  • thaum tsis muaj kev hu rov qab los yog lub cuab yeej tsis ua haujlwm nws mus rau Lub Teeb Txias yog li txuag lub zog.

// --------- tsab rau kev hu rov qab ------------ //

void taskI2CCallback ();

void taskI2CDisable ();

tsis muaj dab tsi taskWiFiCallback ();

void taskWiFiDisable ();

// --------- Cov Haujlwm ------------ //

Task tI2C (2 * TASK_SECOND, TASK_FOREVER, & taskI2CCallback, & ts, cuav, NULL, & taskI2CDisable);

Task tWiFi (20* TASK_SECOND, TASK_FOREVER, & taskWiFiCallback, & ts, cuav, NULL, & taskWiFiDisable);

// pab kom tI2C tI2C.enable ();

Kauj Ruam 5: Nyeem Qhov Kub thiab Qhov Ntsuas Qhov Zoo Los Ntawm SHT25

Nyeem Qhov Kub thiab Vaum Qhov Zoo Los Ntawm SHT25
Nyeem Qhov Kub thiab Vaum Qhov Zoo Los Ntawm SHT25

I2C yog ob txoj hlua sib txuas uas tsuas yog siv ob lub xov hlau los sib txuas lus nrog tus tswv cuab. Ib qho yog SCL (Serial Clock) thiab lwm qhov yog SDA (Serial Data). Txhua lub cuab yeej qhev muaj qhov chaw nyob tshwj xeeb. SHT 25 kuj tseem muaj qhov chaw nyob 8-ntsis thiab tuaj yeem nkag los ntawm 0x44 chaw nyob. nws muaj 8bits ntawm qhov chaw nyob uas 7 khoom yog qhov chaw nyob tiag thiab thaum txoj cai LSB ntsis 0 yog siv los teeb liab nyeem ntawv lossis sau ntawv mus rau lub cuab yeej. Yog tias me ntsis 0 tau teeb tsa rau 1 ces tus tswv cuab yeej yuav nyeem los ntawm tus qhev I2C ntaus ntawv. I2C muaj kev ntseeg tau ntau dua, ua kom nrawm dua thiab nrawm dua thiab txawm tias nws muaj ntau hom kev ua haujlwm uas ua rau nws muaj zog ntau dua

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 SHT25. SHT25 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

Kauj Ruam 6: Tshaj Tawm Tus Nqi rau ThingSpeak Siv ThingSpeak MQTT API

Tshaj Tawm Tus Nqi rau ThingSpeak Siv ThingSpeak MQTT API
Tshaj Tawm Tus Nqi rau ThingSpeak Siv ThingSpeak MQTT API

Txog kev tshaj tawm peb qhov kub thiab txias qhov tseem ceeb rau huab peb tab tom siv ThingSpeak MQTT API. 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. MQTT yog cov txheej txheem ib txwm siv hauv IoT cov kab ke los txuas cov cuab yeej qis thiab cov ntsuas. MQTT yog siv los xa cov lus luv rau thiab los ntawm tus tswv lag luam. ThingSpeak tsis ntev los no tau ntxiv MQTT broker kom cov khoom siv tuaj yeem xa xov mus rau ThingSpeak. Koj tuaj yeem ua raws cov txheej txheem los teeb tsa ThingSpeak Channel los ntawm cov ntawv no

ThingSpeak MQTT

MQTT yog tshaj tawm/sau npe ua vaj tsev uas tau tsim los txuas rau txuas bandwidth thiab lub zog-txwv cov cuab yeej hla wireless tes hauj lwm. Nws yog cov txheej txheem yooj yim thiab hnyav uas ua haujlwm dhau TCP/IP qhov nyob lossis WebSockets. MQTT hla WebSockets tuaj yeem ruaj ntseg nrog SSL. Kev tshaj tawm/sau npe ua haujlwm ua kom cov lus raug thawb mus rau cov neeg siv khoom yam tsis muaj lub cuab yeej xav tau los mus pov ntawv tawm suab tsis tu ncua. Ib lub ncauj lus muaj cov ntaub ntawv qhia txog tus broker. Txhua tus neeg siv khoom uas xav xa lus tshaj tawm lawv mus rau qee lub ncauj lus, thiab txhua tus neeg siv khoom uas xav tau txais cov lus sau npe rau qee lub ncauj lus

Tshaj tawm thiab sau npe siv ThingSpeak MQTT

  • Tshaj tawm rau cov channel pub channel /tshaj tawm /
  • Tshaj tawm rau ib cheeb tsam tshwj xeeb/tshaj tawm/teb/teb/
  • Sau npe yuav mus rau cov channel field channels/subscribe //
  • Sau npe yuav mus rau tus kheej ntiag tug pub pub raws // subscribe/fields/field/
  • Sau npe yuav ua rau txhua qhov ntawm cov channel. raws // subscribe/fields/feild/

void taskWiFiCallback ()

{

Serial.println ("taskWiFiCallbackStarted");

Serial.print ("sijhawm tas rau txoj haujlwm no: / t");

Serial.println (tWiFi.getTimeout ());

yog (! mqttCli.connected ())

{

Serial.println ("Client tsis txuas nrog");

reconnectMQTT ();

}

String topicString = "channel/"+String (channelID)+"/publishing/"+String (writeAPIKey);

int topicLength = topicString.length ()+1;

char topicBuffer [topicLength];

topicString.toCharArray (topicBuffer, topicLength+1);

Serial.println (topicBuffer);

String dataString = String ("field1 =" + String (tempC, 1) + "& field2 =" + String (tempF, 1) + "& field3 =" + String (ntub, 1));

int dataLength = dataString.length ()+1;

byte dataBuffer [dataLength];

dataString.getBytes (dataBuffer, dataLength);

mqttCli.beginPublish (topicBuffer, dataLength, cuav);

Serial.println (mqttCli.write (dataBuffer, dataLength)? "Luam tawm": "luam tawm ua tsis tiav");

mqttCli.endPublish ();

//mqttCli.loop ();

}

Kauj Ruam 7: Tshaj Qhia Huab Cua Email Ceeb Toom

Huab Cua Qhia Email Ceeb Toom
Huab Cua Qhia Email Ceeb Toom
Huab Cua Qhia Email Ceeb Toom
Huab Cua Qhia Email Ceeb Toom

Peb tab tom siv IFTTT cov ntawv thov los tshaj tawm huab cua lub sijhawm tiag tiag Email ceeb toom rau tus neeg siv. Yog li, Peb tau siv nws los ntawm ThingSpeak. Peb tab tom kwv yees 5-fay qhov tseem ceeb ntawm qhov kub thiab txias. Thaum twg tus nqi ntawm qhov nkag zaum kawg yog ntau dua li tus nqi nruab nrab. Nws yuav ua rau ceeb toom email "nws yog hnub kub". thiab thaum nws tsawg dua tus nqi nruab nrab. Nws yuav ua rau email ceeb toom "Hnub zoo nkauj npaum cas". Txhua txhua hnub nyob ib ncig ntawm 10:00 teev sawv ntxov (IST) peb yuav tau txais email ceeb toom

channelID = ******;

iftttURL = 'https://maker.ifttt.com/**************';

moistureData = thingSpeakRead (channelID, 'Field', 3, 'NumDays', 5); tempData = thingSpeakRead (channelID, 'Field', 1, 'NumDays', 5);

perHumid = max (moistureData) -min (noo nooData);

humidValue = 0.1*perHumid+min (moistureData);

perTemp = max (tempData) -min (tempData);

tempValue = 0.1*perTemp+min (tempData);

urlTemp = strcat ('https://api.thingspeak.com/channels/', hlua (channelID), '/fields/1/last.txt');

urlHumid = strcat ('https://api.thingspeak.com/channels/', hlua (channelID), '/fields/3/last.txt'); lastTempValue = str2num (webread (urlTemp)); lastHumidValue = str2num (webread (urlHumid));

yog (lastTempValue

yog (lastTempValue> tempValue || lastHumidValue> humidValue)

plantMessage = 'Nws yog hnub kub.' webwrite (iftttURL, 'value1', plantMessage, 'value2', lastTempValue, 'value3', lastHumidValue); kawg

Kauj Ruam 8: Txoj Cai Tag Nrho

Zuag qhia tag nrho Code
Zuag qhia tag nrho Code
Zuag qhia tag nrho Code
Zuag qhia tag nrho Code
Zuag qhia tag nrho Code
Zuag qhia tag nrho Code

Zuag qhia tag nrho Code

Cov lej tag nrho muaj nyob hauv GitHub qhov chaw cia khoom no

Txwv

  • Muaj qee qhov teeb meem nrog kev tshaj tawm cov ntaub ntawv siv tshaj tawm txoj hauv kev rau cov ntaub ntawv ntau. Los daws qhov teeb meem no peb siv sau () ua haujlwm
  • SPIFFS yuav tsum raug teeb tsa ua ntej xa cov ntaub ntawv tshiab mus rau SPIFFS.
  • Koj yuav tsum tsis txhob siv sijhawm qeeb () ua haujlwm. ncua () cuam tshuam rau kev ua haujlwm tom qab. Hloov chaw, tsim qeeb siv millis () tsuas yog nws tsim nyog

Khab nias

  • ESP826WebServer
  • Teem Sijhawm
  • TSH 25
  • ThingSpeak MQTT API
  • IFTTT
  • PubSubClient

Pom zoo: