From 48023773c62e1b221697378ecd5e533496913485 Mon Sep 17 00:00:00 2001 From: "ishak jmilou.ishak" Date: Tue, 14 Jan 2025 12:30:54 +0100 Subject: [PATCH] went back to older version. db get empty rows --- src/Python/flask/web/app.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index d6e908c..de45dd6 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -111,6 +111,9 @@ def move(): @app.route('/data', methods=['GET']) def data(): + return kobuki_message + +def sensor_data(kobuki_message): try: # Parse de JSON-string naar een Python-dictionary data = json.loads(kobuki_message) @@ -130,21 +133,19 @@ def data(): # Database-insert db = get_db() - with db.cursor() as cursor: + cursor = db.cursor() - # Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value` - sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)" - cursor.executemany(sql_sensor, sensor_data_tuples) - - # Commit en sluit de cursor - db.commit() - cursor.close() + # Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value` + sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)" + cursor.executemany(sql_sensor, sensor_data_tuples) + + # Commit en sluit de cursor + db.commit() + cursor.close() except json.JSONDecodeError as e: print(f"JSON decode error: {e}") except mysql.connector.Error as err: print(f"Database error: {err}") - return kobuki_message - @app.route('/image')