summaryrefslogtreecommitdiff
path: root/mqtt_client/main.py
diff options
context:
space:
mode:
authorLuiz Gustavo Monteiro <116690851+luizgustavomonteiro@users.noreply.github.com>2025-11-01 09:22:33 -0300
committerGitHub <noreply@github.com>2025-11-01 09:22:33 -0300
commitc3a884f12c1d7b6bc286e14bf0f8af2d99dad542 (patch)
tree70e25f610ab41d8028114fd167b0c2ef51e34a1a /mqtt_client/main.py
parent032a77c0b1a2e0e2c247f511c0dc6d2555e691fb (diff)
parentd24056dfa246d6ecf67447fa65eb0cdd67942df3 (diff)
Merge pull request #1 from Simplesmente-O-Grupo/timestamp-db
Adicionado campos no banco de dados
Diffstat (limited to 'mqtt_client/main.py')
-rw-r--r--mqtt_client/main.py3
1 files changed, 2 insertions, 1 deletions
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()