Modification fichier Chaufferie.py
This commit is contained in:
@@ -48,11 +48,12 @@ def on_message(_client, _userdata, msg):
|
||||
logging.info(f"Message reçu sur {msg.topic}: {msg.payload.decode()}")
|
||||
cursor = mydb.cursor()
|
||||
|
||||
frigo_name = msg.topic.split('/')[-1]
|
||||
topic_mqtt = msg.topic.split('/')[1] # ex: 'ECS'
|
||||
frigo_name = msg.topic.split('/')[-1] # ex: 'Dietrich_1'
|
||||
temperature = float(msg.payload.decode())
|
||||
|
||||
sql = "INSERT INTO Chaufferie (Sonde, Temperature, Date) VALUES (%s, %s, %s)"
|
||||
val = (frigo_name, temperature, datetime.now())
|
||||
sql = "INSERT INTO Chaufferie (Sonde, Temperature, Date, Topic) VALUES (%s, %s, %s, %s)"
|
||||
val = (frigo_name, temperature, datetime.now(), topic_mqtt)
|
||||
|
||||
cursor.execute(sql, val)
|
||||
mydb.commit()
|
||||
|
||||
Reference in New Issue
Block a user