mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 12:24:57 +00:00
feat: insert sensor data into the database upon command execution
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from flask import Flask, request, render_template, jsonify, g
|
||||
import paho.mqtt.client as mqtt
|
||||
import mysql.connector
|
||||
import json
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -60,13 +61,6 @@ def control():
|
||||
|
||||
@app.route('/data', methods=['GET'])
|
||||
def data():
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
sql = "INSERT INTO kobuki_data (data) VALUES (%s)"
|
||||
value = data
|
||||
cursor.execute(sql, (value,))
|
||||
db.commit()
|
||||
cursor.close()
|
||||
return kobuki_message
|
||||
|
||||
|
||||
@@ -81,9 +75,14 @@ def move():
|
||||
|
||||
db_connection = get_db()
|
||||
cursor = db_connection.cursor()
|
||||
sql = "INSERT INTO command (command) VALUES (%s)"
|
||||
value = direction
|
||||
cursor.execute(sql, (value,))
|
||||
sql_command = "INSERT INTO command (command) VALUES (%s)"
|
||||
cursor.execute(sql_command, (direction,))
|
||||
|
||||
if data:
|
||||
sql_sensor = "INSERT INTO kobuki_data (data) VALUES (%s)"
|
||||
sensor_data_tuples = [(name, value) for name, value in sensor_data.items()]
|
||||
cursor.executemany(sql_sensor, sensor_data_tuples)
|
||||
|
||||
db_connection.commit()
|
||||
cursor.close()
|
||||
db_connection.close()
|
||||
|
Reference in New Issue
Block a user