diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index f187235..f66a3ee 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -1,6 +1,6 @@ from flask import Flask, request, render_template, jsonify import paho.mqtt.client as mqtt -import mariadb +from flask_mysqldb import MySQL app = Flask(__name__) @@ -18,12 +18,12 @@ mqtt_client.loop_start() mqtt_client.subscribe("kobuki/data") mqtt_client.on_message = on_message # this lines needs to be under the function definition otherwise it cant find which function it needs to use -conn = mariadb.connect( - host='127.0.0.1', - user='admin', - password='kobuki', - database='kobuki') -cur = conn.cursor() +app.config['MYSQL_HOST'] = 'localhost' +app.config["MYSQL_USER"] = 'admin' +app.config["MYSQL_PASSWORD"] = 'kobuki' +app.config["MYSQL_DB"] = 'kobuki' + +mysql = MySQL(app) @app.route('/') @@ -61,7 +61,8 @@ def phpmyadmin_passthrough(path): @app.route("/database") def database(): - return "Connected to database" + cur = mysql.connection.cursor() + cur.execute("SELECT * FROM kobuki") if __name__ == '__main__': app.run(debug=True, port=5000)