mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 11:55:00 +00:00
went back
This commit is contained in:
@@ -111,9 +111,6 @@ def move():
|
|||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
@app.route('/data', methods=['GET'])
|
||||||
def data():
|
def data():
|
||||||
return kobuki_message
|
|
||||||
|
|
||||||
def sensor_data(kobuki_message):
|
|
||||||
try:
|
try:
|
||||||
# Parse de JSON-string naar een Python-dictionary
|
# Parse de JSON-string naar een Python-dictionary
|
||||||
data = json.loads(kobuki_message)
|
data = json.loads(kobuki_message)
|
||||||
@@ -133,19 +130,21 @@ def sensor_data(kobuki_message):
|
|||||||
|
|
||||||
# Database-insert
|
# Database-insert
|
||||||
db = get_db()
|
db = get_db()
|
||||||
cursor = db.cursor()
|
with db.cursor() as cursor:
|
||||||
|
|
||||||
# Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value`
|
# Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value`
|
||||||
sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)"
|
sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)"
|
||||||
cursor.executemany(sql_sensor, sensor_data_tuples)
|
cursor.executemany(sql_sensor, sensor_data_tuples)
|
||||||
|
|
||||||
# Commit en sluit de cursor
|
# Commit en sluit de cursor
|
||||||
db.commit()
|
db.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
print(f"JSON decode error: {e}")
|
print(f"JSON decode error: {e}")
|
||||||
except mysql.connector.Error as err:
|
except mysql.connector.Error as err:
|
||||||
print(f"Database error: {err}")
|
print(f"Database error: {err}")
|
||||||
|
return kobuki_message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/image')
|
@app.route('/image')
|
||||||
|
Reference in New Issue
Block a user