Advertisement
cymplecy

mtest

Oct 30th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1.  
  2. import paho.mqtt.client as paho
  3. import time
  4.  
  5.  
  6.  
  7. def on_connect(client, userdata, rc):
  8.     print("Connected with result code " + str(rc))
  9.  
  10.        
  11. def on_publish(client,userdata,result):
  12.     print("data published \n")
  13.     pass
  14.  
  15. def on_message(client, userdata, msg):
  16.     print(time.asctime() + " Topic: " + msg.topic + '\nMessage: ' +msg.payload.decode())
  17.  
  18.  
  19. broker="mqtt.eclipse.org"
  20. port=1883
  21.  
  22. client1= paho.Client()
  23. client1.on_connect = on_connect
  24. client1.on_publish = on_publish
  25. client1.on_message = on_message
  26.  
  27. client1.connect(broker,port)
  28. client1.loop_start()
  29. client1.subscribe("cheerlights")
  30.  
  31. while True:
  32.     time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement