Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Last active March 1, 2018 06:03
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 LarsBergqvist/f32c5446380029236167912697ee8a19 to your computer and use it in GitHub Desktop.
Save LarsBergqvist/f32c5446380029236167912697ee8a19 to your computer and use it in GitHub Desktop.
MQTT subscriber client that listens to all messages within "Home"
import paho.mqtt.client as mqtt
import datetime
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("Home/#")
def on_message(client, userdata, msg):
print(str(datetime.datetime.now()) + ": " + msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.1.16", 1883, 60)
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment