gregwa

MQTT - Full Circle Magazine #132 - client1.py

Apr 2nd, 2018
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. # client1.py
  2. # For Full Circle Magazine issue 132
  3. import paho.mqtt.client as mqtt
  4.  
  5. def on_connect(client, userdata, flags, rc):
  6.     print("Connected with result code "+str(rc))
  7.     client.subscribe('test')
  8.  
  9. def on_message(client, userdata, msg):
  10.     print(msg.topic+" "+str(msg.payload))
  11.  
  12. client = mqtt.Client()
  13. client.on_connect = on_connect
  14. client.on_message = on_message
  15.  
  16. client.connect("192.168.1.224", 1883, 60)
  17.  
  18. # Blocking call that processes network traffic, dispatches callbacks and
  19. # handles reconnecting.
  20. # Other loop*() functions are available that give a threaded interface and a
  21. # manual interface.
  22. client.loop_forever()
Add Comment
Please, Sign In to add comment