summaryrefslogtreecommitdiff
path: root/mqtt_client/main.py
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-10-10 21:52:46 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-10-10 21:52:46 -0300
commit22935fae60b6ab2040596d4a78d1812e2a16589e (patch)
tree1f8fa5d64d4bc444537a12e098333c3a58e28476 /mqtt_client/main.py
parentdc70b88f7a516279ce0cc3be2d30a5e1d9a80091 (diff)
refactor:remoção do banco
Diffstat (limited to 'mqtt_client/main.py')
-rw-r--r--mqtt_client/main.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/mqtt_client/main.py b/mqtt_client/main.py
index 1a3ca8a..78cdca6 100644
--- a/mqtt_client/main.py
+++ b/mqtt_client/main.py
@@ -1,5 +1,7 @@
import paho.mqtt.client as mqtt
+from paho.mqtt.enums import MQTTProtocolVersion
import json
+from time import sleep
def on_connect(client, userdata, flags, reason_code, properties):
print(f"Conectado: {reason_code}")
@@ -14,10 +16,19 @@ def on_message(client, userdata, msg):
print(f"Unit: {payload["unit"]}")
print(f"Timestamp: {payload["timestamp"]}")
-mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
+mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, protocol=MQTTProtocolVersion.MQTTv5)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
+mqttc.username_pw_set('tester', 'rosebud')
-mqttc.connect("127.0.0.1", 1883, 60)
+connected = False
+
+while(not connected):
+ try:
+ mqttc.connect("127.0.0.1", 1883, 60, '', 0, True)
+ connected = True
+ except ConnectionRefusedError:
+ print("Failed to connect. Retrying...")
+ sleep(5)
mqttc.loop_forever()