Cov txheej txheem:

Tsim Huab Cua Dashboard Siv Tsaus Ntuj API: 5 Kauj Ruam (nrog Duab)
Tsim Huab Cua Dashboard Siv Tsaus Ntuj API: 5 Kauj Ruam (nrog Duab)

Video: Tsim Huab Cua Dashboard Siv Tsaus Ntuj API: 5 Kauj Ruam (nrog Duab)

Video: Tsim Huab Cua Dashboard Siv Tsaus Ntuj API: 5 Kauj Ruam (nrog Duab)
Video: Playful Kiss - Playful Kiss: Full Episode 1 (Official & HD with subtitles) 2024, Kaum ib hlis
Anonim
Image
Image

Tsaus Ntuj tshwj xeeb hauv kev kwv yees huab cua thiab pom kev. Qhov txias tshaj ntawm Tsaus Ntuj yog lawv cov huab cua API uas peb tuaj yeem siv los khaws cov ntaub ntawv huab cua los ntawm yuav luag txhua qhov chaw hauv ntiaj teb. Nws tsis yog tsuas yog huab cua los nag lossis tshav ntuj tab sis qhov kub, qhov dej nag, cua hlob, av noo, nag lossis daus, siab, ntsuas UV, thiab ntau ntxiv, txhua qhov yooj yim muaj rau txhua qhov chaw koj xav tau, thaum twg koj xav tau.

Cia peb kawm paub siv Dark Sky's super-simple API. Yog tias koj tshiab los siv API's Kuv cog lus rau koj tias qhov no yuav yooj yim heev! Thiab yog tias koj tau siv API's ua ntej ntawd kuv vam tias peb tuaj yeem qhia koj yam tshiab nrog cov cai uas peb tau siv.

Yam koj yuav xav tau rau qhov haujlwm no:

  • Tsaus Ntuj API tus account
  • Thawj Xeev tus as khauj
  • Raspberry Pi lossis Laptop

Kauj ruam 1: Pib

Peb twb tau tso ntau txoj haujlwm ua haujlwm rau koj tso cov cai ua ke thiab npaj cov ntaub ntawv. Peb tsuas yog xav kom koj hloov kho ob peb txoj kev. Yog tias koj xav tau qhov nyuaj me ntsis ua qee qhov hloov pauv rau peb cov cai thiab cov ntaub ntawv huab cua tau xa mus, muaj peev xwm txwv tsis tau!

Txhawm rau khaws txhua yam uas peb tau npaj rau koj, koj yuav tsum tau clone lub chaw cia khoom los ntawm GitHub. GitHub yog qhov kev pabcuam uas tso cai rau peb khaws, tshuaj xyuas, thiab tswj cov haujlwm zoo li no. Koj yuav xav khiav tsab ntawv no ntawm lub cuab yeej tshwj xeeb. Raspberry Pi yog qhov kev xaiv zoo tshaj plaws los khiav daim ntawv thov zoo li cov ntawv qhia no.

Txhawm rau clone lub chaw cia khoom txhua yam peb yuav tsum tau ua yog mus rau hauv peb lub davhlau ya nyob twg Pi, lossis koj lub khoos phis tawj davhlau ya nyob twg uas yog SSH'd rau hauv koj tus pi thiab ntaus cov lus txib no:

$ git clone

Ntaus nkag mus thiab koj yuav pom cov ntaub ntawv no:

Cloning rau hauv 'darksky'…

tej thaj chaw deb: Suav cov khoom: 2, ua tiav. tej thaj chaw deb: Tag nrho 2 (delta 0), rov qab siv 0 (delta 0), ntim rov qab siv dua 2 Cov khoom ntim: 100% (2/2), ua tiav. Txheeb xyuas kev sib txuas … ua tiav.

Thaum koj pom qhov no ces ua kev zoo siab, koj tau ua tiav cloned GitHub Repo thiab muaj tag nrho cov ntaub ntawv tsim nyog los tsim txoj haujlwm no. Ua ntej peb txav mus rau cov kauj ruam tom ntej, cia peb siv sijhawm los tshawb nrhiav ib puag ncig phau ntawv no thiab kawm ob peb nqe lus txib yooj yim.

Ntaus cov lus txib hauv qab no rau hauv koj lub davhlau ya nyob twg:

$ ls os

Cov lus txib no teev txhua yam uas muaj nyob hauv phau ntawv teev npe uas koj nyob tam sim no. Cov npe no qhia tau tias peb GitHub Repo tau ua tiav ua tiav rau hauv peb cov npe hauv qab lub npe "darksky." Cia peb saib seb dab tsi hauv phau ntawv teev npe ntawd. Txhawm rau txav mus rau cov npe, txhua yam koj yuav tsum tau ua yog ntaus "cd" thiab tom qab ntawd ntaus lub npe ntawm cov npe uas koj xav mus.

Hauv qhov no, peb yuav ntaus:

$ cd tsaus ntuj

Thaum peb ntaus nkag mus, koj yuav pom tias tam sim no peb nyob hauv phau ntawv teev npe darksky. Cia peb ntaus "ls" dua kom pom cov ntaub ntawv twg peb tau teeb tsa ntawm peb tus pi.

README.md darksky.py…

Ntawm no peb pom qhov peb tau txais peb cov ntawv nyeem thiab cov ntaub ntawv nab nab. Cia peb saib ntawm darksky.py siv "nano" hais kom ua. Cov lus txib nano tso cai rau peb qhib nano ntawv kho qhov twg peb muaj tag nrho peb cov nab npawb nab npawb rau txhua ntu ntawm txoj haujlwm no. Mus tom ntej thiab ntaus:

$ nano darksky.py

Ntawm no koj tuaj yeem pom tag nrho cov cai peb tau npaj rau koj rau txoj haujlwm no. Peb yuav tsis hloov pauv rau cov ntaub ntawv no tseem tsis tau tiav, tab sis xav tias muaj kev ywj pheej mus ncig thiab pom dab tsi peb yuav ua tom qab hauv qhov kev qhia no.

Kauj ruam 2: Siv Dark Sky API

Lub Xeev Thawj
Lub Xeev Thawj

Txhawm rau siv Dark Sky API, koj xub xav tau koj tus lej API. Tsis txhob txhawj xeeb, tau txais tus lej API nrawm thiab dawb. Txhua yam koj yuav tsum tau ua yog mus rau lub vev xaib thiab nyem "Sim dawb" los tsim tus as khauj.

  • Koj tau txais 1, 000 API hu dawb txhua hnub. Txhua qhov API thov hla tus nqi pub dawb txhua hnub $ 0.0001.
  • Qhov kev txwv no yuav rov pib dua txhua hnub thaum ib tag hmo UTC.
  • Kev Thov Huab Cua yuav rov qab qhia huab cua tam sim no rau lub lim tiam tom ntej.
  • Lub Sijhawm Tshuab Thov rov qab saib xyuas lossis kwv yees huab cua rau hnub tim yav dhau los lossis yav tom ntej.

Koj qhov kev tsaus ntuj Sky API tus yuam sij yuav zoo li no: 0123456789abcdef9876543210fedcba.

Koj tuaj yeem ua tus API hu rau Dark Sky los ntawm kev ntaus tus URL rau hauv koj tus browser hauv hom ntawv hauv qab no:

api.darksky.net/forecast/[keyownload/[latitude], [longitude]

Hloov "tus yuam sij" nrog koj tus Tsaus Ntuj API qhov tseem ceeb thiab ntev/latitude nrog txhua yam koj xav tau. Koj tuaj yeem pom koj qhov ntev thiab latitude los ntawm kev mus rau Google Maps thiab tshawb nrhiav koj qhov chaw. Cov txiaj ntsig ntawd yuav nyob hauv qhov URL. Luam thiab muab tso rau saum ntuj tsaus ntuj URL nrog koj tus yuam sij nkag thiab qhov tseem ceeb ntxiv rau hauv qhov chaw nyob bar.

Thaum koj ua qhov ntawd koj yuav pom qee yam zoo li no:

hnub "," ze tshaj plaws StormDistance ": 57," ze tshaj plaws StormBearing ": 15," precipIntensity ": 0," precipProbability ": 0," kub ": 53.9," pom tseeb ": 53.9," dewPoint ": 29.59," av noo ": 0.39, "siab": 1022.45, "windSpeed": 3.87, "windGust": 9.25, "windBearing": 259, "cloudCover": 0.01, "uvIndex": 3, "visibility": 7.8, "ozone": 309.71}, "maj mam": {"ntsiab lus": "Ntshiab rau lub sijhawm.", "cim": "hnub ntshiab", "cov ntaub ntawv": [{"sijhawm": 1550615280, "precipIntensity": 0, "precipProbability": 0 }, Ib…

Nws tuaj yeem nyuaj me ntsis thiab nyuaj rau nyeem yog li qhov kuv pom zoo ua yog siv JSON Formatter los pab ua kom cov ntaub ntawv nyeem tau ntau dua. Thaum koj ua qhov no nws yuav zoo li qhov no:

khoom {9}

latitude: 37.8267 longitude: -122.4233 timezone: America/Los_Angeles tam sim no {19} lub sijhawm: 1550615286 cov ntsiab lus: Ntshiab lub cim: ntshiab -hnub nyob zeStormDistance: 57 ze tshaj plaws StormBearing: 15 nag lossis daus: 0 precipProbability: 0 kub: 53.9 pom tseeb Kub: 53.9 dewPoint: 29.59 av noo 0.39 siab: 1022.45 cuaSpeed: 3.87 cua Gust: 9.25 cua Bearings: 259 huabCover: 0.01 uvIndex: 3 pom kev: 7.8 ozone: 309.71

Koj nyuam qhuav ua tus API hu! Pom yooj yim npaum li cas? Koj tsis tas yuav tsum sau ib kab nkaus xwb. Tam sim no koj tau kawm tiav API's peb tuaj yeem txav mus rau cov ntaub ntawv tshaj tawm ib feem.

Kauj Ruam 3: Thawj Xeev

Peb xav kom tshaj tawm tag nrho peb cov ntaub ntawv huab cua mus rau huab kev pabcuam thiab muaj qhov kev pabcuam ntawd tig peb cov ntaub ntawv mus rau hauv lub dashboard zoo uas peb tuaj yeem nkag tau los ntawm peb lub khoos phis tawj lossis lub xov tooj ntawm tes. Peb cov ntaub ntawv xav tau lub hom phiaj. Peb yuav siv Thawj Lub Xeev raws li lub hom phiaj ntawd.

Kauj Ruam 1: Sau npe rau Tus Thawj Xib Fwb Hauv Xeev

Mus rau https://iot.app.initialstate.com thiab tsim tus as khauj tshiab. Koj tau txais 14 hnub kev sim pub dawb thiab txhua tus neeg nrog edu email chaw nyob tuaj yeem tso npe rau txoj kev npaj kawm dawb.

Kauj ruam 2: Nruab ISStreamer

Txhim Kho Thawj Lub Xeev Python module rau koj li Raspberry Pi. Hauv qhov hais kom ua, khiav cov lus txib hauv qab no:

$ cd/home/pi/$ / curl -sSL https://get.initialstate.com/python -o -| sudo tsoo

Kauj Ruam 3: Ua qee AutomagicAfter Kauj Ruam 2 koj yuav pom qee yam zoo ib yam li cov hauv qab no tso rau ntawm qhov screen:

pi@raspberrypi ~ $ / curl -sSL https://get.initialstate.com/python -o -| sudo bashPassword: Pib ISStreamer Python Yooj Yim Txhim Kho! Qhov no yuav siv ob peb feeb los teeb tsa, rub qee lub kas fes:) Tab sis tsis txhob hnov qab rov qab los, Kuv yuav muaj lus nug tom qab! Pom yooj yim_install: setuptools 1.1.6 Pom pip: pip 1.5.6 los ntawm /Library/Python/2.7/site-packages/pip-1.5.6- py2.7.egg (sej 2.7) pip loj version: 1 pip me me version: 5 ISStreamer pom, hloov kho… Yuav tsum tau hloov kho tshiab tas li: ISStreamer hauv /Library/Python/2.7/site-packages Tu tu… Koj puas xav tau automagically tau txais ib qho piv txwv tsab ntawv? [y/N] Koj xav khaws qhov piv txwv nyob qhov twg? [lub neej ntawd:./is_example.py] Thov xaiv qhov Xeev Lub Xeev app uas koj siv: 1. app.initialstate.com 2. [TSHIAB!] iot.app.initialstate.com Nkag mus xaiv 1 lossis 2: Nkag mus rau iot.app.initialstate.com tus neeg siv lub npe: Nkag mus rau iot.app.initialstate.com lo lus zais:

Thaum nug yog tias koj xav tau automagically tau txais ib qho piv txwv tsab ntawv muab "y" rau yog thiab nias sau kom txuag tau koj cov ntawv hauv qhov chaw nyob. Txog cov lus nug txog app twg koj tab tom siv, xaiv 2 (tshwj tsis yog koj tau kos npe ua ntej lub Kaum Ib Hlis 2018) thiab sau koj lub npe siv thiab tus password.

Kauj Ruam 4: Khiav Cov Piv Txwv

Khiav cov ntawv xeem kom paub tseeb tias peb tuaj yeem tsim cov ntaub ntawv xa mus rau koj Tus Thawj Xeev tus as khauj. Sau cov lus txib hauv qab no:

$ python is_example.py

Kauj Ruam 6: Piv Txwv Cov Ntaub Ntawv

Rov qab mus rau koj lub Xeev Thawj tus lej hauv koj lub vev xaib. Ib lub thoob cov ntaub ntawv tshiab hu ua "Python Stream Piv txwv" yuav tsum tau tshwm nyob rau sab laug hauv koj lub txee rau khoom (koj yuav tau rov ua nplooj ntawv tshiab). Nyem rau ntawm lub thoob no txhawm rau saib koj cov ntaub ntawv.

Kauj Ruam 4: Tsaus Ntuj Huab Cua Dashboard

Tsaus Ntuj Huab Cua Dashboard
Tsaus Ntuj Huab Cua Dashboard

Tam sim no rau qhov lom zem. Peb tau npaj pib siv Dark Sky API los tsim huab cua huab cua thiab khaws keeb kwm huab cua rau qhov chaw peb xaiv. Txhawm rau ua qhov no, peb yuav siv Python tsab ntawv: https://github.com/initialstate/darksky/blob/master/darksky.py. Tsab ntawv no tsuas yog hu ua Dark Sky API siv koj tus lej API thiab khaws cov ntaub ntawv huab cua ntawm lub sijhawm tshwj xeeb. Nws kuj tseem xa cov ntaub ntawv ntawd mus rau koj Tus Thawj Xeev lub txhab nyiaj, uas yuav tso cai rau koj los tsim Tsaus Ntuj Ntuj huab cua dashboard.

Koj tuaj yeem luam daim ntawv no rau koj Pi, lossis nkag mus tau los ntawm GitHub chaw cia khoom uas peb tau cloned ua ntej. Koj tuaj yeem ua qhov no los ntawm kev hloov pauv mus rau hauv koj cov npe darksky los ntawm kev ntaus ntawv:

$ cd tsaus ntuj

Los ntawm no, koj yuav tuaj yeem nkag mus rau cov ntaub ntawv nab nab uas peb yuav khiav los tsim peb cov huab cua huab cua. Ua ntej koj khiav nws, koj yuav tsum teeb tsa koj cov kev xav tau thiab ntxig koj cov yuam sij. Nano rau hauv cov ntawv darksky.py los ntawm kev ntaus ntawv:

$ nano darksky.py

Tom qab ntawd kho qhov seem nyob ze rau sab saud ntawm tsab ntawv:

# --------- Neeg Siv Chaw ---------

Nroog = "Nashville" GPS_COORDS = "36.1628414, -86.780199" DARKSKY_API_KEY = "PLACE KOJ DARK SKY API KEY HERE" BUCKET_NAME = ": partly_sunny:" + CITY + "Weather" BUCKET_KEY = "ds1" ACCESS ACCOUNT KEY NTAWM NO "MINUTES_BETWEEN_READS = 15 # ---------------------------------

Koj yuav tsum teeb tsa qhov xav tau GPS tswj hwm thiab lub nroog lub npe. Koj kuj tseem yuav tsum ntxig koj tus Tsaus Ntuj API tus yuam sij thiab koj Thawj Lub Xeev tus lej nkag mus siv tus lej lossis koj cov ntaub ntawv yuav tsis mus qhov twg. MINUTES_BETWEEN_READS qhov ntsuas yuav teev ntau npaum li cas koj cov ntawv yuav xaiv qhov Tsaus Ntuj API rau cov lus qhia huab cua. 15 feeb muab sijhawm zoo rau lub sijhawm ntev. Rau lub hom phiaj ntawm kev sim lub sijhawm luv, koj tuaj yeem teev qhov no rau 0.5 feeb. Ua koj qhov kev hloov pauv tom qab ntawd nkag mus tswj+X kom tawm thiab txuag.

Thaum koj tau teeb tsa koj cov kev teeb tsa, koj npaj tau los khiav koj tsab ntawv:

$ python darksky.py

Yog tias koj tab tom ssh'ing rau hauv koj Pi thiab xav kom tawm tsab ntawv no tsis muaj cuam tshuam rau lub sijhawm ntev, koj tuaj yeem siv cov lus txib nohup (tsis muaj hang-up) raws li hauv qab no:

$ nohup nab hab sej darksky.py &

Tsab ntawv no yuav ua ntau dua li tsuas yog nyeem cov ntaub ntawv huab cua thiab xa mus rau Lub Xeev Pib. Tsab ntawv no yuav ua kom zoo dua ntawm kev txhawb nqa emoji ua rau Hauv Lub Xeev Thawj cov cuab yeej los ua lub dashboard me ntsis txias dua. Koj tuaj yeem pom cov laj thawj siv los coj cov xwm txheej huab cua los ntawm tam sim no -> lub cim thiab hloov nws mus rau qhov cim cim emoji hauv huab cua_icon ua haujlwm. Ib yam dab tsi zoo sib xws tshwm sim rau lub hli hli hauv kev ua haujlwm moon_icon thiab cua qhia hauv cua wind_dir_icon muaj nuj nqi.

Kauj Ruam 5: Xaus

Xaus
Xaus
Xaus
Xaus

Mus rau koj Tus Thawj Xeev tus as khauj thiab saib koj cov ntaub ntawv. Kuv hloov tag nrho kuv qhov feem pua mus rau qhov ntsuas cua, nag lossis daus mus rau cov kua ntsuas, thiab ntsuas kub mus rau qhov ntsuas kub. Koj tuaj yeem hloov mus rau txhua hom Pobzeb hom thiab xaiv koj cov xim rau cov ntsuas thiab kab kab. Koj tuaj yeem ua rau koj lub dashboard tsaus lossis lub teeb thiab kos cov khoom kawg rau hauv lub vev xaib siv kev siv iFrame.

Yog tias koj xav siv daim phiaj teeb tsa los ntawm kev tshaj tawm pej xeem raws li koj lub dashboard, koj tuaj yeem xa cov txheej txheem rau hauv koj lub thoob cov ntaub ntawv los ntawm kev ua raws cov lus qhia ntawm no. Koj tuaj yeem ntxiv cov duab keeb kwm yav dhau los rau koj lub dashboard kom muab nws cov ntsiab lus ntxiv.

Cov pej xeem sib koom URL rau peb lub dashboard yog

Tam sim no koj tau paub txog Dark Sky API qhov muaj peev xwm tsis muaj qhov kawg! Muaj qhov txwv tsis pub siv API dawb online los tshawb xyuas yog li pib.

Pom zoo: