Add comms simulation and config screen
This commit is contained in:
+37
-10
@@ -19,17 +19,17 @@ def status():
|
||||
|
||||
@app.route("/battery")
|
||||
def battery():
|
||||
return jsonify(pico.get_status()["battery"])
|
||||
return jsonify(pico.get_status().get("battery", {}))
|
||||
|
||||
|
||||
@app.route("/temps")
|
||||
def temps():
|
||||
return jsonify(pico.get_status()["temps"])
|
||||
return jsonify(pico.get_status().get("temps", {}))
|
||||
|
||||
|
||||
@app.route("/relays")
|
||||
def relays():
|
||||
return jsonify(pico.get_status()["relays"])
|
||||
return jsonify(pico.get_status().get("relays", {}))
|
||||
|
||||
|
||||
@app.route("/relay/<name>", methods=["POST"])
|
||||
@@ -37,38 +37,65 @@ def set_relay(name):
|
||||
data = request.get_json(force=True)
|
||||
response = pico.set_relay(name, data.get("state", False))
|
||||
|
||||
if not response["success"]:
|
||||
return jsonify(response), 404
|
||||
if not response.get("success"):
|
||||
return jsonify(response), 503
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
|
||||
@app.route("/network")
|
||||
def network():
|
||||
return jsonify(pico.get_status()["network"])
|
||||
return jsonify(pico.get_status().get("network", {}))
|
||||
|
||||
|
||||
@app.route("/network/wifi", methods=["POST"])
|
||||
def enable_wifi():
|
||||
data = request.get_json(force=True)
|
||||
minutes = int(data.get("minutes", 10))
|
||||
return jsonify(pico.enable_wifi(minutes))
|
||||
response = pico.enable_wifi(minutes)
|
||||
|
||||
if not response.get("success"):
|
||||
return jsonify(response), 503
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
|
||||
@app.route("/vehicle/ignition", methods=["POST"])
|
||||
def toggle_ignition():
|
||||
return jsonify(pico.toggle_ignition())
|
||||
response = pico.toggle_ignition()
|
||||
|
||||
if not response.get("success"):
|
||||
return jsonify(response), 503
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
|
||||
@app.route("/sensor/<name>/fault", methods=["POST"])
|
||||
def toggle_sensor_fault(name):
|
||||
response = pico.toggle_sensor_fault(name)
|
||||
|
||||
if not response["success"]:
|
||||
return jsonify(response), 404
|
||||
if not response.get("success"):
|
||||
return jsonify(response), 503
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
|
||||
@app.route("/comms")
|
||||
def comms():
|
||||
return jsonify(pico.get_comms())
|
||||
|
||||
|
||||
@app.route("/comms/rs485/disconnect", methods=["POST"])
|
||||
def disconnect_rs485():
|
||||
pico.disconnect_rs485()
|
||||
return jsonify({"success": True, "rs485_connected": False})
|
||||
|
||||
|
||||
@app.route("/comms/rs485/restore", methods=["POST"])
|
||||
def restore_rs485():
|
||||
pico.restore_rs485()
|
||||
return jsonify({"success": True, "rs485_connected": True})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
|
||||
Reference in New Issue
Block a user