Cov txheej txheem:

Kev Saib Xyuas Txoj Kev: 15 Kauj Ruam
Kev Saib Xyuas Txoj Kev: 15 Kauj Ruam

Video: Kev Saib Xyuas Txoj Kev: 15 Kauj Ruam

Video: Kev Saib Xyuas Txoj Kev: 15 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Txoj Kev Saib Xyuas
Txoj Kev Saib Xyuas

Hnub no peb yuav qhia koj li cas peb teeb tsa txoj kev tsis xws luag raws li kev ntsuas nrawm, LoRaWAN, Amazon Web Services thiab Google Cloud API.

Kauj ruam 1: Yuav tsum tau ua

  • DISCO-L072CZ-LRWAN1 pawg thawj coj saib
  • X-NUCLEO-IKS01A2 nthuav dav nthuav dav (rau lub ntsuas cua)
  • X-NUCLEO-GNSS1A1 (rau kev hloov chaw)
  • AWS account
  • Tus lej Google Cloud Platform

Kauj Ruam 2: Txhim kho thiab ua kom pom lub Sensor's Firmware

Txuas IKS01A2 thiab GNSS1A1 nyob rau sab saum toj ntawm lub rooj tsavxwm los ntawm GPIO pins. Rub lub firmware tus lej los ntawm GitHub. Tsim (yog tias koj tsis muaj ib qho) tus as khauj ntawm ARM Mbed thiab ntshuam cov cai hauv repo ntawm online compiler. Teem lub hom phiaj platform rau DISCO-L072CZ-LRWAN1 thiab txuag txoj haujlwm. Tam sim no lub taub hau rau Cov Khoom Network thiab tsim ib tus as khauj yog tias koj tsis muaj nws lawm. Tsim daim ntawv thov, tsim cov cuab yeej tshiab hauv daim ntawv thov thiab teeb tsa hom kev sib txuas rau OTAA. Lob qhov tsis tsim nyog los ua cov hauv qab no hauv kab ntawv mbed_app.json: "lora.appskey", "lora.nwkskey", "lora.device-address".

Lub ntsuas yuav ntsuas cov ntaub ntawv ntsuas thiab GNSS cov ntaub ntawv ib ntus thiab xa lawv los ntawm LoRa kev txuas mus rau lub qhov rooj ze tshaj, uas yuav xa lawv mus rau peb daim ntawv thov ntawm Cov Khoom Network. Cov kauj ruam tom ntej yog teeb tsa huab server, thiab kev koom ua ke HTTP ntawm TTN.

Kauj Ruam 3: Teeb Huab

Teeb Huab
Teeb Huab

Tam sim no peb tau npaj los teeb tsa cov txheej txheem huab uas yuav sau thiab sib sau cov ntaub ntawv los ntawm txhua lub rooj xa ntawv. Cov txheej txheem no tau qhia hauv daim duab hauv qab no thiab nws tau tsim los ntawm:

  • Kinesis, los daws cov ntaub ntawv nkag mus;
  • Lambda, txhawm rau lim thiab npaj ua ntej cov ntaub ntawv ua ntej khaws cia;
  • S3, khaws tag nrho cov ntaub ntawv;
  • EC2, txhawm rau txheeb xyuas cov ntaub ntawv thiab tuav peb lub hauv ntej-kawg.

Kauj Ruam 4: Teeb tsa AWS Lambda

Setup AWS Lambda
Setup AWS Lambda

Peb yuav piav qhia cov kauj ruam tsim nyog los teeb tsa cov txheej txheem no, pib nrog Lambda.

  1. Nkag mus nrog koj tus lej AWS, thiab los ntawm console nplooj ntawv tseem ceeb thiab mus rau Lambda
  2. Nyem rau Tsim Cov Haujlwm
  3. Nyob rau sab saud ntawm nplooj ntawv nws yuav tsum raug xaiv Tus Sau los ntawm Kos. Tom qab ntawd ua tiav lwm cov haujlwm raws li hauv daim duab thiab tom qab ntawd nyem Tsim Ua Haujlwm
  4. Tam sim no koj tau tsim AWS Lambda ua haujlwm, mus rau https://github.com/roadteam/data-server thiab luam cov ntsiab lus ntawm aws_lambda.py cov ntaub ntawv rau hauv cov editor uas koj pom ib nrab ntawm nplooj ntawv. Koj li haujlwm Lambda tam sim no tau npaj lawm:)

Kauj Ruam 5: Teeb AWS Kinesis Firehose Data Stream

Teem AWS Kinesis Firehose Data Stream
Teem AWS Kinesis Firehose Data Stream
  1. Rov qab tam sim no rau AWS console nplooj ntawv tseem ceeb, thiab hauv Cov Kev Pabcuam mus rau Kinesis
  2. Tam sim no koj nyob hauv nplooj ntawv tseem ceeb ntawm Kinesis. Ntawm sab xis ntawm nplooj ntawv, hauv qab 'Kinesis Firehose xa cov kwj dej', xaiv 'Tsim cov kwj xa tshiab'
  3. Hauv 'Kev xa npe lub npe' sau 'txoj kev-saib xyuas-kwj'. Tawm ntawm lwm qhov chaw mus rau qhov tsis raug thiab nyem tom ntej
  4. Tam sim no nyob rau hauv 'Hloov pauv cov ntaub ntawv nrog AWS Lambda' xaiv Enabled, thiab raws li Lambda ua haujlwm nyem rau ntawm qhov tsim tshiab 'txoj kev-saib xyuas-lambda'. Tsis txhob txhawj xeeb yog tias muaj lus ceeb toom txog lub sijhawm ua haujlwm tshwm tuaj, vim tias kev ua haujlwm uas peb tab tom ua tsis raug suav nrog. Tawm ntawm lwm qhov chaw mus rau qhov tsis raug thiab nyem tom ntej
  5. Raws li lub hom phiaj xaiv Amazon S3, thiab raws li S3 lo lus xaiv xaiv Tsim Tshiab. Raws li lub npe thoob nkag mus 'txoj kev-saib xyuas-thoob' thiab tom qab ntawd mus. Tam sim no tawm ntawm lwm qhov chaw rau lub neej ntawd thiab nyem Tom ntej
  6. Koj tuaj yeem xav teeb tsa Qhov Loj rau 1MB thiab Lub Sij Hawm Tsis pub dhau 60 vib nas this. Qhov tsis tuaj yeem yuav yaug mus rau S3 thaum twg ib qho ntawm ob qhov xwm txheej txaus siab. Tsis txhob tawm ntawm nplooj ntawv, saib cov kauj ruam tom ntej

Kauj Ruam 6: Teeb IAM Txoj Haujlwm rau Kinesis

Teeb IAM Txoj Haujlwm rau Kinesis
Teeb IAM Txoj Haujlwm rau Kinesis

Tam sim no peb teeb tsa kev tso cai kev nyab xeeb rau Kinesis, txij li nws yuav tsum hu rau Lambda ua haujlwm rau kev npaj ua ntej thiab tom qab ntawd nws yuav sau rau ntawm S3

  1. Hauv qab ntawm nplooj ntawv uas koj nyob hauv 'IAM lub luag haujlwm' xaiv 'Tsim tshiab ntawm kev xaiv', tsim lub luag haujlwm IAM tshiab raws li hauv daim duab thiab nyem Cia
  2. Tam sim no koj tau rov qab mus rau nplooj ntawv dhau los, nyem tom ntej. Tam sim no koj tuaj yeem xav ntsuas ob zaug txhua qhov ntsuas. Thaum ua tiav nyem rau ntawm 'Tsim Kev Xa Dej'

Cov kav dej Kinesis-Lambda-S3 tab tom tab tom ua haujlwm!

Kauj Ruam 7: Teeb tsa AWS EC2

Setup AWS EC2
Setup AWS EC2

Tam sim no peb yuav teeb tsa ib qho piv txwv EC2 nrog qee qhov API uas yuav tso cai rau peb thawb thiab rub cov ntaub ntawv los ntawm AWS huab thiab tseem yog lub server rau qhov twg los tuav peb daim ntawv thov. Hauv kev tsim khoom ib puag ncig, koj yuav xav tshaj tawm API siv qhov ntau ntxiv AWS API Gateway.

  1. Los ntawm AWS console nplooj ntawv tseem ceeb, mus rau EC2 kev pabcuam
  2. Nyem rau Launch Instance
  3. Hauv qhov tshawb nrhiav sab sau muab tus lej no: 'ami-08935252a36e25f85', uas yog tus lej cim ntawm lub tshuab ua ntej tau teeb tsa ua ntej siv. Nyem Xaiv ntawm sab xis
  4. Xaiv t2.micro los ntawm kab ntawv 'Hom' thiab nyem 'Tshawb xyuas thiab tso tawm'. Tsis txhob tso qhov piv txwv tsis tau, mus rau kauj ruam tom ntej

Kauj Ruam 8: Teeb IAM Kev Ruaj Ntseg Ruaj Ntseg rau EC2

Teeb IAM Kev Ruaj Ntseg Ruaj Ntseg rau EC2
Teeb IAM Kev Ruaj Ntseg Ruaj Ntseg rau EC2
  1. Ua ntej tshaj tawm peb xav hloov kho pawg neeg ruaj ntseg ntawm peb qhov piv txwv. Txhawm rau ua qhov no, nyob rau sab xis ntawm ntu 'Pawg Pawg Ruaj Ntseg' nyem 'Kho kom raug pawg ruaj ntseg' teeb tsa pab pawg ruaj ntseg tshiab raws li hauv qab no. Qhov no pib teeb tsa lub firewall ntawm koj qhov piv txwv nthuav tawm chaw nres nkoj 22 rau SSH kev txuas thiab chaw nres nkoj 80 rau http cov kev pabcuam
  2. Nyem dua 'Tshawb xyuas thiab Tua tawm'. Tam sim no xyuas tias txhua qhov ntsuas tau teeb tsa. Thaum ua tiav nyem Launch
  3. Nyem rau ntawm lub qhov rai tshiab yuav tshwm tuaj teeb tsa tus yuam sij khub rau ssh txuas nrog rau qhov piv txwv. Xaiv 'Tsim tus yuam sij tshiab' thiab raws li lub npe nkag 'ec2-txoj kev-saib xyuas'. Nyem Download tus yuam sij khub. Nws yog ib qho tseem ceeb heev uas cov ntaub ntawv no ploj lossis (zuj zus) tau khaws cia yam tsis muaj kev nyab xeeb: koj yuav tsis tuaj yeem rub tus yuam sij ntxiv. Thaum rub tawm qhov tseem ceeb.pem piv txwv yog npaj los pib

Kauj Ruam 9: Nkag Mus Rau Koj Li EC2

Nkag Mus Rau Koj Tus Txheej Txheem EC2
Nkag Mus Rau Koj Tus Txheej Txheem EC2

Koj qhov piv txwv EC2 tshiab tau nce hauv AWS huab. Koj tuaj yeem txuas rau nws nrog cov ntaub ntawv tseem ceeb rub tawm ua ntej (rau qhov kev qhia no peb xav tias koj paub qhov pib ntawm ssh). Koj tuaj yeem khaws qhov piv txwv IP los ntawm kev xaiv nws hauv lub dashboard hauv ntu 'Nqe lus piav qhia' raws li hauv qab no: Koj tuaj yeem siv ob qho tib si koj tus IP lossis koj tus pej xeem DNS nws zoo ib yam. Nrog tus neeg siv ssh tam sim no nkag mus rau cov lus txib:

ssh -i ec2-road-monitoring.pem ec2-user@YOUR-IP-ADDR-OR-DNS

qhov twg ec2-txoj kev-xyuas.pem yog koj qhov tseem ceeb tsim ua ntej.

Tam sim no npaj mus rub tus server-sab chaws hla

git clone-ua tau zoo

Kauj ruam 10: Rov qab Google Maps API

Rov qab tau Google Maps API
Rov qab tau Google Maps API

Peb yuav luag tiav. Tam sim no peb yuav tsum teeb tsa google maps API hauv peb nplooj ntawv html txhawm rau nthuav qhia daim ntawv qhia nrog cov ntsiab lus rau cov neeg siv:

  1. Nkag mus rau koj tus lej Google thiab mus rau
  2. Nyem rau 'Pib Pib' nyob rau sab laug ntawm nplooj ntawv
  3. Xaiv 'Maps' hauv cov ntawv qhia zaub mov thiab tom qab ntawd nyem txuas ntxiv
  4. Raws li lub npe project nkag mus rau 'txoj kev saib xyuas' thiab nyem Next
  5. Sau koj cov ntaub ntawv them nqi thiab nyem Txuas ntxiv
  6. Tam sim no koj txoj haujlwm tau npaj tiav thiab peb yuav tau txais tus lej API los ntawm txhaj rau APIs & Cov Kev Pabcuam -> Ntawv Pov Thawj

Kauj ruam 11: Launch Server

Tua neeg rau zaub mov
Tua neeg rau zaub mov

Thiab nyob ntawd nws yog koj tus lej API. Qhov kawg koj yuav tsum tau ua yog mus rau data_visualization/anomalies_map.html thiab luam koj tus yuam sij mus rau qhov kawg ntawm cov ntaub ntawv zoo li, hloov 'KOJ-KEY-HERE'

Tam sim no txhua yam tau teeb tsa thiab npaj mus! Txhawm rau kom nws pib ua haujlwm hauv EC2 piv txwv: 'cd data-server' 'python flask_app.py'

Nkag mus rau hauv koj tus browser lub ip lossis dns chaw nyob ntawm koj li EC2 piv txwv, koj yuav tsum pom daim ntawv qhia tsis sib xws nrog qee cov ntaub ntawv dag

Kauj Ruam 12: Ua HTTP Kev Sib Koom ntawm Cov Khoom Network

Ua HTTP Kev Sib Koom ntawm Cov Khoom Network
Ua HTTP Kev Sib Koom ntawm Cov Khoom Network

Tam sim no peb muaj txhua qhov kev txhawb nqa rov qab thiab ua haujlwm peb tuaj yeem ua tiav los ua HTTP kev koom ua ke.

  1. Tsim daim ntawv thov tshiab thiab sau npe koj lub cuab yeej. Peb xav tias kev paub pib ntawm TTN, yog tias tsis xa mus rau phau ntawv qhia pib sai
  2. Hauv koj daim ntawv thov zaub mov xaiv 'Kev Sib Koom' thiab tom qab ntawd 'ntxiv kev koom ua ke'
  3. Xaiv HTTP kev koom ua ke
  4. Nkag mus rau cov teb tom qab daim duab thiab hloov pauv nrog koj li EC2 ip lossis pej xeem DNS

Kauj Ruam 13: Ua Cov Ntaub Ntawv

Rau txhua qhov tuple ntawm cov ntaub ntawv T sau los ntawm lub ntsuas koj yuav tsum ua cov hauv qab no:

  1. Tau txais cov txheej tuples uas muaj GPS tswj hwm poob hauv thaj tsam ntawm T. Hauv cheeb tsam hauv cheeb tsam yog txhua qhov tuples uas yog 100 metres ncig T.
  2. Rau txhua qhov nyob ze tuple N laij cov xwm txheej ntawm tus accelerometer Z-axis hauv N. Hauv pseudocode: mean = sum ([x. Z_accel ** 2 rau x nyob ze]) / near.size
  3. Suav tus qauv sib npaug sib txawv. Hauv pseudocode: std = sum ([(x. Z_accel ** 2 - txhais tau) ** 2 rau x nyob ze])
  4. Cov zis hauv hom ntawv no: lat, ntev, Z_accel ** 2, txhais tau tias, std

Txhawm rau suav thaj tsam hauv zos siv GPS nrug deb li cas hauv metres. Hauv C ++:

#define D2R (M_PI / 180.0)

#define EARTH_RAY 6371 ob npaug nrug (ob lat1, ob zaug ntev 1, ob lat2, ob zaug ntev2) {ob dlong = (long2 - long1) * D2R; ob dlat = (lat2 - lat1) * D2R; ob a = pow (sin (dlat/2.0), 2) + cos (lat1 * D2R) * cos (lat2 * D2R) * pow (sin (dlong/2.0), 2); ob npaug c = 2 * atan2 (sqrt (a), sqrt (1-a));

Tam sim no, siv cov ntaub ntawv nruab nrab uas tsim tawm hauv cov kauj ruam dhau los, txheeb xyuas qhov tsis sib xws thiab ua qhov tsis paub qab hau kev siv qhov kev txiav txim siab no siv rau txhua kab:

kab = daim ntawv qhia (ntab, line.split (","))

v = kab [2] txhais tau tias = kab [3] std = kab [4] yog v (txhais + std*3): yog v (txhais + std*2): yog v (txhais + std): o.append ([1, kab [0], kab [1]) lwm: o.append ([2, kab [0], kab [1]) lwm: o.append ([3, kab [0], kab [1]))

Qhov tsis xws luag raug cais los ntawm kev siv 68-95-99.7 txoj cai

Tam sim no koj muaj kev sau nrog hom ntawv no [hom, lat, ntev].

Lub ntsiab lus hom yog cov hauv qab no:

  1. Me ntsis anomaly, tej zaum tsis muaj feem cuam tshuam
  2. Qhov nruab nrab qhov txawv txav
  3. Qhov tsis txaus ntseeg

Kauj Ruam 14: Pom kev

Pom kev
Pom kev

Txhawm rau nkag siab thiab tej zaum hloov pauv qhov pom kev peb yuav tsum kawm paub siv tus cim kev cai, tus yam ntxwv ntawm Google Maps API

Ua ntej, daim ntawv qhia yuav tsum tau pib ua hauv kev hu rov qab:

muaj nuj nqi initMap () {

cov ntaub ntawv = queryData (); map = new google.maps. Map (document.getElementById ('map'), {zoom: 15, center: {lat: data [0] [1], lng: data [0] [2]}}); lus (); }

Qhia lub npe ntawm qhov kev hu rov qab hauv qhov url (peb tso rau ntawm no ua ntej peb tus lej API) hauv HTML tag:

tsab ntawv async defer src = "https://maps.googleapis.com/maps/api/js?key=[KEY]&callback=initMap"

Lub cim tuaj yeem tso rau hauv daim duab qhia chaw thaum tsim cov khoom:

google.maps. Marker tshiab ({txoj haujlwm: {lat: LATITUDE, lng: LONGITUDE}, daim ntawv qhia: daim duab qhia chaw, cim: "/path/to/icon.png"})

Koj tuaj yeem pom hauv cov cai uas rau txhua cov ntaub ntawv hauv cov ntaub ntawv ntawm qhov tsis sib xws lub cim tau muab ntxig (saib cov lus hais () muaj nuj nqi) thiab lub cim yog ua raws ntawm chav kawm ntawm qhov tsis xws luag. Thaum khiav qhov no mus rau qhov browser peb tuaj yeem tshawb xyuas daim ntawv qhia chaw uas qhov txawv txav tuaj yeem raug lim siv lub npov, raws li pom hauv daim duab.

Kauj Ruam 15: Khab nias thiab Txuas Sab Nraud

Txoj haujlwm no yog tsim los ntawm Giovanni De Luca, Andrea Fioraldi thiab Pietro Spadaccino, thawj xyoo MSc hauv Engineering hauv Computer Science cov tub ntxhais kawm ntawm Sapienza University of Rome.

  • Xaub cov kws sau ntawv siv los nthuav qhia qhov pov thawj ntawm lub tswvyim no:

    www.slideshare.net/PietroSpadaccino/road-m…

  • GitHub repos nrog txhua tus lej:

    github.com/roadteam

Pom zoo: