Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paho.mqtt.client as mqtt #import the client1
- import time
- def on_connect(client, userdata, rc):
- print("Connected with result code: %s" % rc)
- client.subscribe("hello/world")
- def on_message(client, userdata, message):
- print("message received " ,str(message.payload.decode("utf-8")))
- print("message topic=",message.topic)
- print("message qos=",message.qos)
- print("message retain flag=",message.retain)
- def main():
- client = mqtt.Client("P1") #create new instance
- # client.on_connect = on_connect
- client.on_message=on_message #attach function to callback
- client.connect("192.168.1.39")
- client.loop_start() #start the loop
- client.subscribe("hello/world") # subscribe on topic hello/world
- time.sleep(99) # wait
- client.loop_stop() #stop the loop
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement