Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import paho.mqtt.client as mqtt
  2. import RPi.GPIO as gpio
  3.  
  4. #set up the mqtt
  5. username = "@gmail.com"
  6. password = ""
  7. host = "mqtt.dioty.co"
  8. port = 1883
  9.  
  10. #set up the gpio
  11. gpio.setwarnings(false)
  12. gpio.setmode(gpio.board)
  13. gpio.setup(11, gpio.out)
  14.  
  15. def on_connect(client, userdata, flags, rc):
  16. client.subscribe("/@gmail.com/on")
  17. print("connected...\n")
  18.  
  19.  
  20. def on_message(client, userdata, msg):
  21. print(msg.topic+" "+str(msg.payload))
  22. client.publish("/@gmail.com/connected", str(msg.payload), qos=0, retain=False)
  23. # if str(msg.payload) == b'true':
  24. # x = x
  25.  
  26.  
  27. def on_disconnect(client, userdata, rc):
  28. if rc != 0:
  29. print("Unexpected disconnection.")
  30.  
  31. client = mqtt.Client()
  32. client.on_connect = on_connect
  33. client.on_message = on_message
  34. client.on_disconnect = on_disconnect
  35.  
  36. client.username_pw_set(username, password)
  37. client.connect(host, port, 60)
  38.  
  39.  
  40.  
  41. client.loop_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement