Skip to content

Instantly share code, notes, and snippets.

@li2hub
Created February 19, 2019 15:36
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/b139a8ee5a017ae6ab9eeafca8a047fd to your computer and use it in GitHub Desktop.
Save li2hub/b139a8ee5a017ae6ab9eeafca8a047fd to your computer and use it in GitHub Desktop.
import time
import paho.mqtt.client as paho
broker="192.168.x.xxx" #IP of your Raspberry Pi
#define callback
def on_message(client, userdata, message):
time.sleep(1)
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("nodemcu")
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment