From b0792a6635fa7c3cbbab102dc770e396578e9878 Mon Sep 17 00:00:00 2001 From: moritz Date: Thu, 27 Jun 2024 12:14:02 +0200 Subject: [PATCH] python databank anpassen --- Pi-py-Code/protocoll.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Pi-py-Code/protocoll.py b/Pi-py-Code/protocoll.py index ba6fdad..76397a8 100644 --- a/Pi-py-Code/protocoll.py +++ b/Pi-py-Code/protocoll.py @@ -4,7 +4,7 @@ from tmp_0x09 import get_temp # MySQL database connection setup -config = { +config_local = { 'user': 'root', # dein MySQL-Benutzername 'password': '', # dein MySQL-Passwort (standardmäßig leer bei XAMPP) 'host': '127.0.0.1', @@ -12,11 +12,19 @@ config = { 'raise_on_warnings': True } -def insert_data(temp, sensor_id): +config_cloud = { + 'user': 'moritz', # dein MySQL-Benutzername + 'password': 'T3st1234', # dein MySQL-Passwort (standardmäßig leer bei XAMPP) + 'host': 'icetruck.mysql.database.azure.com', + 'database': 'arduino', + 'raise_on_warnings': True +} + +def insert_data(temp, sensor_id, config): try: cnx = mysql.connector.connect(**config) cursor = cnx.cursor() - add_data = ("INSERT INTO Sensordaten " + add_data = ("INSERT INTO sensordaten " "(temperatur, sensor_id) " "VALUES (%s, %s)") data = (temp, sensor_id) @@ -36,6 +44,6 @@ def insert_data(temp, sensor_id): if __name__ == '__main__': while True: - insert_data(get_temp(0x09), 1) - insert_data(get_temp(0x0a), 2) + insert_data(get_temp(0x09), 1, config_cloud) + insert_data(get_temp(0x0a), 2, config_cloud) #insert_data(get_temp(0x0b), 3)