Skip to content

Instantly share code, notes, and snippets.

@oksbwn
Created April 28, 2020 07:46
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 oksbwn/a34ef8918035ca00f7be2338dcb81af3 to your computer and use it in GitHub Desktop.
Save oksbwn/a34ef8918035ca00f7be2338dcb81af3 to your computer and use it in GitHub Desktop.
import paho.mqtt.client as mqtt
import time
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("home/test/in")
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.username_pw_set("<username>", password="<password>")
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.0.7", 1883, 60)
client.loop_start()
while 1:
client.publish("home/test/out", "Test Data")
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment