added pi zero backend for wrapping gpsd

This commit is contained in:
Mikkeli Matlock
2026-01-26 00:56:43 +09:00
parent 4d7edd694a
commit 1314b4a05d
4 changed files with 250 additions and 0 deletions

71
pi/backend/README.md Normal file
View File

@@ -0,0 +1,71 @@
# Backend
Python GPS service for Smart Serow. Connects to `gpsd`, buffers positions, exposes HTTP API.
## Setup
```bash
# Install uv if you haven't
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
cd pi/backend
uv sync
```
## Run
```bash
uv run python main.py
```
Or for development:
```bash
uv run flask --app main run --host 0.0.0.0 --port 5000 --reload
```
## API
| Endpoint | Description |
|----------|-------------|
| `GET /health` | Health check, shows gpsd connection status |
| `GET /gps` | Latest GPS fix (lat, lon, alt, speed, track) |
| `GET /gps/history` | Last 100 buffered positions |
## Test from SSH
```bash
curl http://localhost:5000/health
curl http://localhost:5000/gps
curl http://localhost:5000/gps/history | jq
```
## gpsd Setup (Pi)
```bash
# Install
sudo apt install gpsd gpsd-clients
# Configure (edit DEVICES to match your GPS serial port)
sudo nano /etc/default/gpsd
# Example /etc/default/gpsd:
# DEVICES="/dev/ttyUSB0"
# GPSD_OPTIONS="-n"
# START_DAEMON="true"
# Restart
sudo systemctl restart gpsd
# Test gpsd directly
gpsmon
cgps -s
```
## Stub Mode
If `gpsdclient` isn't installed or gpsd isn't running, the service generates fake GPS data for UI testing.
## Deploy
TODO: Add to `scripts/deploy.py` as second target + systemd service.