mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
add direction to db when pressed button
This commit is contained in:
@@ -18,6 +18,14 @@ mqtt_client.loop_start()
|
||||
mqtt_client.subscribe("kobuki/data")
|
||||
mqtt_client.on_message = on_message
|
||||
|
||||
cnx = mysql.connector.connect(
|
||||
host="127.0.0.1",
|
||||
port=3306,
|
||||
user="admin",
|
||||
password="kobuki",
|
||||
database="kobuki"
|
||||
)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
@@ -33,6 +41,12 @@ def control():
|
||||
def move():
|
||||
data = request.get_json()
|
||||
direction = data.get("direction")
|
||||
|
||||
cursor = cnx.cursor()
|
||||
cursor.execute("INSERT INTO kobuki_data (command) VALUES (%s)", (direction,))
|
||||
cnx.commit()
|
||||
cursor.close()
|
||||
cnx.close()
|
||||
|
||||
# Verstuur de richting via MQTT
|
||||
if direction:
|
||||
@@ -47,23 +61,12 @@ def phpmyadmin_passthrough(path):
|
||||
|
||||
@app.route("/database")
|
||||
def database():
|
||||
try:
|
||||
cnx = mysql.connector.connect(
|
||||
host="127.0.0.1",
|
||||
port=3306,
|
||||
user="admin",
|
||||
password="kobuki",
|
||||
database="kobuki"
|
||||
)
|
||||
cursor = cnx.cursor()
|
||||
cursor.execute("SELECT * FROM kobuki_data")
|
||||
rows = cursor.fetchall()
|
||||
cursor.close()
|
||||
cnx.close()
|
||||
return str(rows)
|
||||
except mysql.connector.Error as err:
|
||||
print(f"Database error: {err}")
|
||||
return f"Database error: {err}", 500
|
||||
cursor = cnx.cursor()
|
||||
cursor.execute("SELECT * FROM kobuki_data")
|
||||
rows = cursor.fetchall()
|
||||
cursor.close()
|
||||
cnx.close()
|
||||
return str(rows)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000)
|
Reference in New Issue
Block a user