diff --git a/mqtt_test.py b/mqtt_test.py new file mode 100644 index 0000000..d07cfd0 --- /dev/null +++ b/mqtt_test.py @@ -0,0 +1,29 @@ +import paho.mqtt.client as mqtt + +BROKER = "broker.hivemq.com" +PORT = 1883 + +# Callback when client connects +def on_connect(client, userdata, flags, rc): + if rc == 0: + print("✅ Successfully connected to HiveMQ broker!") + else: + print("❌ Failed to connect. Return code:", rc) + +# Create client +client = mqtt.Client() + +# Attach callback +client.on_connect = on_connect + +try: + print("Attempting to connect...") + + # Connect to broker + client.connect(BROKER, PORT, 60) + + # Start network loop + client.loop_start() + +except Exception as e: + print("❌ Connection error:", e) \ No newline at end of file