Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import paho.mqtt.client as mqtt
  4.  
  5. def on_connect(client, obj, flags, rc):
  6. print("rc: " + str(rc))
  7.  
  8. def on_message(client, obj, msg):
  9. print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
  10.  
  11. def on_subscribe(client, obj, mid, granted_qos):
  12. print("Subscribed: " + str(mid) + " " + str(granted_qos))
  13.  
  14. client = mqtt.Client()
  15. client.on_connect = on_connect
  16. client.on_message = on_message
  17. client.on_subscribe = on_subscribe
  18.  
  19. client.tls_set(
  20. ca_certs='/opt/wott/certs/ca.crt',
  21. certfile='/opt/wott/certs/client.crt',
  22. keyfile='/opt/wott/certs/client.key'
  23. )
  24.  
  25.  
  26. # disables peer verification
  27. # client.tls_insecure_set(True)
  28.  
  29. # Note that you need to map x.d.wott.local to the IP to the MQTT server
  30. # in /etc/hosts as the hostname must match the CN in the certificate.
  31. client.connect('x.d.wott.local', 8883, 60)
  32.  
  33. client.subscribe('wott/temperature', 0)
  34.  
  35. client.loop_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement