From d24056dfa246d6ecf67447fa65eb0cdd67942df3 Mon Sep 17 00:00:00 2001 From: Matheus Date: Fri, 31 Oct 2025 22:44:37 -0300 Subject: Adicionado campos no banco de dados --- mqtt_client/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mqtt_client/main.py') diff --git a/mqtt_client/main.py b/mqtt_client/main.py index f460520..0ba9f10 100644 --- a/mqtt_client/main.py +++ b/mqtt_client/main.py @@ -6,6 +6,7 @@ from database import engine, SessionLocal from models import Base, Reading import os from time import sleep +from datetime import datetime print("Sleeping for 10 seconds to wait for db setup...") sleep(10) @@ -64,7 +65,7 @@ def on_message(client, userdata, msg): session.begin() for reading in readings: print(reading) - session.add(Reading(sensor_device_id=stationId, measure_id=measure, value=reading['value'])) + session.add(Reading(sensor_device_id=stationId, measure_id=measure, value=reading['value'], time=datetime.fromtimestamp(reading['timestamp'],))) session.commit() session.close() -- cgit v1.2.3