Cov txheej txheem:

CLOUD MONITOR With AWS & ARDUINO - Electric Boy: 6 Kauj Ruam
CLOUD MONITOR With AWS & ARDUINO - Electric Boy: 6 Kauj Ruam

Video: CLOUD MONITOR With AWS & ARDUINO - Electric Boy: 6 Kauj Ruam

Video: CLOUD MONITOR With AWS & ARDUINO - Electric Boy: 6 Kauj Ruam
Video: RemoteXY IoT Cloud Control 2024, Kaum ib hlis
Anonim
CLOUD MONITOR With AWS & ARDUINO - Electric Boy
CLOUD MONITOR With AWS & ARDUINO - Electric Boy

Nws yog ib txoj haujlwm yooj yim - tig lub teeb thaum muaj qee yam tsis raug… Ua rau cov lej nce mus rau cov ntawv ceeb toom nrog ntau lub dashboards ntawm peb lub khoos phis tawj niaj hnub no, peb yuav ua li cas thiaj paub tseeb tias peb tsis nco qhov tseem ceeb tiag tiag. Cov lus teb yog lub cev qhia qhov xwm txheej. Los yog tshwj xeeb ntxiv rau txoj haujlwm, Huab Saib Xyuas, uas tuaj yeem zaum ntawm koj lub rooj - ib txwm pom. Raws li lub npe qhia, tus saib xyuas yuav pab saib xyuas kev noj qab haus huv ntawm koj cov kev pabcuam huab (… lossis lwm yam ntxiv tiag, ntuj yog qhov txwv, thov zam txim). Txawm koj, zoo li kuv, yuav tsum ua? Txawm hais tias tsis yog, koj yuav muaj lub tswv yim rau koj li phiaj xwm IoT yav tom ntej.

Zoo, yog tias koj npaj tau, cia pib!

Kauj Ruam 1: Cov Cheeb Tsam, Cov Khoom Siv, Cov Cuab Yeej Xav Tau, Cov Ntawv Thov thiab Kev Pabcuam Online

Cov ntsiab lus thiab khoom siv

_ Arduino Micro e Genuino Micro (1 unit)… lossis ib qho me me Arduino sib xws - hauv kuv cov ntaub ntawv freetronics LeoStick (https://www.freetronics.com.au/collections/arduino/products/leostick)

_ ThingM BlinkM - I2C Tswj RGB LED (1 chav nyob)

_ Mini huab teeb (1 chav nyob) … lossis lwm lub nkoj uas koj xaiv

_ USB-A rau B Cable (1 unit)… lossis ib qho qub USB cable nrog hom-A ntsaws

Cov cuab yeej xav tau

_ Soldering hlau (generic)

APPS & ONLINE SERVICE

_ Amazon Web Services AWS Lambda (https://aws.amazon.com/it/lambda/)

_ Amazon Web Services AWS IoT (https://aws.amazon.com/it/iot/)

Kauj ruam 2: Kho vajtse

Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse

Lub teeb tsaus ntuj twb los nrog LED ua hauv - txias dawb hauv kuv rooj plaub. Kuv xav tias nws yuav zoo los qhia qhov xwm txheej sib txawv los ntawm cov xim sib txawv. Yog li kuv tsuas yog khaws cov huab zoo li casing. Txog rau lub hlwb ntawm kev ua haujlwm Kuv tau xaiv qhov tsawg tshaj plaws Arduino sib xws uas kuv muaj muaj: Freetronics LeoStick tau yog qhov kuv nyiam ua qauv tsim rau ntau xyoo thiab kuv muaj khoom txaus. Nws los nrog cov khoom zoo: tus hais lus piezo, ob lub RGB LEDs (ib qho yog khi rau lub zog, RX thiab TX tab sis) thiab qhov zoo tshaj plaws, koj tuaj yeem yooj yim ntsaws nws mus rau hauv USB chaw nres nkoj - tsis muaj FTDI sab nraud lossis kab xav tau. Nws kuj tseem me me tsis tau breadboard tau tshaj.

Vim li cas kuv thiaj tsis xaiv ESP8266? Txhawm rau ua kom muaj wireless tiag, koj kuj tseem yuav txiav lub hwj chim qaum - uas ua rau qee yam nyuaj me ntsis ntxiv rau ntxiv roj teeb thiab tsis yooj yim ntawm kev rov them dua. Txij li huab saib yuav zaum ze ntawm kuv lub khoos phis tawj nws yooj yim dua rau siv USB zog. Tsis tas li teeb tsa Wi-nkaus kev sib txuas tsis yog ib txwm ncaj ncaj rau tom ntej. Qhov ntawm ATmega32u4, Arduino Micro thiab LeoStick sib qhia qhov txawv ntawm qhov muaj I2C cov ntaub ntawv ntawm D2 thiab moos ntawm D3. Qhov no muaj feem cuam tshuam thaum txuas BlinkM RGB LED. Tsis zoo li cov ntawv Atmega328 uas koj tuaj yeem yooj yim ntsaws BlinkM daim thaiv rau hauv cov ntawv A2.. A5, qhov no yuav tsis ua haujlwm ntawm no (Kuv tsis thab nrog lub tsev qiv ntawv I2C muag).

Los ntawm desoldering tus txiv neej lub taub hau VCC thiab GND ntawm BlinkM, Kuv tuaj yeem txuas ntxiv cov uas muaj xaim thiab khaws txhua yam hauv pob ntsaws-muaj peev xwm me ntsis pob. Lub BlinkM muaj nws tus kheej micro tswj ntawm lub nkoj thiab tso cai rau cov ntawv thov siab dua: piv txwv li ua si cov ntawv xim xim yam tsis muaj Arduino txuas nrog. Kuv yuav luag zoo li WS2812 (Adafruits NeoPixels zoo heev) yuav tau pab kuv zoo dua - alas kuv tsis muaj. Txhawm rau ua kom tiav kho vajtse me ntsis, Kuv txiav qhov kawg ntawm tus txiv neej hom-A USB ntsaws, xov nws los ntawm lub qhov ua ntej qhov drilled ze ntawm lub hauv paus ntawm huab huab thiab muab cov xov txuas rau LeoStick (liab: 5V, dawb: Cov ntaub ntawv-, ntsuab: Cov ntaub ntawv+, dub: Hauv av).

Kauj Ruam 3: Kev Txhim Kho Architecture

Tshuaj Architecture
Tshuaj Architecture
Tshuaj Architecture
Tshuaj Architecture

Tsuas yog qhov yuav tsum tau muaj zog uas kuv tau ua rau kuv tus kheej, yog kom muaj lub ntsuas saib tom qab lub firewall. Txawm hais tias qhov tseem ceeb tshaj plaws, qhov no ua rau lub web hooks rau kev tshwm sim hloov pauv tsis tau. Ib lub tswv yim pov npav raug them nqi raws li TCP kev mus los thiab tej zaum yuav ncua cov xwm txheej nyob ntawm qhov kev xaiv tsa ntau zaus.

Kev daws teeb meem yog pom hauv WebSockets uas muab kev sib txuas lus duplex. Amazons IoT cov kev pabcuam muab cov lus xa xov uas txhawb nqa MQTT hla WebSockets. Raws li nws tshwm sim, cov kev pabcuam tuaj yeem hu tsis tas yuav teeb tsa Yam, Duab Ntxoo, Txoj Cai lossis Txoj Cai.

Muaj cov cuab yeej SDK muaj rau Arduino Yún thiab qee qhov kev siv zog yog ua los ntawm kev xa SDK mus rau lwm lub platform zoo li ESP8266. Tab sis vim tias tus saib xyuas ib txwm txuas nrog los ntawm kev sib txuas, kuv txiav txim siab thaum ntxov kom muaj daim ntawv thov NodeJS (khiav ntawm lub khoos phis tawj desktop) los ua tus thov API thiab siv Arduino tsuas yog tau txais thiab tso saib cov xim xim. Txoj kev hloov ntawd tuaj yeem ua tau yooj yim hauv JavaScript, yam tsis tas yuav cuam tshuam nrog kev tshaj tawm firmware. Cia peb hais tias peb muaj lub peev xwm thauj khoom tau qhib thoob plaws thaj tsam muaj uas ua kev kuaj mob rau ntawm lub web server piv txwv thiab pib ntsuas txoj cai raws CPU load. Qhov sib xws CloudFormation tus qauv tuaj yeem yog ▶ ️ saib hauv Tus Tsim lossis ▶ ️ tsim ncaj qha los ntawm lub console. Nco tseg: qee qhov kev pabcuam hauv pawg no yuav raug nqi.

Kuv txuas tus qauv nrog cov khoom rau Lambda ua haujlwm thiab kev tso cai tsim nyog. Tom qab ntawd xav tau IoT REST API qhov kawg kom tau ntxig ua qhov ntsuas. Txhawm rau siv qhov no, Kuv tau sau tsab ntawv me me uas siv CLI los thov ARN (> aws iot piav qhia-qhov kawg) thiab tom qab ntawd hu rau tsim-pawg nrog qhov ntsuas hauv kab. Lossis koj tseem tuaj yeem ua nws ntawm tes:

// RETRIVE IoT REST API ENDPOINT

aws iot description-endpoint

// CREATE STACK> aws cloudformation create-stack --stack-name MiniCloudMonitor --template-body file: //cfn-template.json --parameters ParameterKey = IotRestApiEndpoint, ParameterValue = {IoT_REST_API_ENDPOINT} --capabilities CAPABILITY_NAMED_I

// DELETE STACK> aws cloudformation delete-stack --stack-name MiniCloudMonitor

Qhov zoo tshaj kuv yuav tsum siv tib lub tswb ceeb toom uas ua rau nws pib ntsuas, rau qhov tseem hu ua Lambda ua haujlwm thiab txoj kev ntawd hloov kho qhov xwm txheej ntawm tus saib. Tam sim no qhov no tsuas yog ua tau thaum siv SNS ua ntu nruab nrab. Thaum lub sijhawm txheej txheej no zoo li tsis muaj qhov xav tau thiab kuv txiav txim siab siv CloudWatch EC2 Txoj Cai Kev Siv Lub Neej kom hu rau Lambda ncaj qha. Tseem, Kuv xav tshawb qhov kev xaiv ntawm SNS → Lambda yav tom ntej.

Kauj ruam 4: Software

Kuv pib los ntawm kev sau Arduino Sketch. Lub voj tseem ceeb () yog nyeem Chars los ntawm kev txuas txuas thiab tsim txoj hlua kom txog thaum nws tau txais tus cim tshiab. Nws yog tom qab ntawd xav tias tus lej xim hex tau xa thiab qhov tsim nyog I2C hais kom sau rau BlinkM LED. Qhov no tsis yog ntau txog kev ua haujlwm raws li kev yooj yim. Cov peev txheej ua tiav rau Sketch thiab lwm cov ntaub ntawv tuaj yeem tau txais ntawm GitHub. Nram qab no yog qee qhov piv txwv cov ntsiab lus tseem ceeb:

void voj () {

thaum (Serial.available ()) {

char inChar = (char) Serial.read ();

yog (inChar == '\ n') {

tus lej ntev = strtol (inputString.c_str (), NULL, 16);

byte r = tus lej >> 16;

byte g = tus lej >> 8 & 0xFF;

byte b = tus lej & 0xFF;

BlinkM_fadeToRGB (blinkm_addr, r, g, b);

inputString = "" cov ntaub ntawv;

lwm yam {

inputString += inChar;

}

}

}

NodeJS App yuav tsum siv kev cuam tshuam rau AWS thiab Arduino. Tom qab tuaj yeem ua tiav hauv tsuas yog ob peb kab ntawm cov cai thaum siv cov ntawv ntim khoom ntim zoo heev:

var serialport = xav tau ('serialport'); chaw nres nkoj = tshiab serialport (PORT_COM_NAME, {

baudRate: SERIAL_BAUD_RATE

});

port.on ('qhib', muaj nuj nqi () {

});

port.on ('yuam kev', muaj nuj nqi (yuam kev) {

});

Txuas mus rau AWS IoT xav tau kev siv zog ntau heev ib yam. Tsuas yog qhov tsis zoo yog paub tias siv MQTT+WebSockets hla chaw nres nkoj 443 xav tau kev lees paub los ntawm Access Keys. SDK yuav nyeem cov no los ntawm qhov hloov pauv ib puag ncig. Tej zaum nws yuav tsim nyog kom xa tawm AWS_ACCESS_KEY_ID thiab AWS_SECRET_ACCESS_KEY.

var awsiot = require ('aws-iot-device-sdk'); var device = awsiot.device ({

clientId: 'MiniCloudMonitor-' + (Math.floor ((Math.random () * 100000) + 1)), region: AWS_REGION, raws tu qauv: 'wss', chaw nres nkoj: 443, debug: muaj tseeb

});

device.on ('txuas', muaj nuj nqi () {

device.subscribe (MQTT_TOPIC);

});

device.on ('lus', ua haujlwm (ncauj lus, them nyiaj) {

yog (chaw nres nkoj && them nyiaj && npe == MQTT_TOPIC) {

var lus = JSON.parse (payload);

yog (message.hasOwnProperty (MQTT_JSON_KEY))

{rov qab;

}

}

});

Lambda ua haujlwm lees paub cov xim xim ua qhov ntsuas ntsuas - tsis zoo nkauj, tab sis hloov pauv tau zoo nyob rau theem no. Yuav kom tuaj yeem tshaj tawm rau MQTT cov ncauj lus, nws ua kom nrawm rau IotData cov khoom, uas xav tau IoT REST API qhov kawg. CloudFormation tus qauv tau saib xyuas qhov ntawd thaum tsim cov pawg.

var AWS = require ('aws-sdk'); var mqtt = new AWS. IotData ({

qhov kawg: process.env. MQTT_ENDPOINT});

export.handler = muaj nuj nqi (xwm txheej, ntsiab lus, hu rov qab) {

var cov = {

ntsiab lus: process.env. MQTT_TOPIC, payload: '{ "xim \": / "' + event.colour + '\"}', qog: 0

};

mqtt.publish (params, muaj nuj nqi (yuam kev, cov ntaub ntawv) {

callback (yuam kev);

});

};

Kauj Ruam 5: Xaus

Kuv zoo siab tiag tiag coj qhov tshwm sim virtual "yug" hauv huab rau hauv lub ntiaj teb lub cev. Thiab raws li kuv txoj haujlwm tsiaj me nws tau lom zem heev. Txhawm rau coj mus rau qib tom ntej Kuv yuav xav txog …

  • txhim kho kev ruaj ntseg thiab kev zam tshwj xeeb
  • tshawb nrhiav txoj hauv kev zoo dua los koom ua ke AWS huab cua ntsuas
  • sim nrog ntau lub cev ntsuas xws li ntsuas, ntsuas kab, …
  • muaj kev xaiv txav mus rau lwm lub platform xws li Azure, Google, Heroku,…
  • saib xyuas cov xwm txheej tshwj xeeb rau Jenkins, GitHub,…

Kuv vam tias koj nyiam nyeem phau ntawv qhia no thiab tej zaum txawm tias khaws qee yam tshiab los ntawm txoj kev. Yog tias koj tuaj yeem xav txog txoj hauv kev sib txawv/zoo dua los ua tej yam thov qhia nws hauv cov lus hauv qab no. Thiab ntawm chav kawm, yog tias koj pom qhov ua yuam kev lub taub hau yuav zoo siab heev. Ua tsaug rau koj lub sijhawm.

Pom zoo: