Cov txheej txheem:

Tshaj Tawm Wireless Siab Sensor Cov Ntaub Ntawv Siv MQTT: 7 Cov Kauj Ruam
Tshaj Tawm Wireless Siab Sensor Cov Ntaub Ntawv Siv MQTT: 7 Cov Kauj Ruam

Video: Tshaj Tawm Wireless Siab Sensor Cov Ntaub Ntawv Siv MQTT: 7 Cov Kauj Ruam

Video: Tshaj Tawm Wireless Siab Sensor Cov Ntaub Ntawv Siv MQTT: 7 Cov Kauj Ruam
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla использовать для? 2024, Kaum ib hlis
Anonim
Tshaj Tawm Wireless Siab Sensor Cov Ntaub Ntawv Siv MQTT
Tshaj Tawm Wireless Siab Sensor Cov Ntaub Ntawv Siv MQTT

ESP32 thiabESP 8266 yog SoC paub zoo heev hauv IoT. Cov no yog cov khoom zoo rau IoT cov haujlwm. ESP 32 yog cov cuab yeej siv nrog WiFi thiab BLE. Tsuas yog muab koj tus SSID, tus lej zais thiab tus IP teeb tsa thiab muab cov khoom tso rau hauv huab. Nov yog cov lus qhia no, Peb yuav xav txog qee yam ntawm cov ntsiab lus yooj yim ntawm IoT zoo li IoT platform, MQTT, Captive portals thiab lwm yam. Yog li cia peb mus hla nws

  • IoT Architecture hauv cov lus yooj yim heev suav nrog cov cuab yeej kos thiab IoT platform los tso lub cuab yeej hauv huab. Ntawm no peb tab tom siv UbiDots IoT platform txhawm rau pom cov ntaub ntawv ntsuas.
  • Kev tswj hwm tus IP chaw thiab Tus neeg siv daim ntawv pov thawj tuaj yeem mob taub hau rau tus neeg siv. Yuav ua li cas yog tias Tus Neeg Siv Khoom xav hloov daim ntawv pov thawj WiFi? Yuav ua li cas yog tias tus neeg siv xav hloov DHCP/Static IP nqis? Kev ntsais muag ESP32 txhua lub sijhawm tsis txaus ntseeg thiab tsis yog qhov kev daws rau cov teeb meem no. Yog li peb yuav dhau los ntawm lub qhov rooj raug kaw kom txuag tau WiFi daim ntawv pov thawj thiab lwm yam teeb tsa.
  • MQTT tam sim no dhau los ua ib qho lus siv ntau hauv IoT ntiaj teb. nws tau hla dhau qhov kev thov thiab lus teb (HTTP) los ntawm Kev Tshaj Tawm thiab Sau Npe vim tias nrawm, muaj zog thiab tsis muaj teeb meem.

Ntawm no hauv cov lus qhia no, peb yuav mus ua kom pom.

  • Muab WiFi thiab MQTT daim ntawv pov thawj siv Captive Portal.
  • Tshaj tawm thiab sau npe ntau yam Sensor cov ntaub ntawv rau UbiDots.
  • Nyeem cov ntaub ntawv Sensor los ntawm Wireless Siab thiab Kub Sensor
  • Hosting lub vev xaib los ntawm ESP32.
  • Nyeem thiab Sau Ntawv los ntawm SPIFFS ESP32.

Kauj Ruam 1: Kev Kho Vajtse thiab Software Tshwj Xeeb

Kho vajtse Specification

  • ESP32 WiFi/BLE
  • Wireless Siab thiab Kub Sensor

Specification ntawm Software

  • Arduino IDE Cov
  • XCTU
  • Labview Utility

Kauj Ruam 2: Wireless Siab thiab Kub Kub

Wireless Siab thiab Kub Sensors
Wireless Siab thiab Kub Sensors
Wireless Siab thiab Kub Sensors
Wireless Siab thiab Kub Sensors
Wireless Siab thiab Kub Sensors
Wireless Siab thiab Kub Sensors

Nta

  • Muaj Qib Sensor Ntev Ntau Yam Wireless Siab Kub Sensor
  • Kev Ua Haujlwm Ntau Yam 0 txog 14000 mbar -40 ° txog +85 ° C (-40 ° txog 185 ° F)
  • Configurable Internal Calculation Pressure Resolution 0.012 txog 0.065 mbar
  • Configurable Internal Calculation Kub Daws Teeb Meem 0.002 txog 0.012 ° C
  • Qhov tseeb ± 2.5 mbar, ± 2 ° C.
  • Siab Tsis Txaus Siab, Txheeb Ze Siab thiab Txheeb Ze Qhov Siab Hloov pauv cov txiaj ntsig
  • 2 mais Kab-ntawm-Pom Ntau Yam nrog On-Board Antenna
  • Superior LOS Ntau li ntawm 28 mais nrog High-Gain Antennas
  • Kev cuam tshuam rau Raspberry Pi, Microsoft® Azure®, Arduino thiab Ntau Ntxiv
  • Wireless Mesh Networking siv DigiMesh®

Kev teeb tsa Wireless Siab thiab Kub Sensor Siv Labview Utility thiab XCTU

Lub Sensor khiav hauv ob hom

  • Kev teeb tsa hom: teeb tsa Pan ID, ncua sijhawm, Tsis rov ua dua thiab lwm yam Ntxiv rau qhov no dhau ntawm qhov kev qhia no thiab yuav piav qhia hauv cov lus qhia tom ntej.
  • Hom Khiav: Peb tab tom khiav lub cuab yeej hauv Hom Khiav. Thiab txhawm rau txheeb xyuas cov txiaj ntsig no peb tab tom siv Labview Utility

Labview UI no qhia pom qhov tseem ceeb hauv cov duab zoo. Nws qhia txog tam sim no nrog rau qhov txiaj ntsig yav dhau los. Koj tuaj yeem mus rau qhov txuas no txhawm rau rub Labview UI. nyem rau ntawm Run icon los ntawm cov ntawv qhia zaub mov nplooj ntawv kom mus rau hom khiav.

Kauj ruam 3: Txuas rau WiFi

Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi

Peb tab tom siv lub portal raug kaw kom txuag tau WiFi cov ntaub ntawv pov thawj thiab kom yuj dhau IP chaw. Txog kev qhia ntxaws ntxaws ntawm lub portal raug kaw, koj tuaj yeem hla cov lus qhia hauv qab no.

Lub qhov rooj raug kaw muab rau peb xaiv los xaiv ntawm Static thiab DHCP nqis. Tsuas yog nkag mus rau daim ntawv pov thawj zoo li IP zoo li qub, Subnet Mask, lub qhov rooj thiab Wireless Sensor Gateway yuav tau teeb tsa ntawm tus IP ntawd.

Ib lub vev xaib raug teeb tsa nyob qhov twg cov npe qhia pom muaj WiFi tes hauj lwm thiab muaj RSSI. Xaiv WiFi network thiab tus password thiab nkag mus xa. Cov ntaub ntawv pov thawj yuav raug cawm hauv EEPROM thiab IP chaw yuav raug cawm hauv SPIFFS. Xav paub ntau ntxiv txog qhov no tuaj yeem pom hauv phau ntawv qhia no.

Kauj Ruam 4: Teeb UbiDots ntawm ESP32

Teeb UbiDots ntawm ESP32
Teeb UbiDots ntawm ESP32

Ntawm no peb tab tom siv Wireless Siab thiab Kub Sensor nrog ESP 32 lub cuab yeej kom tau txais qhov kub thiab txias cov ntaub ntawv. Peb tab tom xa cov ntaub ntawv mus rau UbiDots siv MQTT raws tu qauv. MQTT ua raws li kev tshaj tawm thiab sau npe ua haujlwm qhov kev thov thiab lus teb. Nws nrawm dua thiab ntseeg tau dua HTTP. Qhov no ua haujlwm raws li hauv qab no.

  • Peb tab tom siv Task Scheduler los Teem sijhawm ua haujlwm zoo li nqa cov ntaub ntawv los ntawm cov ntsuas, Tshaj tawm cov ntsuas nyeem ntawv, Sau npe rau MQTT lub ncauj lus.
  • Ua ntej, suav nrog Task Scheduler header files, nws yog piv txwv thiab teem sijhawm ua haujlwm.
  • Peb tau teem sijhawm ob txoj haujlwm hais txog ob txoj haujlwm tswj hwm sib txawv.

#define _TASK_TIMEOUT#suav nrog Teem sijhawm ts; // --------- Tasks ------------ // Task tSensor (4 * TASK_SECOND, TASK_FOREVER, & taskSensorCallback, & ts, cuav, NULL, & taskSensorDisable); Task tWiFi (10* TASK_SECOND, TASK_FOREVER, & taskWiFiCallback, & ts, cuav, NULL, & taskWiFiDisable);

  • 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 txog nws lub sijhawm tawm Peb tab tom txuas rau Wifi hauv zos thiab MQTT tus tswv lag luam.
  • Tam sim no Task 2 tau qhib thiab peb tab tom ua haujlwm Task 1
  • Txoj Haujlwm 2 yog rau tshaj tawm cov ntaub ntawv ntsuas rau UbiDots MQTT tus neeg ua haujlwm no ua haujlwm rau 20 vib nas this kom txog thaum nws mus txog 20 feeb
  • Thaum Task2 mus txog nws lub sijhawm tawm Task 1 tau qhib dua thiab Task2 tau xiam oob khab. Ntawm no dua, peb tau txais tus nqi hloov kho tshiab thiab cov txheej txheem txuas ntxiv mus.

Nyeem I2C Sensor Cov Ntaub Ntawv

Peb tau txais 29-byte thav duab los ntawm Wireless Kub thiab Vaum Sensors. Cov thav duab no tau siv kom tau txais qhov kub thiab txias cov ntaub ntawv tseeb

yog (Serial1.available ())

{data [0] = Serial1.read (); ncua (k); yog (cov ntaub ntawv [0] == 0x7E) {thaum (! Serial1.available ()); rau (i = 1; i <36; i ++) {data = Serial1.read (); ncua (1); } yog (cov ntaub ntawv [15] == 0x7F) /////// txhawm rau txheeb xyuas yog tias cov ntaub ntawv tau txais yog raug {yog (cov ntaub ntawv [22] == 0x06) //////// xyuas kom tseeb tias hom sensor yog qhov tseeb {int cTemp = ((((cov ntaub ntawv [24]) * 256) + cov ntaub ntawv [25]))); int16_t abs_pressure = ((((uint16_t) (cov ntaub ntawv [26]) << 8) | cov ntaub ntawv [27])*0.001); int rlt_pressure = ((((cov ntaub ntawv [28]) * 256) + cov ntaub ntawv [29]) * 0.001); int16_t delta_alt = ((((uint16_t) (data [30]) << 8) | data [31])*0.01); roj teeb ntab = ((cov ntaub ntawv [18] * 256) + cov ntaub ntawv [19]); ntab voltage = 0.00322 * roj teeb; Serial.print ("Tus lej Sensor"); Serial.println (cov ntaub ntawv [16]); Serial.print ("Hom Sensor"); Serial.println (cov ntaub ntawv [22]); Serial.print ("Firmware Version"); Serial.println (cov ntaub ntawv [17]); Serial.print ("Kub hauv Celsius:"); Serial.print (cTemp); Serial.println ("C"); Serial.print ("Siab Tsis Zoo:"); Serial.println (abs_pressure); Serial.print ("mbar"); Serial.print ("Txheeb ze siab:"); Serial.println (rlt_pressure); Serial.print ("mbar"); Serial.print ("Delta Qhov siab:"); Serial.println (delta_alt); Serial.print ("meter"); Serial.print ("ADC tus nqi:"); Serial.println (roj teeb); Serial.print ("Roj teeb Voltage:"); Serial.print (qhov hluav taws xob); Serial.println ("\ n"); yog (voltage <1) {Serial.println ("Sijhawm Hloov Lub Roj Teeb"); }}} lwm qhov {rau (i = 0; i <36; i ++) {Serial.print (cov ntaub ntawv )); Serial.print (","); ncua (1); }}}}

Txuas rau UbiDots MQTT API

Suav nrog cov ntawv header rau txheej txheem MQTT

#suav nrog

txhais lwm qhov kev hloov pauv rau MQTT xws li tus neeg siv lub npe, tus tswv lag luam chaw nyob, tus lej cim npe

#define TOKEN "BBFF-************************************" // Koj Ubidots TOKEN#txhais MQTT_CLIENT_NAME "****************************"

char mqttBroker = "yam.ubidots.com";

char them [100]; lub ntsiab lus [150]; // tsim qhov sib txawv los khaws cov cim token ID

Kauj Ruam 5: Tshaj Tawm Kev Nyeem Ntawv Sensor rau UbiDots

Luam tawm Kev Nyeem Ntawv Nyeem rau UbiDots
Luam tawm Kev Nyeem Ntawv Nyeem rau UbiDots

Tsim cov kev hloov pauv kom khaws cov ntaub ntawv sib txawv thiab tsim cov cim sib txawv los khaws cov ncauj lus

#define VARIABLE_LABEL_TEMPF "tempF" // Txheeb xyuas cov ntawv sib txawv #txhais VARIABLE_LABEL_TEMPC "tempC" // Txheeb xyuas cov ntawv sib txawv #define VARIABLE_LABEL_BAT "puav" #define VARIABLE_LABEL_HUMID "ntub" // Txheeb xyuas cov ntawv sib txawv

char topic1 [100];

char topic2 [100]; char nqe 3 [100];

tshaj tawm cov ntaub ntawv rau cov ncauj lus MQTT hais txog kev them nyiaj yuav zoo li {"tempc": {tus nqi: "tempData"}}

sprintf (ntsiab lus 1, "%s", ""); sprintf (topic1, "%s%s", "/v1.6/devices/", DEVICE_LABEL); sprintf (payload, "%s", ""); // Ntxuav lub payload sprintf (payload, "{"%s / ":", VARIABLE_LABEL_TEMPC); // Ntxiv tus nqi sprintf (payload, "%s {" value / ":%s}", payload, str_cTemp); // Ntxiv tus nqi sprintf (payload, "%s}", payload); // Kaw cov phau ntawv txhais lus kab lus Serial.println (them nyiaj); Serial.println (client.publish (topic1, payload)? "Luam tawm": "tsis tau tshaj tawm"); // Ua tib yam rau lwm lub ncauj lus ib yam nkaus

client.publish () tshaj tawm cov ntaub ntawv rau UbiDots

Kauj Ruam 6: Pom Cov Ntaub Ntawv

Visualizing Cov Ntaub Ntawv
Visualizing Cov Ntaub Ntawv
  • Mus rau Ubidots thiab nkag mus rau koj tus lej nyiaj.
  • Nkag mus rau Dashboard los ntawm Cov Ntaub Ntawv tab teev rau saum.
  • Tam sim no nyem rau "+" icon ntxiv cov widgets tshiab.
  • Xaiv tus widget los ntawm daim ntawv thiab ntxiv qhov sib txawv thiab cov khoom siv.
  • Cov ntaub ntawv ntsuas tuaj yeem pom ntawm lub dashboard siv cov cuab yeej sib txawv.

Kauj Ruam 7: Txoj Cai Tag Nrho

Over Code rau HTML thiab ESP32 tuaj yeem pom nyob hauv GitHub qhov chaw cia khoom no.

Khab nias

  • ncd ESP32 breakout board.
  • ncd Wireless Siab thiab Kub Sensors
  • pubsubclient
  • UbiDots
  • Teem Sijhawm

Pom zoo: