Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. ## MQTT
  2. def on_connect(client, userdata, flags, rc):
  3. print(mqtt_topic)
  4. client.subscribe(mqtt_topic,qos=1)
  5. print("Connected")
  6.  
  7. def on_publish(client, userdata, mid):
  8. print("mid: "+str(mid))
  9.  
  10.  
  11. def on_subscribe(client, userdata, mid, granted_qos):
  12. print("Subscribed: "+str(mid)+" "+str(granted_qos))
  13.  
  14. def init_mqtt(client,device_type,device_id,mqtt_host,mqtt_port,mqtt_topic):
  15. jstemp['device_type']=device_type
  16. jstemp['device_id']=device_id
  17. client.on_connect = on_connect
  18. client.on_publish = on_publish
  19. client.on_subscribe=on_subscribe
  20. client.connect(mqtt_host, int(mqtt_port))
  21. print(mqtt_host)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement