Created
November 15, 2015 04:26
-
-
Save nakagami/f6b6b49a947bae4cabea to your computer and use it in GitHub Desktop.
A sample of MQTT subscriber (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 paho.mqtt.client as mqtt # https://pypi.python.org/pypi/paho-mqtt/ | |
| topic = "foo/bar" | |
| def on_connect(client, userdata, flags, respons_code): | |
| print('connect:status {0}'.format(respons_code)) | |
| client.subscribe(topic) | |
| def on_message(client, userdata, msg): | |
| print("recieve message %s:%s" % (msg.topic, str(msg.payload))) | |
| if __name__ == '__main__': | |
| client = mqtt.Client(protocol=mqtt.MQTTv311) | |
| client.on_connect = on_connect | |
| client.on_message = on_message | |
| client.username_pw_set('subscriber', 'pass') | |
| client.connect('localhost') | |
| client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment