From 827b46bb166d9cfe65c3bf316d34f7916d1f76c4 Mon Sep 17 00:00:00 2001 From: Nathalia Veiga <114751360+nahveiga@users.noreply.github.com> Date: Mon, 20 Oct 2025 14:05:55 -0300 Subject: Create frontend --- frontend | 1 + 1 file changed, 1 insertion(+) create mode 100644 frontend diff --git a/frontend b/frontend new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/frontend @@ -0,0 +1 @@ + -- cgit v1.2.3 From 18b4c8bc11b9cee599542a4e3aa49cd3979e603c Mon Sep 17 00:00:00 2001 From: Nathalia Veiga <114751360+nahveiga@users.noreply.github.com> Date: Mon, 20 Oct 2025 14:51:41 -0300 Subject: Update frontend --- frontend | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/frontend b/frontend index 8b13789..91532f6 100644 --- a/frontend +++ b/frontend @@ -1 +1,28 @@ +Estratégia de implementação Frontend/Backend para sistema de estação meteorológica com ESP32 +- Formato JSON padronizado (sugestão): +{ + "station_id": "ESP32_001", + "timestamp": 1697203200, + "readings": { + "temperature": 25.4, + "humidity": 65.2, + "pressure": 1013.25, + "luminosity": 450, + "wind_direction": 180, + "wind_speed": 5.2 + } +} + + +- VISÃO CLIENT: +info essenciais: +- condições em tempo real: + -> Temperatura + -> Umidade + -> Pressao atmosférica + -> Luminosidade + -> Velocidade e direção do vento + -> ultima atualização + +- situação da estação -- cgit v1.2.3 From 8aaa85953f408e50ecfe0a6484d5113de06f014d Mon Sep 17 00:00:00 2001 From: Nathalia Veiga <114751360+nahveiga@users.noreply.github.com> Date: Mon, 20 Oct 2025 14:56:20 -0300 Subject: Add additional weather station status indicators --- frontend | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frontend b/frontend index 91532f6..ac66a0f 100644 --- a/frontend +++ b/frontend @@ -26,3 +26,16 @@ info essenciais: -> ultima atualização - situação da estação + -> online / offline + -> bateria / alimentação + -> qualidade sinal + -> defeito em algum sensor + +- tendencia e previsão + -> temperatura ta subindo ou caindo? + -> pressão está subindo ou caindo? + -> Grafico das ultimas horas + +- Recordes do dia, semana e mes + + -- cgit v1.2.3 From 578c68b99150eb68209cca2659d27d94d8a6a488 Mon Sep 17 00:00:00 2001 From: Nathalia Veiga <114751360+nahveiga@users.noreply.github.com> Date: Mon, 20 Oct 2025 15:01:40 -0300 Subject: Create frontend\src\components\SensorGauge.jsx --- "frontend\\src\\components\\SensorGauge.jsx" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "frontend\\src\\components\\SensorGauge.jsx" diff --git "a/frontend\\src\\components\\SensorGauge.jsx" "b/frontend\\src\\components\\SensorGauge.jsx" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/frontend\\src\\components\\SensorGauge.jsx" @@ -0,0 +1 @@ + -- cgit v1.2.3 From ea698a5c77702684fbebf89db9ba6f8071f2df5b Mon Sep 17 00:00:00 2001 From: Nathalia Veiga <114751360+nahveiga@users.noreply.github.com> Date: Mon, 20 Oct 2025 15:02:55 -0300 Subject: Delete frontend\src\components\SensorGauge.jsx odeio github web --- "frontend\\src\\components\\SensorGauge.jsx" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "frontend\\src\\components\\SensorGauge.jsx" diff --git "a/frontend\\src\\components\\SensorGauge.jsx" "b/frontend\\src\\components\\SensorGauge.jsx" deleted file mode 100644 index 8b13789..0000000 --- "a/frontend\\src\\components\\SensorGauge.jsx" +++ /dev/null @@ -1 +0,0 @@ - -- cgit v1.2.3 From 97d7629619a651392a9015391b7433955cd65209 Mon Sep 17 00:00:00 2001 From: Nathalia Veiga Date: Mon, 20 Oct 2025 19:41:04 -0300 Subject: pastas e organização - frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend | 41 --------------------------------- frontend-arq | 41 +++++++++++++++++++++++++++++++++ frontend/src/components/AlertPainel.jsx | 0 frontend/src/components/ChartWidget.jsx | 0 frontend/src/components/SensorGauge.jsx | 0 frontend/src/pages/Dashboard.jsx | 0 frontend/src/pages/History.jsx | 0 frontend/src/services/api.js | 0 8 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 frontend create mode 100644 frontend-arq create mode 100644 frontend/src/components/AlertPainel.jsx create mode 100644 frontend/src/components/ChartWidget.jsx create mode 100644 frontend/src/components/SensorGauge.jsx create mode 100644 frontend/src/pages/Dashboard.jsx create mode 100644 frontend/src/pages/History.jsx create mode 100644 frontend/src/services/api.js diff --git a/frontend b/frontend deleted file mode 100644 index ac66a0f..0000000 --- a/frontend +++ /dev/null @@ -1,41 +0,0 @@ -Estratégia de implementação Frontend/Backend para sistema de estação meteorológica com ESP32 - -- Formato JSON padronizado (sugestão): -{ - "station_id": "ESP32_001", - "timestamp": 1697203200, - "readings": { - "temperature": 25.4, - "humidity": 65.2, - "pressure": 1013.25, - "luminosity": 450, - "wind_direction": 180, - "wind_speed": 5.2 - } -} - - -- VISÃO CLIENT: -info essenciais: -- condições em tempo real: - -> Temperatura - -> Umidade - -> Pressao atmosférica - -> Luminosidade - -> Velocidade e direção do vento - -> ultima atualização - -- situação da estação - -> online / offline - -> bateria / alimentação - -> qualidade sinal - -> defeito em algum sensor - -- tendencia e previsão - -> temperatura ta subindo ou caindo? - -> pressão está subindo ou caindo? - -> Grafico das ultimas horas - -- Recordes do dia, semana e mes - - diff --git a/frontend-arq b/frontend-arq new file mode 100644 index 0000000..ac66a0f --- /dev/null +++ b/frontend-arq @@ -0,0 +1,41 @@ +Estratégia de implementação Frontend/Backend para sistema de estação meteorológica com ESP32 + +- Formato JSON padronizado (sugestão): +{ + "station_id": "ESP32_001", + "timestamp": 1697203200, + "readings": { + "temperature": 25.4, + "humidity": 65.2, + "pressure": 1013.25, + "luminosity": 450, + "wind_direction": 180, + "wind_speed": 5.2 + } +} + + +- VISÃO CLIENT: +info essenciais: +- condições em tempo real: + -> Temperatura + -> Umidade + -> Pressao atmosférica + -> Luminosidade + -> Velocidade e direção do vento + -> ultima atualização + +- situação da estação + -> online / offline + -> bateria / alimentação + -> qualidade sinal + -> defeito em algum sensor + +- tendencia e previsão + -> temperatura ta subindo ou caindo? + -> pressão está subindo ou caindo? + -> Grafico das ultimas horas + +- Recordes do dia, semana e mes + + diff --git a/frontend/src/components/AlertPainel.jsx b/frontend/src/components/AlertPainel.jsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/components/ChartWidget.jsx b/frontend/src/components/ChartWidget.jsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/components/SensorGauge.jsx b/frontend/src/components/SensorGauge.jsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/pages/History.jsx b/frontend/src/pages/History.jsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 370d3014ebf95e0c422a3ea2b39d568d66eb326e Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Monteiro Date: Mon, 20 Oct 2025 21:06:44 -0300 Subject: Postgres Conteiner Settings --- .env.example | 4 ++-- compose.yaml | 24 ++++++++++++++++++++++++ database/create_table.sql | 6 ++++++ mosquitto-config/mosquitto.conf | 4 ++-- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 database/create_table.sql diff --git a/.env.example b/.env.example index dee33a5..94f8f32 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # vim:ft=sh # Usuário que o cliente MQTT utilizará para logar -MQTT_CLIENT_USER="changeme" +MQTT_CLIENT_USER="tester" # Senha que o cliente MQTT utilizará para logar -MQTT_CLIENT_PASSWORD="changeme" +MQTT_CLIENT_PASSWORD="rosebud" diff --git a/compose.yaml b/compose.yaml index db32d4c..21f3cea 100644 --- a/compose.yaml +++ b/compose.yaml @@ -30,5 +30,29 @@ services: depends_on: - mosquitto + + postgres: + image: postgres:13 + container_name: postgres + ports: + - 5432:5432 + environment: + POSTGRES_PASSWORD: public + POSTGRES_USER: root + POSTGRES_DB: control_station + volumes: + - $PWD/database/create-table.sql:/docker-entrypoint-initdb.d/init.sql + + + pgadmin: + image: dpage/pgadmin4 + container_name: pgadmin + environment: + - PGADMIN_DEFAULT_EMAIL=admin@admin.com + - PGADMIN_DEFAULT_PASSWORD=admin + ports: + - "5050:80" + depends_on: + - postgres networks: mosquitto: diff --git a/database/create_table.sql b/database/create_table.sql new file mode 100644 index 0000000..8ee801a --- /dev/null +++ b/database/create_table.sql @@ -0,0 +1,6 @@ +create table if not exists climameasures ( + stationname varchar(255), + measurevalue int null, + unit float null, + currenttime timestamp default current_timestamp +); \ No newline at end of file diff --git a/mosquitto-config/mosquitto.conf b/mosquitto-config/mosquitto.conf index f913973..7e941f9 100644 --- a/mosquitto-config/mosquitto.conf +++ b/mosquitto-config/mosquitto.conf @@ -1,3 +1,3 @@ listener 1883 0.0.0.0 -allow_anonymous false -password_file /mosquitto/config/pass-file +allow_anonymous true +# password_file /mosquitto/config/pass-file -- cgit v1.2.3 From ba5f30be9f69d18cbb3ffe2d00ba9cf287b77f43 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 21 Oct 2025 00:11:39 -0300 Subject: fix:criação automática de tabelas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compose.yaml | 17 ++++++++++------- database/create_table.sql | 6 ------ database/init_scripts/create_table.sql | 6 ++++++ 3 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 database/create_table.sql create mode 100644 database/init_scripts/create_table.sql diff --git a/compose.yaml b/compose.yaml index 21f3cea..c5102e4 100644 --- a/compose.yaml +++ b/compose.yaml @@ -29,21 +29,18 @@ services: - mosquitto depends_on: - mosquitto - - postgres: image: postgres:13 container_name: postgres - ports: - - 5432:5432 + networks: + - database environment: POSTGRES_PASSWORD: public POSTGRES_USER: root POSTGRES_DB: control_station volumes: - - $PWD/database/create-table.sql:/docker-entrypoint-initdb.d/init.sql - - + - ${PWD}/database/init_scripts:/docker-entrypoint-initdb.d + - db_data:/var/lib/postgresql/data pgadmin: image: dpage/pgadmin4 container_name: pgadmin @@ -52,7 +49,13 @@ services: - PGADMIN_DEFAULT_PASSWORD=admin ports: - "5050:80" + networks: + - database depends_on: - postgres networks: mosquitto: + database: + +volumes: + db_data: diff --git a/database/create_table.sql b/database/create_table.sql deleted file mode 100644 index 8ee801a..0000000 --- a/database/create_table.sql +++ /dev/null @@ -1,6 +0,0 @@ -create table if not exists climameasures ( - stationname varchar(255), - measurevalue int null, - unit float null, - currenttime timestamp default current_timestamp -); \ No newline at end of file diff --git a/database/init_scripts/create_table.sql b/database/init_scripts/create_table.sql new file mode 100644 index 0000000..8ee801a --- /dev/null +++ b/database/init_scripts/create_table.sql @@ -0,0 +1,6 @@ +create table if not exists climameasures ( + stationname varchar(255), + measurevalue int null, + unit float null, + currenttime timestamp default current_timestamp +); \ No newline at end of file -- cgit v1.2.3 From e9f3d47100fd5f61342af0a6f8e1abbe3bea9093 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Monteiro Date: Sun, 26 Oct 2025 14:36:11 -0300 Subject: Added database model --- database/init_scripts/create_table.sql | 15 +++++++ mqtt_client/crud.py | 0 mqtt_client/database.py | 0 mqtt_client/models.py | 81 ++++++++++++++++++++++++++++++++++ mqtt_client/schemas.py | 0 5 files changed, 96 insertions(+) create mode 100644 mqtt_client/crud.py create mode 100644 mqtt_client/database.py create mode 100644 mqtt_client/models.py create mode 100644 mqtt_client/schemas.py diff --git a/database/init_scripts/create_table.sql b/database/init_scripts/create_table.sql index 8ee801a..ae5b3d1 100644 --- a/database/init_scripts/create_table.sql +++ b/database/init_scripts/create_table.sql @@ -1,3 +1,18 @@ +create table if not exists station ( + id integer, + name varchar(100), + locationid int null, + installation_date date +); + +create table if not exists climameasures ( + stationname varchar(255), + measurevalue int null, + unit float null, + currenttime timestamp default current_timestamp +); + + create table if not exists climameasures ( stationname varchar(255), measurevalue int null, diff --git a/mqtt_client/crud.py b/mqtt_client/crud.py new file mode 100644 index 0000000..e69de29 diff --git a/mqtt_client/database.py b/mqtt_client/database.py new file mode 100644 index 0000000..e69de29 diff --git a/mqtt_client/models.py b/mqtt_client/models.py new file mode 100644 index 0000000..d6bd2ba --- /dev/null +++ b/mqtt_client/models.py @@ -0,0 +1,81 @@ +from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Boolean +from sqlalchemy.orm import relationship +from sqlalchemy.sql import func +from database import Base + +# ---------------------------- +# Location +# ---------------------------- +class Location(Base): + __tablename__ = "locations" + + id = Column(Integer, primary_key=True, index=True) + street = Column(String(200), nullable=True, index=True) + avenue = Column(String(200), nullable=True, index=True) + zip_code = Column(String(20), nullable=True, index=True) + + # Relationship: One location to many stations + stations = relationship("Station", back_populates="location") + + +# ---------------------------- +# Station +# ---------------------------- +class Station(Base): + __tablename__ = "stations" + + id = Column(Integer, primary_key=True, index=True) + name = Column(String(100), nullable=False, index=True) + location_id = Column(Integer, ForeignKey("locations.id"), nullable=True, index=True) + installation_date = Column(DateTime, server_default=func.now()) + is_active = Column(Boolean, default=True) + + # Relationships + location = relationship("Location", back_populates="stations") + sensor_devices = relationship("SensorDevice", back_populates="station") + + +# ---------------------------- +# SensorDevice +# ---------------------------- +class SensorDevice(Base): + __tablename__ = "sensor_devices" + + id = Column(Integer, primary_key=True, index=True) + name = Column(String(100), nullable=True, index=True) + installation_date = Column(DateTime, server_default=func.now()) + station_id = Column(Integer, ForeignKey("stations.id"), nullable=True, index=True) + is_active = Column(Boolean, default=True) + + # Relationships + station = relationship("Station", back_populates="sensor_devices") + readings = relationship("Reading", back_populates="sensor_device") + + +# ---------------------------- +# Measure +# ---------------------------- +class Measure(Base): + __tablename__ = "measures" + + id = Column(Integer, primary_key=True, index=True) + name = Column(String(50), nullable=True, index=True) + + # Relationships + readings = relationship("Reading", back_populates="measure") + + +# ---------------------------- +# Reading +# ---------------------------- +class Reading(Base): + __tablename__ = "readings" + + id = Column(Integer, primary_key=True, index=True) + sensor_device_id = Column(Integer, ForeignKey("sensor_devices.id"), nullable=True, index=True) + measure_id = Column(Integer, ForeignKey("measures.id"), nullable=True, index=True) + value = Column(Float, nullable=True) + + # Relationships + sensor_device = relationship("SensorDevice", back_populates="readings") + measure = relationship("Measure", back_populates="readings") diff --git a/mqtt_client/schemas.py b/mqtt_client/schemas.py new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 52a4fe2625b63683fcdcd74f704e49aa65cb0dd8 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Monteiro Date: Sun, 26 Oct 2025 16:09:12 -0300 Subject: database connection tested successfully - tables readed on pgadmin --- compose.yaml | 11 ++++++++--- database/init_scripts/create_table.sql | 21 --------------------- mqtt_client/database.py | 10 ++++++++++ mqtt_client/main.py | 13 ++++++++++--- mqtt_client/requirements.txt | 4 +++- 5 files changed, 31 insertions(+), 28 deletions(-) delete mode 100644 database/init_scripts/create_table.sql diff --git a/compose.yaml b/compose.yaml index c5102e4..549379a 100644 --- a/compose.yaml +++ b/compose.yaml @@ -23,6 +23,7 @@ services: environment: MQTT_CLIENT_USER: ${MQTT_CLIENT_USER} MQTT_CLIENT_PASSWORD: ${MQTT_CLIENT_PASSWORD} + DATABASE_URL: postgresql://root:public@postgres:5432/control_station build: context: ./mqtt_client/ networks: @@ -33,14 +34,18 @@ services: image: postgres:13 container_name: postgres networks: - - database + - mosquitto + ports: + - "5432:5432" environment: POSTGRES_PASSWORD: public POSTGRES_USER: root POSTGRES_DB: control_station volumes: - - ${PWD}/database/init_scripts:/docker-entrypoint-initdb.d + #- ${PWD}/database/init_scripts:/docker-entrypoint-initdb.d - db_data:/var/lib/postgresql/data + + pgadmin: image: dpage/pgadmin4 container_name: pgadmin @@ -50,7 +55,7 @@ services: ports: - "5050:80" networks: - - database + - mosquitto depends_on: - postgres networks: diff --git a/database/init_scripts/create_table.sql b/database/init_scripts/create_table.sql deleted file mode 100644 index ae5b3d1..0000000 --- a/database/init_scripts/create_table.sql +++ /dev/null @@ -1,21 +0,0 @@ -create table if not exists station ( - id integer, - name varchar(100), - locationid int null, - installation_date date -); - -create table if not exists climameasures ( - stationname varchar(255), - measurevalue int null, - unit float null, - currenttime timestamp default current_timestamp -); - - -create table if not exists climameasures ( - stationname varchar(255), - measurevalue int null, - unit float null, - currenttime timestamp default current_timestamp -); \ No newline at end of file diff --git a/mqtt_client/database.py b/mqtt_client/database.py index e69de29..c0691a1 100644 --- a/mqtt_client/database.py +++ b/mqtt_client/database.py @@ -0,0 +1,10 @@ +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker +import os + +DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://root:public@postgres:5432/control_station") + +engine = create_engine(DATABASE_URL) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) +Base = declarative_base() diff --git a/mqtt_client/main.py b/mqtt_client/main.py index dad09b5..109ca49 100644 --- a/mqtt_client/main.py +++ b/mqtt_client/main.py @@ -2,8 +2,15 @@ import paho.mqtt.client as mqtt from paho.mqtt.enums import MQTTProtocolVersion import json from time import sleep +from database import engine +from models import Base import os +print("Creating ORM SQL Tables..") +Base.metadata.create_all(bind=engine) +print("Tables created successfully.") + + def on_connect(client, userdata, flags, reason_code, properties): print(f"Conectado: {reason_code}") # Me inscrevo em todos os tópicos sobre clima @@ -13,9 +20,9 @@ def on_connect(client, userdata, flags, reason_code, properties): def on_message(client, userdata, msg): payload = json.loads(msg.payload) print(msg.topic) - print(f"Value: {payload["value"]}") - print(f"Unit: {payload["unit"]}") - print(f"Timestamp: {payload["timestamp"]}") + print(f"Value: {payload['value']}") + print(f"Unit: {payload['unit']}") + print(f"Timestamp: {payload['timestamp']}") try: user_name = os.environ["MQTT_CLIENT_USER"] diff --git a/mqtt_client/requirements.txt b/mqtt_client/requirements.txt index 96a2716..1521b2d 100644 --- a/mqtt_client/requirements.txt +++ b/mqtt_client/requirements.txt @@ -1 +1,3 @@ -paho-mqtt==2.1.0 +sqlalchemy +psycopg2-binary +paho-mqtt -- cgit v1.2.3