mqtt_client.py 661 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: AnsjerFormal
  7. @software: PyCharm
  8. @DATE: 2019/3/7 9:43
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: mqtt_client.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. import paho.mqtt.client as mqtt
  15. HOST = "192.168.136.45"
  16. PORT = 1883
  17. def test():
  18. client = mqtt.Client()
  19. client.username_pw_set(username='我是设备aa',password='xxxxxxx')
  20. client.connect(HOST, PORT, 60)
  21. client.publish("chat", "lalalallalalalalal", 2)
  22. # client.loop()
  23. client.loop_forever()
  24. if __name__ == '__main__':
  25. test()