python backend arduino service
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
"""Smart Serow Backend - GPS service with HTTP API."""
|
||||
"""Smart Serow Backend - GPS and Arduino services with HTTP API."""
|
||||
|
||||
from flask import Flask, jsonify
|
||||
from gps_service import GPSService
|
||||
from arduino_service import ArduinoService
|
||||
|
||||
app = Flask(__name__)
|
||||
gps = GPSService()
|
||||
arduino = ArduinoService()
|
||||
|
||||
|
||||
@app.route("/health")
|
||||
def health():
|
||||
"""Health check endpoint."""
|
||||
return jsonify({"status": "ok", "gps_connected": gps.connected})
|
||||
return jsonify({
|
||||
"status": "ok",
|
||||
"gps_connected": gps.connected,
|
||||
"arduino_connected": arduino.connected,
|
||||
})
|
||||
|
||||
|
||||
@app.route("/gps")
|
||||
@@ -25,13 +31,27 @@ def gps_history():
|
||||
return jsonify(gps.get_buffer())
|
||||
|
||||
|
||||
@app.route("/arduino")
|
||||
def arduino_data():
|
||||
"""Current Arduino telemetry (voltage, rpm, etc)."""
|
||||
return jsonify(arduino.get_latest())
|
||||
|
||||
|
||||
@app.route("/arduino/history")
|
||||
def arduino_history():
|
||||
"""Buffered Arduino telemetry history."""
|
||||
return jsonify(arduino.get_buffer())
|
||||
|
||||
|
||||
def main():
|
||||
"""Entry point."""
|
||||
gps.start()
|
||||
arduino.start()
|
||||
try:
|
||||
# Host 0.0.0.0 for access from Flutter app
|
||||
app.run(host="0.0.0.0", port=5000, debug=False)
|
||||
finally:
|
||||
arduino.stop()
|
||||
gps.stop()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user