差異處
這裏顯示兩個版本的差異處。
| 兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
| tech:owntrack [2025/04/08 09:23] – [自建 OwnTrack 追蹤 GPS 軌跡服務] jonathan | tech:owntrack [2026/03/03 14:26] (目前版本) – 3. 匯出特定 user 或 device 在特定日期區間的軌跡資料作法 jonathan | ||
|---|---|---|---|
| 行 5: | 行 5: | ||
| * GitHub - https:// | * GitHub - https:// | ||
| + | ===== 架構圖 ===== | ||
| + | |||
| + | < | ||
| + | graph TB | ||
| + | %% External Components | ||
| + | Mobile[📱 OwnTracks Mobile App< | ||
| + | Browser[🌐 Web Browser] | ||
| + | External[🌍 External MQTT Clients] | ||
| + | WebApp[📱 Mobile Web App< | ||
| + | | ||
| + | %% Docker Services | ||
| + | subgraph " | ||
| + | subgraph " | ||
| + | MQTT[Eclipse Mosquitto< | ||
| + | end | ||
| + | | ||
| + | subgraph " | ||
| + | Recorder[OwnTracks Recorder< | ||
| + | end | ||
| + | | ||
| + | subgraph " | ||
| + | Frontend[OwnTracks Frontend< | ||
| + | end | ||
| + | end | ||
| + | | ||
| + | %% Storage | ||
| + | subgraph "Data Storage" | ||
| + | MosquittocConf[(Mosquitto Config< | ||
| + | MosquittoData[(Mosquitto Data< | ||
| + | MosquittoLog[(Mosquitto Logs< | ||
| + | RecorderStore[(Location Data< | ||
| + | AuthFile[(Authentication< | ||
| + | end | ||
| + | | ||
| + | %% Data Flow - Location Publishing | ||
| + | Mobile -.-> | ||
| + | Mobile -.-> | ||
| + | External -.-> | ||
| + | WebApp -.-> | ||
| + | | ||
| + | %% Internal MQTT Subscription | ||
| + | MQTT -->|MQTT Subscribe< | ||
| + | | ||
| + | %% Data Storage Flow | ||
| + | Recorder --> RecorderStore | ||
| + | MQTT --> MosquittoData | ||
| + | MQTT --> MosquittoLog | ||
| + | | ||
| + | %% Web Interface Flow | ||
| + | Browser -->|HTTP Request< | ||
| + | Frontend -->|HTTP API Calls< | ||
| + | Recorder -->|JSON Response< | ||
| + | Frontend --> | ||
| + | | ||
| + | %% Configuration and Authentication | ||
| + | MQTT -.-> MosquittocConf | ||
| + | Recorder -.-> AuthFile | ||
| + | | ||
| + | %% WebSocket for Real-time (optional) | ||
| + | MQTT -.-> | ||
| + | | ||
| + | %% Styling | ||
| + | classDef service fill:# | ||
| + | classDef storage fill:# | ||
| + | classDef external fill:# | ||
| + | | ||
| + | class MQTT, | ||
| + | class MosquittoData, | ||
| + | class Mobile, | ||
| + | </ | ||
| ===== 安裝服務 ===== | ===== 安裝服務 ===== | ||
| ==== Server 端 ==== | ==== Server 端 ==== | ||
| + | * 安裝與設定目錄檔案配置 < | ||
| + | . | ||
| + | ├── auth | ||
| + | │ | ||
| + | ├── docker-compose.yml | ||
| + | ├── .env | ||
| + | └── mosquitto | ||
| + | └── config | ||
| + | ├── mosquitto.conf | ||
| + | └── passwd | ||
| + | </ | ||
| * {{repo> | * {{repo> | ||
| - | | + | |
| - | * {{repo> | + | * {{repo> |
| + | - 產生 MQTT 的設定檔 mosquitto/ | ||
| + | mkdir -p mosquitto/ | ||
| + | vi mosquitto/ | ||
| + | </ | ||
| + | * {{repo> | ||
| + | - 產生可存取 MQTT 的帳號密碼檔< | ||
| + | touch mosquitto/ | ||
| + | chmod 0770 mosquitto/ | ||
| + | </ | ||
| + | - 設定直接存取 OTRecorder 的帳號密碼檔 auth/ | ||
| + | mkdir -p auth | ||
| + | vi auth/ | ||
| + | </ | ||
| + | * {{repo> | ||
| + | - 第一次啟動服務 < | ||
| + | docker compose pull | ||
| + | docker compose up -d | ||
| + | </ | ||
| + | - 查看相關紀錄 | ||
| + | * docker compose 紀錄 < | ||
| + | * MQTT 紀錄 < | ||
| + | - 建立 Recoder 存取 MQTT 的帳號密碼(定義在 .env 內) Exp. recorder / recorderpass< | ||
| + | docker compose exec mosquitto chown root:root / | ||
| + | docker compose exec mosquitto mosquitto_passwd / | ||
| + | </ | ||
| + | - 建立 jonathan 存取 MQTT 的帳號密碼 Exp. jonathan / mypassword< | ||
| + | docker compose exec mosquitto mosquitto_passwd / | ||
| + | </ | ||
| ==== 手機端 ==== | ==== 手機端 ==== | ||
| - | | + | === 直接連 OTRecoder === |
| + | | ||
| + | * ++看畫面|{{: | ||
| * 設定 Endpoint 的 URL Exp. http:// | * 設定 Endpoint 的 URL Exp. http:// | ||
| - | * 設定 Credentials 的 Username 與 Password **要和 .env 內設定的相同** | + | * 設定 Credentials 的 Username 與 Password **要和 |
| + | * ++看畫面|{{: | ||
| + | |||
| + | === 連 MQTT (才可看到 Friends) === | ||
| + | * Connection 要選 MQTT | ||
| + | * ++看畫面|{{: | ||
| + | * 設定 Endpoint | ||
| + | * Host/Port Exp. 192.168.11.200 / 9001 (WebSocket) | ||
| + | * Client ID Exp. jonathan (建議和 Credentials 的 Username 相同 | ||
| + | * Use WebSockets : 啟用 | ||
| + | * ++看畫面|{{: | ||
| + | * 設定 Identification | ||
| + | * Device ID Exp. pixel9 | ||
| + | * Tracker ID Exp. jt (會顯示在 Android 的地圖上) | ||
| + | * ++看畫面|{{: | ||
| + | * 設定 Credentials (設定在 mosquitto/ | ||
| + | * Username Exp. jonathan | ||
| + | * Password Exp. mypassword | ||
| + | * TLS 關閉 | ||
| + | * Parameters | ||
| + | * Keepalive : 3600 | ||
| + | * Clean Session : 啟動 | ||
| + | * ++看設定畫面|{{: | ||
| + | |||
| + | ===== 管理端可以看到畫面 ===== | ||
| + | * Frontend - http:// | ||
| + | * OTRecorder - http:// | ||
| + | |||
| + | ===== 設定 Reverse Proxy 方式 ===== | ||
| + | * 這樣的設定好處是, | ||
| + | |||
| + | ==== 透過 Cloudflare Tunnel 設定 OTRecorder 對外服務 ==== | ||
| + | < | ||
| + | * 以 Endpoint 的 URL Exp. http:// | ||
| + | |||
| + | ==== 透過 Nginx Proxy Manager 設定 MQTT + WebSocket 對外服務 ==== | ||
| + | * 以 Endpoint 的 Host: mqtt.ichiayi.com Port:80 為例, 預計對應成 http:// | ||
| + | |||
| + | |||
| + | |||
| + | ===== 常見問題 ===== | ||
| + | ==== 1. 合併兩個 rec 作法 ==== | ||
| + | * 因為在相同裝置 Exp. Android, 修改設定中的 Device ID, Username 就會在主機端自動建立不同的目錄 Exp. Device ID : pixel9 , Username : jonathan 就會在 store/rec 與 store/last 都會建立出 jonathan/ | ||
| + | * 如果想要將 store/rec 內的紀錄檔 Exp. 2025-05.rec 進行合併 Exp. jonathan/ | ||
| + | - 備份與合併 2025-05.rec < | ||
| + | cd store/ | ||
| + | cp 2025-05.rec 2025-05.rec.bak | ||
| + | cat ../ | ||
| + | </ | ||
| + | - 將合併後的檔案依照資料時間進行排序 < | ||
| + | sort -s -k 1 2025-05.rec -o 2025-05.rec | ||
| + | </ | ||
| + | - 刪除 data.mdb 資料檔< | ||
| + | cd | ||
| + | rm -f store/ | ||
| + | </ | ||
| + | - 重起 otrecorder 服務< | ||
| + | docker compose restart otrecorder | ||
| + | docker compose logs -f otrecorder | ||
| + | </ | ||
| + | |||
| + | ==== 2. 刪除特定 user 或 device 作法 ==== | ||
| + | * 因為在相同裝置 Exp. Android, 修改設定中的 Device ID, Username 就會在主機端自動建立不同的目錄 Exp. Device ID : jonathan , Username : jonathan 就會在 store/rec 與 store/last 都會建立出 jonathan/ | ||
| + | - 針對這檔案型的作法就是直接刪除檔案 Exp. 刪除 jonathan/ | ||
| + | cd | ||
| + | rm -rf store/ | ||
| + | rm -rf store/ | ||
| + | rm -f store/ | ||
| + | </ | ||
| + | - 重起 otrecorder 服務< | ||
| + | docker compose restart otrecorder | ||
| + | </ | ||
| + | - 刪除 MQTT 的資料後, | ||
| + | rm mosquitto/ | ||
| + | docker compose restart mosquitto | ||
| + | </ | ||
| + | - 在 Android 需要進入 Friends-> | ||
| + | * ++看畫面|{{: | ||
| + | |||
| + | ==== 3. 匯出特定 user 或 device 在特定日期區間的軌跡資料作法 ==== | ||
| + | * 語法 : < | ||
| + | * Exp. Device ID : pixel9 , Username : jonathan 在 2026-02-05 ~ 2026-02-23 的 gpx 軌跡資料< | ||
| + | curl -o mytrack_20260205-0223.gpx " | ||
| + | </ | ||
| ===== 參考網址 ===== | ===== 參考網址 ===== | ||