forked from render-examples/flask-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub.py
More file actions
36 lines (27 loc) · 905 Bytes
/
Copy pathsub.py
File metadata and controls
36 lines (27 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#A simple testing script for an MQTT sub to test the publisher ig idk
import paho.mqtt.client as mqtt
def onMessage(client, userdata, msg):
print("Message received")
print(msg.topic + ": " + msg.payload.decode())
client = mqtt.Client()
client.enable_logger()
client.on_message = onMessage
print("Running mqttsub test sub script...QOS=1")
# mqtthost = "broker.mqttdashboard.com"
# mqtthost = "mqtt.eclipseprojects.io"
mqtthost = "test.mosquitto.org"
if (client.connect(mqtthost, 1883, 30) != 0):
print("Could not connect to " + mqtthost)
exit()
else:
print("Connection successful to " + mqtthost)
# mytopic = "sosa/test"
mytopic = "sosa/plug"
client.subscribe(mytopic, 1)
print("Subscribed to topic :" + mytopic)
try:
print("Press Ctrl+C to exit...")
client.loop_forever(1, retry_first_connection=True)
except:
print("Disconnecting from broker")
client.disconnect()