diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index ef2a503..fbe0040 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -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()