Created
November 15, 2015 04:24
-
-
Save nakagami/671c9abca98c43d9936f to your computer and use it in GitHub Desktop.
A sample of MQTT publisher (QoS=0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2.7 | |
| from __future__ import print_function | |
| import datetime | |
| import time | |
| import paho.mqtt.client as mqtt # https://pypi.python.org/pypi/paho-mqtt/ | |
| topic = "foo/bar" | |
| if __name__ == '__main__': | |
| client = mqtt.Client(protocol=mqtt.MQTTv311) | |
| client.username_pw_set('publisher', 'pass') | |
| client.connect('localhost') | |
| for i in range(100): | |
| s = str(datetime.datetime.now()) | |
| print("send message :%s:%s" % (topic, s)) | |
| client.publish(topic, s) | |
| time.sleep(1) | |
| client.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment