mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
Refactor MQTT connection and message sending in Flask app
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
from flask import Flask, request, render_template
|
||||
import paho.mqtt.publish as publish
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
mqtt_client = mqtt.Client()
|
||||
|
||||
# Verbinding maken met de Raspberry Pi (broker)
|
||||
mqtt_client.connect("ishakpi.ddns.net", 1883, 60)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/move', methods=['POST'])
|
||||
def move():
|
||||
direction = request.form['direction']
|
||||
publish.single("move", direction, hostname="145.109.226.204")
|
||||
return "Message sent"
|
||||
mqtt_client.publish("website/knop", "Knop ingedrukt!")
|
||||
return "Bericht verzonden!"
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
Reference in New Issue
Block a user