Skip to content

Instantly share code, notes, and snippets.

@braitom
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braitom/770d38402457e585f10f to your computer and use it in GitHub Desktop.
Save braitom/770d38402457e585f10f to your computer and use it in GitHub Desktop.
MQTT subscribe sample
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe("test/iOS")
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
if __name__ == '__main__':
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("10.12.0.244", 1883, keepalive=60)
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment