雲端計算期末報告 === [TOC] ## Step 0 : Requirement - ENV  - Python package 1. **pyhon: 3.9.0** 2. **pynmea2: 1.19.0** - Python library for the NMEA 0183 protcol 3. **pyrebase4: 4.7.1** - A simple python wrapper for the Firebase API with current deps 4. **pyserial: 3.5** - Python Serial Port Extension - GPS sensor G-MOUSE RoHS ipx6(USB port)  ## Step01 : Connect to GPS sensor from raspberryPi 3B and test: - test wheather GPS sensor already attached the Raspberry Pi ```bash= lsusb ``` - Output(successful)  - grap the loaction from GPS sensor like this ```bash= # use this command to check the serial port that we can use it. ls /dev/tty* ``` - Output  - And then use command to grap location info ```bash= cat /dev/ttyACMO ``` - Output  > NEMA(National Marine Electronics Association) GPS 數據格式介紹 > 1. GPGGA:全球定位系統定位資料(時間、位置、定位類型資料) > 2. GPGLL:地理位置、緯度、經度 > 3. GPVTG:相對於地面的航向和速度資訊 > 4. GPRMC:時間、日期、位置、航向和速度數據 (我們將選定這個數據做為收集對象) > 5. GPGSA:GPS 接收器操作模式、定位解決方案中使用的衛星以及 DOP 值。 > 6. GPGSV:視野中的 GPS 衛星數量、衛星 ID 號碼、海拔、方位角和 SNR 值。 - Use package "pynmea2" to parse the GPS locate info ($GPRMC) - SourceCode ```Python3.9= import pyrebase import serial import pynmea2 firebaseConfig={ "apiKey": "<YOUR_APIKEY>", "authDomain": "gps-tracker-21ea5.firebaseapp.com", "databaseURL": "https://gps-tracker-21ea5-default-rtdb.firebaseio.com", "projectId": "gps-tracker-21ea5", "storageBucket": "gps-tracker-21ea5.appspot.com", "messagingSenderId": "936208496146", "appId": "1:936208496146:web:6434e09e7a39466ac00acb" } firebase=pyrebase.initialize_app(firebaseConfig) db=firebase.database() while True: port="/dev/ttyACM0" ser=serial.Serial(port, baudrate=9600, timeout=0.5) dataout = pynmea2.NMEAStreamReader() newdata=ser.readline() n_data = newdata.decode('latin-1') if n_data[0:6] == '$GPRMC': newmsg=pynmea2.parse(n_data) lat=newmsg.latitude lng=newmsg.longitude gps = "Latitude=" + str(lat) + " and Longitude=" + str(lng) print(gps) data = {"LAT": lat, "LNG": lng} db.update(data) print("Data sent") ``` - Output afer parsing  ## Step02 : Construct a web system to grab the location from raspberry Pi that is attached by GPS sensor - WorkFlow  - 流程介紹 1. 後端架構 - GPS傳感器: 負責接收來自衛星的信號,並輸出位置信息的NMEA數據。 2. Raspberry Pi 3B: - 作為中心處理單元,負責接收從GPS傳感器輸出的NMEA數據。 - Raspberry Pi通過串行接口連接到GPS傳感器,接收位置數據。 3. Pynmea2 解析: - 一個Python庫,用於解析GPS傳感器輸出的NMEA格式數據。 - 此庫幫助解析數據,提取有用的定位信息,如經度和緯度。 4. gps_send.py 腳本: - 運行在Raspberry Pi上的Python腳本。 - 腳本讀取和解析GPS數據,然後將解析後的數據(經度和緯度)發送Firebase實時數據庫。 5. Firebase實時數據庫: - 一個由Google提供的NoSQL數據庫服務,用於存儲和同步客戶端與雲端的數據。 - 本架構中,它用來實時存儲和同步從gps_send.py腳本發送的位置數據。 - 前端架構 1. Web Application (Firebase): - 基於Firebase服務構建的Web應用程序。 - 負責從Firebase實時數據庫中實時提取位置數據。 2. Google Maps API: - 一個由Google提供的地圖服務API,用於在Web應用中渲染地圖。 - Web應用利用這個API將從Firebase獲取的位置數據顯示在地圖上,實現實時位置追蹤。 3. 用戶設備: - 用戶通過Web瀏覽器訪問Web應用。 - 用戶設備顯示的Web應用通過Google Maps API實現的地圖上呈現實時更新的位置數據。 - 數據流 - GPS傳感器獲取位置數據並通過串行連接傳輸到Raspberry Pi。 - Raspberry Pi使用pynmea2庫解析這些數據,並通過gps_send.py腳本將其發送到Firebase實時數據庫。 - Web應用從Firebase實時數據庫獲取這些數據,並通過Google Maps API在用戶設備上顯示位置。 ## step 03 : Practical result ||| |:-:|:-:| - Demo 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up