Created
February 18, 2017 23:23
-
-
Save AliYmn/ec31f94301ac00d351d39ed114d65d4e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# This is the Publisher | |
client = mqtt.Client() | |
client.connect("ip_Adress",1883,60) | |
client.publish("temp/random", 5) | |
client.disconnect() | |
# ------------------------------- | |
import paho.mqtt.client as mqtt | |
# This is the Subscriber | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code " + str(rc)) | |
client.subscribe("temp/random") | |
def on_message(client, userdata, msg): | |
if msg.payload.decode() == "Hello world!": | |
print("Yes!") | |
client.disconnect() | |
client = mqtt.Client() | |
client.connect("server_ip", 1883, 60) | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.loop_forever() | |
# Source = http://www.ev3dev.org/docs/tutorials/sending-and-receiving-messages-with-mqtt/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment