From 08dfdeb1c5b56a2e290193674ef5c7dfe37bb6d2 Mon Sep 17 00:00:00 2001 From: Matheus Date: Thu, 9 Oct 2025 00:38:08 -0300 Subject: Commit inicial --- .gitignore | 2 ++ README.md | 7 +++++++ docs/overview.png | Bin 0 -> 438193 bytes mqtt_client/main.py | 23 +++++++++++++++++++++++ mqtt_client/requirements.txt | 1 + 5 files changed, 33 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 docs/overview.png create mode 100644 mqtt_client/main.py create mode 100644 mqtt_client/requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3b019b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/db-store/ +venv diff --git a/README.md b/README.md new file mode 100644 index 0000000..0779778 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Projeto de estação meteorológica +Precisamos de um nome melhor. + +Objetivo: Monitorar dados de sensor de microcontroladores e exibi-los em dashboards. + +O plano inicial é esse: +![Imagem overview do plano](docs/overview.png) diff --git a/docs/overview.png b/docs/overview.png new file mode 100644 index 0000000..044e554 Binary files /dev/null and b/docs/overview.png differ diff --git a/mqtt_client/main.py b/mqtt_client/main.py new file mode 100644 index 0000000..1a3ca8a --- /dev/null +++ b/mqtt_client/main.py @@ -0,0 +1,23 @@ +import paho.mqtt.client as mqtt +import json + +def on_connect(client, userdata, flags, reason_code, properties): + print(f"Conectado: {reason_code}") + # Me inscrevo em todos os tópicos sobre clima + client.subscribe("weather/#") + +# Simplesmente imprime a mensagem como texto. +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"]}") + +mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) +mqttc.on_connect = on_connect +mqttc.on_message = on_message + +mqttc.connect("127.0.0.1", 1883, 60) + +mqttc.loop_forever() diff --git a/mqtt_client/requirements.txt b/mqtt_client/requirements.txt new file mode 100644 index 0000000..96a2716 --- /dev/null +++ b/mqtt_client/requirements.txt @@ -0,0 +1 @@ +paho-mqtt==2.1.0 -- cgit v1.2.3