python databank anpassen
This commit is contained in:
parent
8531a8d79f
commit
b0792a6635
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue