Created
April 28, 2020 07:46
-
-
Save oksbwn/a34ef8918035ca00f7be2338dcb81af3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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