Cov txheej txheem:

Pib Nrog AWS IoT Nrog Wireless Kub Sensor Siv MQTT: 8 Cov Kauj Ruam
Pib Nrog AWS IoT Nrog Wireless Kub Sensor Siv MQTT: 8 Cov Kauj Ruam

Video: Pib Nrog AWS IoT Nrog Wireless Kub Sensor Siv MQTT: 8 Cov Kauj Ruam

Video: Pib Nrog AWS IoT Nrog Wireless Kub Sensor Siv MQTT: 8 Cov Kauj Ruam
Video: Mana Xiong - Yuav Nrog Koj Nyob 2024, Kaum ib hlis
Anonim
Pib Nrog AWS IoT Nrog Wireless Kub Kub Sensor Siv MQTT
Pib Nrog AWS IoT Nrog Wireless Kub Kub Sensor Siv MQTT

Hauv Kev Qhia Ua Ntej Ua Ntej, peb tau dhau los ntawm cov huab sib txawv xws li Azure, Ubidots, ThingSpeak, Losant thiab lwm yam Peb tau siv MQTT raws tu qauv rau xa cov ntaub ntawv sensor mus rau huab hauv yuav luag txhua lub platform huab. Yog xav paub ntxiv txog MQTT, nws qhov zoo thiab txiaj ntsig dhau HTTP raws tu qauv koj tuaj yeem xa mus rau cov lus qhia no.

Hauv cov lus qhia no, peb yuav nthuav mus rau lwm qhov thiab paub zoo tshaj huab platform Amazon Web Services. Ntau ntawm koj yuav paub nrog AWS aka Amazon Web Services thiab huab ua haujlwm tau muab los ntawm AWS. Nws yog qhov tseem ceeb ntawm kev txhim kho lub vev xaib tau ntau xyoo. Nrog kev nce qib ntawm IoT daim ntawv thov, AWS tau los nrog kev daws teeb meem ntawm AWSIoT. AWSIoT yog qhov kev daws teeb meem txhim khu kev qha rau hosting peb daim ntawv thov IoT.

Los ntawm ua raws cov lus qhia no:

  • Koj yuav tuaj yeem teeb tsa AWS tus lej rau koj daim ntawv thov IoT
  • Koj yuav tuaj yeem txuas ESP32 rau AWS IoT core
  • Xa thiab tau txais cov lus siv MQTT thiab HTTP raws tu qauv
  • Ua kom pom cov ntaub ntawv xa hauv AWS

Kauj ruam 1: teeb tsa AWS Account

Teeb tsa tus as khauj AWS yog yooj yim heev. Koj tsuas yog yuav tsum tau xa ob peb daim ntawv pov thawj, txuas cov cai rau nws, Sau npe lub cuab yeej thiab pib tau txais cov ntaub ntawv ntsuas cov lus hauv AWS.

Txhawm rau teeb tsa AWS tus account ua raws cov lus qhia no.

Kauj ruam 2: Khoos phis tawj thiab khoos phis tawj tshwj xeeb

Kho vajtse thiab Software Specifications
Kho vajtse thiab Software Specifications

Specification ntawm Software

AWS account

Kho vajtse Specification

  • ESP32
  • Wireless Kub thiab Kev Ruaj Ntseg Sensor
  • Zigmo Gateway tus txais

Kauj Ruam 3: Kev Ruaj Ntseg Wireless thiab Kub Kub

Wireless Kev co thiab Kub Sensors
Wireless Kev co thiab Kub Sensors

Qhov no yog Long Range Industrial IoT wireless kev co thiab ntsuas kub, khav theeb txog li 2 Mile ntau yam siv cov wireless mesh networking architecture. Kev koom nrog 16-ntsis Kev co thiab Kub sensor, lub ntsuas no xa tawm cov ntaub ntawv muaj kev co zoo heev ntawm cov neeg siv txhais ua ntu zus. Nws muaj cov yam ntxwv hauv qab no:

  • Muaj Qib 3-axis Kev Ruaj Ntseg Sensor nrog Range 32g Ntau Yam
  • Xam RMS, MAX, thiab MIN g Kev co
  • Kev tshem tawm suab nrov uas siv Lim Tsawg dhau
  • Ntau Zaus (Bandwidth) txog 12, 800 Hz
  • Qauv Tus Nqi mus txog 25, 600Hz
  • Kev Nkag Siab Sib Txuas nrog 2 Mile Wireless Range
  • Kev Ua Haujlwm Kub Ntau Yam -40 txog +85 ° C
  • Phab Ntsa-Mounted lossis Magnet Mounted IP65 Rated EnclosureExample Software rau Visual Studio thiab LabVIEW
  • Kev co Sensor nrog Kev Tshawb Fawb Sab Nraud
  • Txog li 500, 000 Kev Tshaj Tawm los ntawm 4 AA Roj Teeb Ntau Lub Rooj vag thiab Cov Qauv Xaiv Muaj

Kauj ruam 4: ESP32 AWS Firmware

Txhawm rau txuas rau AWS thiab pib xa cov ntaub ntawv mus raws cov theem hauv qab no

  • Rub tawm AWS lub tsev qiv ntawv los ntawm Github chaw cia khoom hauv qab no
  • clone repo thiab tso AWS_IOT cov ntaub ntawv rau cov ntawv tais ceev tseg ntawm Arduino cov npe

git clone

Tam sim no cia peb hla txoj cai:

  • Hauv daim ntawv thov no, peb tau siv lub qhov rooj raug kaw kom txuag tau WiFi cov ntaub ntawv pov thawj thiab kom hla los ntawm 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 5: Tau Txais Cov Ntaub Ntawv Sensor los ntawm Wireless Kev co thiab Kub Sensor

Tau txais cov ntaub ntawv Sensor los ntawm Wireless Kev co thiab Kub Sensor
Tau txais cov ntaub ntawv Sensor los ntawm Wireless Kev co thiab Kub Sensor
Tau Txais Cov Ntaub Ntawv Sensor los ntawm Wireless Kev co thiab Kub Sensor
Tau Txais Cov Ntaub Ntawv Sensor los ntawm Wireless Kev co thiab Kub Sensor

Peb tau txais 54-byte thav duab los ntawm Wireless Kub thiab Kev Ruaj Ntseg. Cov thav duab no tau muab coj los ua kom tau qhov kub thiab txias cov ntaub ntawv.

ESP32 muaj peb UARTs muaj rau Kev Siv Serial

  1. RX0 GPIO 3, TX0 GPIO 1
  2. RX1 GPIO9, TX1 GPIO 10
  3. RX2 GPIO 16, TX2 GPIO 17

thiab 3 kho vajtse Serial chaw nres nkoj

  • Cov
  • Cov lej 1
  • Cov lej 2

Ua ntej, pib kho Hardware Serial header file. Ntawm no peb yuav siv RX2 thiab TX2 aka. GPIO 16 thiab GPIO 17 tus pin ntawm ESP32 pawg thawj coj kom tau txais cov ntaub ntawv xov xwm.

#suav nrog

# txhais RXD2 16 # txhais TXD2 17

Serial2.begin (115200, SERIAL_8N1, RXD2, TXD2); // pins 16 rx2, 17 tx2, 19200 bps, 8 khoom tsis muaj qhov sib npaug 1 nres me ntsis

Cov kauj ruam hauv qab no yuav coj koj mus ntxiv kom tau txais qhov txiaj ntsig sensor tiag

  • Tsim cov kev hloov pauv rau khaws cia qhov kub, av noo, roj teeb, thiab lwm yam txiaj ntsig ntsuas
  • Teem Rx, tx pin, baud tus nqi thiab cov khoom sib npaug rau cov khoom siv kho vajtse
  • Ua ntej, txheeb xyuas tias muaj qee yam los nyeem siv Serial1.available ()
  • Peb yuav tau txais tus ncej ntawm 54 bytes.
  • Txheeb rau 0x7E uas yog pib byte.
  • Cov ntaub ntawv kev co muaj RMS tus nqi rau 3 axis, min qhov tseem ceeb rau 3 axis, qhov tseem ceeb tshaj plaws rau 3 axis.
  • qhov ntsuas kub thiab roj teeb yuav muaj 2 bytes ntawm cov ntaub ntawv
  • tau txais lub npe sensor, hom, qhov ntsuas qhov ntsuas yuav muaj 1 byte ntawm cov ntaub ntawv thiab tuaj yeem tau txais los ntawm qhov chaw nyob

yog (Serial2.available ()) {Serial.println ("Nyeem Serial"); cov ntaub ntawv [0] = Serial2.read (); ncua (k); yog (cov ntaub ntawv [0] == 0x7E) {Serial.println ("Tau Txais Pob"); thaum (! Serial2.available ()); rau (i = 1; i <55; i ++) {data = Serial2.read (); ncua (1); } yog (cov ntaub ntawv [15] == 0x7F) /////// txhawm rau txheeb xyuas yog tias cov ntaub ntawv tau txais raug yog {yog (cov ntaub ntawv [22] == 0x08) //////// xyuas kom tseeb tias hom sensor yog qhov tseeb {rms_x = ((uint16_t) (((data [24]) << 16) + ((data [25]) << 8) + (data [26]))/100); rms_y = ((uint16_t) (((data [27]) << 16) + ((data [28]) << 8) + (data [29]))/100); rms_z = ((uint16_t) (((data [30]) << 16) + ((data [31]) << 8) + (data [32]))/100); int16_t max_x = ((uint16_t) (((data [33]) << 16) + ((data [34]) << 8) + (data [35]))/100); int16_t max_y = ((uint16_t) (((data [36]) << 16) + ((data [37]) << 8) + (data [38]))/100); int16_t max_z = ((uint16_t) (((data [39]) << 16) + ((data [40]) << 8) + (data [41]))/100);

int16_t min_x = ((uint16_t) (((data [42]) << 16) + ((data [43]) << 8) + (data [44]))/100); int16_t min_y = ((uint16_t) (((data [45]) << 16) + ((data [46]) << 8) + (data [47]))/100); int16_t min_z = ((uint16_t) (((data [48]) << 16) + ((data [49]) << 8) + (data [50]))/100);

cTemp = ((((cov ntaub ntawv [51]) * 256) + cov ntaub ntawv [52])); roj teeb ntab = ((cov ntaub ntawv [18] * 256) + cov ntaub ntawv [19]); voltage = 0.00322 * roj teeb; Serial.print ("Tus lej Sensor"); Serial.println (cov ntaub ntawv [16]); senseNumber = 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 ("RMS kev co hauv X-axis:"); Serial.print (rms_x); Serial.println ("mg"); Serial.print ("RMS kev co hauv Y-axis:"); Serial.print (rms_y); Serial.println ("mg"); Serial.print ("RMS kev co hauv Z-axis:"); Serial.print (rms_z); Serial.println ("mg");

Serial.print ("Kev co qis hauv X-axis:");

Serial.print (min_x); Serial.println ("mg"); Serial.print ("Kev co tsawg hauv Y-axis:"); Serial.print (min_y); Serial.println ("mg"); Serial.print ("Kev co tsawg hauv Z-axis:"); Serial.print (min_z); Serial.println ("mg");

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 {rau (kuv = 0; kuv <54; kuv ++) {Serial.print (cov ntaub ntawv )); Serial.print (","); ncua (1); }}}}

Kauj Ruam 6: Txuas rau AWS

Connecting to AWS
Connecting to AWS
  • Suav nrog AWS_IOT.h, WiFi.h header files teeb tsa kev sib txuas nrog AWSIoT hub
  • Nkag mus rau koj Tus Chaw Nyob, Tus Neeg Siv Khoom uas yuav yog lub npe txoj cai, thiab lub ncauj lus lub npe uas yuav yog lub npe khoom

// ********* AWS Credentials ************* // char HOST_ADDRESS = "a2smbp7clzm5uw-ats.iot.us-east-1.amazonaws.com"; char CLIENT_ID = "ncdGatewayPolicy"; char TOPIC_NAME = "ncdGatewayThing";

Tsim kom muaj tus lej sib txawv los khaws koj li JSON, qhov no, peb tau tsim hom los khaws JSON

const char *format = "{" SensorId / ": \"%d / ", \" messageId / ":%d, \" rmsX / ":%d, \" rmsY / ":%d, \" rmsZ / ":%d, \" cTemp / ":%d, \" voltage / ":%. 2f}";

Tsim qhov piv txwv ntawm chav kawm AWS_IOT

AWS_IOT esp; // Instance of AWS_IOT class

Tam sim no txuas rau AWSIoT hub siv cov hauv qab no

void reconnectMQTT () {if (hornbill.connect (HOST_ADDRESS, CLIENT_ID) == 0) {Serial.println ("Txuas rau AWS"); ncua (1000);

yog (0 == hornbill.subscribe (TOPIC_NAME, mySubCallBackHandler))

{Serial.println ("Subscribe Successfull"); } lwm {Serial.println ("Sau npe yuav ua tsis tau, Tshawb xyuas Lub Npe Lub Npe thiab Ntawv Pov Thawj"); thaum (1); }} lwm {Serial.println ("AWS txuas tsis tau, Txheeb xyuas qhov chaw nyob"); thaum (1); }

ncua (2000);

}

tshaj tawm cov ntaub ntawv sensor tom qab txhua 1 feeb

yog (zuam> = 60) // tshaj tawm rau cov ncauj lus txhua 5seconds {zuam = 0; char them nyiaj [PAYLOAD_MAX_LEN]; snprintf (payload, PAYLOAD_MAX_LEN, hom ntawv, senseNumber, msgCount ++, rms_x, rms_y, rms_z, cTemp, voltage); Serial.println (them nyiaj); yog (hornbill.publish (TOPIC_NAME, them nyiaj) == 0) {Serial.print ("Tshaj Tawm Xov Xwm:"); Serial.println (them nyiaj); } lwm {Serial.println ("Tshaj tawm ua tsis tiav"); }} vTaskDelay (1000 / portTICK_RATE_MS); zuam ++;

Kauj ruam 7: Pom cov ntaub ntawv hauv AWS

Visualizing Data in AWS
Visualizing Data in AWS
Visualizing Data in AWS
Visualizing Data in AWS
Visualizing Data in AWS
Visualizing Data in AWS
  • Nkag mus rau koj tus lej AWS.
  • nyob rau sab laug ntawm lub toolbar, koj yuav pom Cov Kev Pabcuam tab
  • Nyem rau ntawm lub tab no thiab hauv Is Taws Nem ntawm Yam Yam xaiv IoT Core.
  • Xaiv QoS thiab tsis muaj. ntawm cov lus rau cov neeg siv khoom. Sau lub ntsiab lus lub npe.

Kauj Ruam 8: Txoj Cai Tag Nrho

Koj tuaj yeem pom tag nrho cov cai ntawm no Github Repository.

Khab nias

  • Arduino Json Cov
  • Wireless Kub thiab Vaum Sensors
  • ESP32
  • PubSubClient

Pom zoo: