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
|
from flask import Flask, request, render_template
|
||||||
import paho.mqtt.publish as publish
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
mqtt_client = mqtt.Client()
|
||||||
|
|
||||||
|
# Verbinding maken met de Raspberry Pi (broker)
|
||||||
|
mqtt_client.connect("ishakpi.ddns.net", 1883, 60)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
@app.route('/move', methods=['POST'])
|
@app.route('/move', methods=['POST'])
|
||||||
def move():
|
def move():
|
||||||
direction = request.form['direction']
|
mqtt_client.publish("website/knop", "Knop ingedrukt!")
|
||||||
publish.single("move", direction, hostname="145.109.226.204")
|
return "Bericht verzonden!"
|
||||||
return "Message sent"
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
Reference in New Issue
Block a user