Add phone hotspot uplink
Prefer a configured phone hotspot for outbound synchronization, preserve secure write-only credentials, and recover through home WiFi or the local Pi hotspot. Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import Flask, render_template, make_response, json, jsonify, request, send_file
|
||||
from modules import app_gps, app_events, app_car, app_account, app_gps,app_obd, app_sql, app_dash, app_upload, app_video, app_health, app_alerts, app_settings
|
||||
from modules import app_gps, app_events, app_car, app_account, app_gps,app_obd, app_sql, app_dash, app_upload, app_video, app_health, app_alerts, app_settings, app_network
|
||||
import os, time
|
||||
from gevent.pywsgi import WSGIServer
|
||||
|
||||
@@ -46,6 +46,38 @@ def api_settings():
|
||||
return jsonify(error="Invalid settings.", fields=errors), 400
|
||||
return jsonify(app_settings.get_settings())
|
||||
|
||||
@app.route('/api/uplink/status')
|
||||
def uplink_status():
|
||||
try:
|
||||
return jsonify(app_network.get_status())
|
||||
except app_network.NetworkConfigurationError as error:
|
||||
return jsonify(error=str(error)), 503
|
||||
|
||||
@app.route('/api/uplink/config', methods=['POST', 'DELETE'])
|
||||
def uplink_config():
|
||||
try:
|
||||
if request.method == 'DELETE':
|
||||
app_network.remove_phone_hotspot()
|
||||
else:
|
||||
body = request.get_json(silent=True)
|
||||
if not isinstance(body, dict):
|
||||
return jsonify(error="Expected a JSON object."), 400
|
||||
app_network.configure_phone_hotspot(
|
||||
body.get("ssid"),
|
||||
body.get("password"),
|
||||
)
|
||||
return jsonify(app_network.get_status())
|
||||
except app_network.NetworkConfigurationError as error:
|
||||
return jsonify(error=str(error)), 400
|
||||
|
||||
@app.route('/api/uplink/connect', methods=['POST'])
|
||||
def uplink_connect():
|
||||
try:
|
||||
app_network.request_phone_connection()
|
||||
except app_network.NetworkConfigurationError as error:
|
||||
return jsonify(error=str(error)), 503
|
||||
return jsonify(status="connection_requested"), 202
|
||||
|
||||
@app.route('/api/trips')
|
||||
def trips():
|
||||
return jsonify({"trips": app_sql.list_trips()})
|
||||
|
||||
Reference in New Issue
Block a user