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

39
pi/backend/main.py Normal file
View File

@@ -0,0 +1,39 @@
"""Smart Serow Backend - GPS service with HTTP API."""
from flask import Flask, jsonify
from gps_service import GPSService
app = Flask(__name__)
gps = GPSService()
@app.route("/health")
def health():
"""Health check endpoint."""
return jsonify({"status": "ok", "gps_connected": gps.connected})
@app.route("/gps")
def gps_data():
"""Current GPS data."""
return jsonify(gps.get_latest())
@app.route("/gps/history")
def gps_history():
"""Buffered GPS history."""
return jsonify(gps.get_buffer())
def main():
"""Entry point."""
gps.start()
try:
# Host 0.0.0.0 for access from Flutter app
app.run(host="0.0.0.0", port=5000, debug=False)
finally:
gps.stop()
if __name__ == "__main__":
main()