Skip to content

Instantly share code, notes, and snippets.

@li2hub
Last active February 25, 2019 15:18
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 li2hub/908e9f663f47a7c0d4428395457bdcba to your computer and use it in GitHub Desktop.
Save li2hub/908e9f663f47a7c0d4428395457bdcba to your computer and use it in GitHub Desktop.
import paho.mqtt.client as paho
broker="192.168.xx.xxx" #IP of your Raspberry Pi
def on_message(client, userdata, message):
print("received message =",str(message.payload.decode("utf-8")))
client= paho.Client("client-001")
client.on_message=on_message
print("connecting to broker ",broker)
client.connect(broker)
print("subscribing ")
client.subscribe("sensor_data")
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment