mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +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
|
from flask import Flask, request, render_template, jsonify, g
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
import json
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@@ -60,13 +61,6 @@ def control():
|
|||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
@app.route('/data', methods=['GET'])
|
||||||
def data():
|
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
|
return kobuki_message
|
||||||
|
|
||||||
|
|
||||||
@@ -81,9 +75,14 @@ def move():
|
|||||||
|
|
||||||
db_connection = get_db()
|
db_connection = get_db()
|
||||||
cursor = db_connection.cursor()
|
cursor = db_connection.cursor()
|
||||||
sql = "INSERT INTO command (command) VALUES (%s)"
|
sql_command = "INSERT INTO command (command) VALUES (%s)"
|
||||||
value = direction
|
cursor.execute(sql_command, (direction,))
|
||||||
cursor.execute(sql, (value,))
|
|
||||||
|
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()
|
db_connection.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
db_connection.close()
|
db_connection.close()
|
||||||
|
Reference in New Issue
Block a user