Skip to content

Instantly share code, notes, and snippets.

@nakagami
Created November 15, 2015 04:24
Show Gist options
  • Select an option

  • Save nakagami/671c9abca98c43d9936f to your computer and use it in GitHub Desktop.

Select an option

Save nakagami/671c9abca98c43d9936f to your computer and use it in GitHub Desktop.
A sample of MQTT publisher (QoS=0)
#!/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