Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import paho.mqtt.client as mqtt
- # The callback for when the client receives a CONNACK response from the server.
- def on_connect(client, userdata, flags, rc):
- print("Connected with result code "+str(rc))
- client = mqtt.Client()
- client.on_connect = on_connect
- client.connect("localhost", 1883, 60)
- client.loop_start()
- counter = 0
- while True:
- client.publish("lol/data", counter)
- counter += 1
- time.sleep(1)
- ==============================================================================
- import paho.mqtt.client as mqtt
- def on_connect(client, userdata, flags, rc):
- print("Connected with result code "+str(rc))
- client.subscribe("lol/data")
- client.subscribe("$SYS/broker/subscriptions/#")
- def on_message(client, userdata, msg):
- print(msg.topic+" "+str(msg.payload))
- client = mqtt.Client()
- client.on_connect = on_connect
- client.on_message = on_message
- client.connect("localhost", 1883, 60)
- client.loop_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement