Advertisement
Guest User

Paho Mqtt Client

a guest
Jul 4th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import paho.mqtt.client as paho
  2. import os
  3. import time
  4. from random import randint
  5. import json
  6.  
  7.  
  8. myhash = randint(20000,30000)
  9.  
  10. broker = "127.0.0.1"
  11. port = 1883
  12.  
  13. mypid = os.getpid()
  14. client_uniq = client_uniq = "client123"
  15. mqttc = paho.Client(client_uniq, True)
  16.  
  17. # Connect with timeout
  18. mqttc.connect(broker, port, 60)
  19.  
  20. def on_message( mosq, obj, msg):
  21.     print "what's payload: ", msg.payload
  22.  
  23. # Subscribe
  24. mqttc.subscribe('mqtt-subscription-client123qos1',1)
  25. mqttc.on_message = on_message
  26.  
  27.  
  28. while mqttc.loop()==0:
  29.     msg = 13
  30.  
  31.     mqttc.publish("request", msg , qos=1, retain=False) # qos = 0,
  32.     print "Message Published"
  33.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement