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.subscribe("kobuki/data")
|
||||||
mqtt_client.on_message = on_message
|
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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
@@ -34,6 +42,12 @@ def move():
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
direction = data.get("direction")
|
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
|
# Verstuur de richting via MQTT
|
||||||
if direction:
|
if direction:
|
||||||
mqtt_client.publish("home/commands", direction)
|
mqtt_client.publish("home/commands", direction)
|
||||||
@@ -47,23 +61,12 @@ def phpmyadmin_passthrough(path):
|
|||||||
|
|
||||||
@app.route("/database")
|
@app.route("/database")
|
||||||
def database():
|
def database():
|
||||||
try:
|
cursor = cnx.cursor()
|
||||||
cnx = mysql.connector.connect(
|
cursor.execute("SELECT * FROM kobuki_data")
|
||||||
host="127.0.0.1",
|
rows = cursor.fetchall()
|
||||||
port=3306,
|
cursor.close()
|
||||||
user="admin",
|
cnx.close()
|
||||||
password="kobuki",
|
return str(rows)
|
||||||
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
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=5000)
|
app.run(debug=True, port=5000)
|
Reference in New Issue
Block a user