mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
28 lines
809 B
Python
28 lines
809 B
Python
from flask import Flask, request, render_template, jsonify
|
|
import paho.mqtt.client as mqtt
|
|
|
|
app = Flask(__name__)
|
|
|
|
# Create an MQTT client instance
|
|
mqtt_client = mqtt.Client()
|
|
mqtt_client.username_pw_set("ishak", "kobuki")
|
|
mqtt_client.connect("localhost", 1883, 60)
|
|
mqtt_client.loop_start()
|
|
|
|
@app.route('/', methods=["GET","POST"])
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/move', methods=['POST'])
|
|
def move():
|
|
data = request.get_json()
|
|
direction = data.get("direction")
|
|
|
|
# Verstuur de richting via MQTT
|
|
if direction:
|
|
mqtt_client.publish("home/commands", direction) # Het topic kan aangepast worden
|
|
|
|
return jsonify({"status": "success", "direction": direction})
|
|
# Run the Flask application in debug mode
|
|
if __name__ == '__main__':
|
|
app.run(debug=True) |