Cov txheej txheem:

RPi IoT Ntse Teeb Siv Firebase: 4 Cov Kauj Ruam (nrog Duab)
RPi IoT Ntse Teeb Siv Firebase: 4 Cov Kauj Ruam (nrog Duab)

Video: RPi IoT Ntse Teeb Siv Firebase: 4 Cov Kauj Ruam (nrog Duab)

Video: RPi IoT Ntse Teeb Siv Firebase: 4 Cov Kauj Ruam (nrog Duab)
Video: Штукатурка стен - самое полное видео! Переделка хрущевки от А до Я. #5 2024, Kaum ib hlis
Anonim
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase
RPi IoT Ntse Teeb Siv Firebase

Phau ntawv qhia no qhia koj yuav ua li cas thiab teeb tsa ib lub app los tswj Raspberry Pi ntawm Firebase (Cov ntaub ntawv online). Thiab tom qab ntawd 3D luam ntawv rooj plaub rau Pi Zero W, Powerboost 1000C, roj teeb, thiab Blinkt !.

Yuav kom ua raws li yooj yim tshaj plaws, kuv pom zoo kom paub txog Xcode thiab Raspberry Pi.

Thiab yog tias koj nyiam qhov koj pom, ua raws kuv ntawm Instagram thiab Twitter (@Anders644PI) kom ua raws li qhov kuv ua.

Koj yuav xav tau:

  • Raspberry Pi Zero W nrog cov hloov pauv thiab GPIO-headers

    (lossis zoo ib yam Pi Zero nrog WiFi dongle)

  • Lub PowerBoost 1000 C.
  • Lub roj teeb Lithium Ion - 3.7v 2000mAh
  • Ib Blinkt! (lossis ib qho pHAT/HAT, uas: tsis siv tus pin 5 lub cev thiab HAT tus yuav tsum tiaj tus hauv qab.)
  • 8GB lossis siab dua Micro SD Card, nrog Raspbian Stretch (nrog desktop) ntawm nws
  • Keyboard thiab nas (tab sis koj tuaj yeem txuas nrog ssh, yog tias koj tam sim no yuav ua li cas)
  • Kev txuas mus rau tus saib lossis TV (lossis ssh!)
  • Seem screws
  • Cov xov hlau me
  • Hloov me me thiab khawm me me
  • Lub tshuab luam ntawv 3D thiab ib lub raj ntawm ib qho xim PLA filament, thiab ib lub raj ntawm PLA pob tshab (lossis koj tuaj yeem siv qhov kev pabcuam 3D zoo li 3D Hubs luam tawm rau koj)

Kauj ruam 1: Firebase thiab Xcode

Firebase thiab Xcode
Firebase thiab Xcode
Firebase thiab Xcode
Firebase thiab Xcode
Firebase thiab Xcode
Firebase thiab Xcode

Ua ntej peb yuav teeb tsa Firebase nrog lub app, yog li peb tuaj yeem sib txuas lus los ntawm app mus rau Pi.

Yog tias koj tsis meej pem, koj tuaj yeem saib daim vis dis aus no.

1. Qhib Xcode, thiab ua qhov tshiab Xcode project. Xaiv Ib Leeg Saib App thiab hu nws RPiAppControl, thiab paub tseeb tias cov lus yog Swift. Nias Next, thiab txuag nws.

2. Luam koj li Bundle Identifier, vim tias peb yuav xav tau tom qab.

3. Hauv Firebase, nkag mus nrog koj tus lej Google, thiab nyem mus rau console.

4. Tsim txoj haujlwm tshiab, thiab hu nws RPiAppControl.

5. Nyem Ntxiv Firebase rau koj IOS App. Muab tshuaj txhuam rau hauv koj Daim Ntawv Qhia Tus Kheej, thiab nias Sau Npe App.

6. Rub tawm GoogleService-Info.plist, thiab rub nws mus rau koj li Xcode Project.

7. Rov qab ntawm Firebase, nias Txuas ntxiv. Tom qab ntawd qhib lub davhlau ya nyob twg thiab mus rau qhov chaw ntawm koj li Xcode project.

8. Khiav cov lus txib no:

pib init

9. Qhib Podfile, thiab hauv qab use_frameworks!, ntxiv kab no:

pod 'Firebase/Tub ntxhais'

10. Rov qab rau hauv lub davhlau ya nyob twg hom: pod install, thiab kaw Xcode.

11. Hauv Finder, mus rau koj li Xcode project, thiab qhib qhov tshiab.xcworkspacefile tsim.

12. Hauv no mus rau AppDelegate.swift, thiab hauv qab UIKit ntshuam ntxiv kab no:

ntshuam Firebase

Thiab hauv daim ntawv thov-ua haujlwm, ntxiv kab no:

FIRApp.configure ().

13. Rov qab rau hauv Firebase, nyem Txuas ntxiv thiab tom qab ntawd ua tiav.

14. Mus rau Database, tom qab ntawd Cov Cai, thiab teeb tsa ".read" thiab ".write" kom muaj tseeb. Nias PUBLISH.

15. Rov qab ntawm Xcode, qhib lub Podfile, thiab hauv kab thawj peb teev hauv, ntxiv qhov no:

pod 'Firebase/Database'

16. Rov qab rau hauv lub davhlau ya nyob twg, khiav cov pod ntxiv.

Kauj ruam 2: Ua tiav Xcode

Ua tiav Xcode
Ua tiav Xcode
Ua tiav Xcode
Ua tiav Xcode
Ua tiav Xcode
Ua tiav Xcode

Tam sim no peb yuav ua tiav txoj cai thiab teeb tsa hauv Xcode.

Qhov no siv Xcode 9 thiab Swift 4

Code rau ViewController1. Nyob rau sab saud ntawm ViewController, thiab hauv qab UIKit ntshuam, ntxiv qhov no:

ntshuam Firebase

ntshuam FirebaseDatabase

2. Nyob rau hauv qab ntawm ViewController, thiab nyob rau hauv didReceiveMemoryWarning -function, luam qhov muab tso ua haujlwm no rau txhua lub pob:

func num1 (xeev: Txoj hlua) {

cia ref = FIRDatabase.database (). siv () cia tso tawm: [String: Any] = ["state": state] ref.child ("num1"). setValue (post)}Nco ntsoov hloov tus (tus lej

3. Hauv qhov viewDidLoad -function, nyob rau hauv super.viewDidLoad (), ntxig kab no rau txhua lub pob (Rau ntau lub khawm, tsuas yog hloov tus (tus lej). Saib daim duab …):

num1 (xeev: "OFF")

Txheej txheem ntawm Main.storyboard thiab cov nyees khawm

1. Mus rau Main.storyboard, thiab muab qee lub khawm. Koj tuaj yeem teeb tsa lawv zoo li kuv tau ua, lossis kho lawv raws li koj nyiam.

2. Txuas cov nyees khawm nrog ViewController. Txhua lub pob yuav tsum txuas nrog ob zaug: Ib qho yog qhov ua thiab UIButton hu ua tus lej (tus lej) Khawm, thiab lwm qhov yog lub qhov hluav taws xob tsis raug thiab hu nws tus lej (tus lej) Xim. Saib daim duab…

3. Tom qab ntawd rau tag nrho cov nyees khawm, muab lo rau kab no rau txhua qhov haujlwm:

yog self.num1Color.backgroundColor == UIColor.lightGray {// Teem cov xim keeb kwm yav dhau rau lightGray

num1 (xeev: "ON") // Xa lub xeev: "ON" rau firebase tus kheej.num1Color.backgroundColor = UIColor (liab: 0.96, ntsuab: 0.41, xiav: 0.26, alpha: 1.0) // Teeb xim tom qab rau reddish} lwm tus {num1 (xeev: "OFF") // Xa lub xeev: "OFF" rau firebase tus kheej.num1Color.backgroundColor = UIColor.lightGray // Teeb xim tom qab rau lightGray}

Tam sim no koj yuav tsum tuaj yeem sim nws, los ntawm kev khiav lub app, thiab thaum koj nias lub pob, koj yuav tsum pom nws hloov pauv lub xeev, hauv Lub Sijhawm Teev Npe hauv Firebase.

Kev sib tw tiav (Tsis teb los tau)

1. Rub cov duab hauv qab no, thiab ntxig rau LaunchScreen-image-j.webp

2. Mus rau Assets.xcassets thiab tom qab ntawd AppIcon. Hauv qhov no, tso rau hauv AppIcon -qhov loj me.

Kauj Ruam 3: Teeb Raspberry Pi

Raspberry Pi Teeb
Raspberry Pi Teeb

Tam sim no peb yuav tsum teeb tsa Pi nrog Firebase, yog li app tuaj yeem sib txuas lus, pov Firebase, rau Pi.

Kuv tsis tau sau cov cai, tab sis koj tuaj yeem pom thawj tus lej ntawm no.

1. Hauv lub davhlau ya nyob twg, khiav qhov hloov tshiab ib txwm muaj:

sudo apt-tau hloov tshiab && sudo apt-get dist-upgrade

2. Tom qab ntawd peb yuav import pyrebase (Firebase):

sudo pip nruab pyrebase

sudo pip3 nruab pyrebase sudo pip3 nruab-hloov kho google-auth-oauthlib

3. Tam sim no rub tawm Blinkt lub tsev qiv ntawv:

curl https://get.pimoroni.com/blinkt | tsoo

4. Clone kuv GitHub chaw cia khoom:

git clone https://github.com/Anders644PI/RPiAppControl.gitcd RPiAppControl

5. Kho qhov AppRPiControl_Template.py:

nano RPiAppControl_Template.py

6. Sau koj li Firebase ApiKey thiab projectId. Koj tuaj yeem pom cov no los ntawm kev mus rau koj li Firebase Project, thiab nyem Ntxiv Lwm Lub App thiab tom qab ntawd ntxiv Firebase rau koj lub vev xaib app.

7. Kho lub luag haujlwm, thiab txuag koj qhov kev hloov pauv los ntawm nias ctrl-o (nkag) thiab kaw nrog ctrl-x.

8. Tam sim no khiav nws nrog:

sudo python3 RPiAppControl_Template.py

9. Yog tias koj siv Blinkt, koj tuaj yeem sim ua piv txwv, thaum koj tau sau rau hauv koj li Firebase ApiKey thiab projectId:

cd piv txwv

nano RPiAppControl_blinkt_demo.py

Tam sim no khiav nws:

sudo python3 RPiAppControl_blinkt_demo.pyNco ntsoov tias tom qab koj sau tsab ntawv, nws siv sijhawm li ib feeb los npaj (tsawg kawg ntawm Pi Zero). Thiab tsab ntawv yuav tsum tau khiav hauv sej 3

10. LUS QHIA: Yog tias koj xav kom tsab ntawv khiav ntawm khau raj, koj tuaj yeem paub yuav ua li cas, ntawm no.

Kaw/Fais fab khawm

Nws yog xaiv tau los teeb tsa lub zog khawm, tab sis kuv pom zoo nws. Ua raws nrog cov vis dis aus no, teeb tsa nws.

Nco ntsoov tias qhov no siv tus lej pin 5 ntawm Pi, yog li qee qhov HATs yuav tsis ua haujlwm.

Kauj ruam 4: Cov ntaub ntawv kaw

Pom zoo: