Skip to content
Permalink
Browse files
Merge pull request #1 from ac0745/master
mqtt materials
  • Loading branch information
aa7401 committed Dec 31, 2017
2 parents 33778c4 + 7782a0d commit 0f73a27bc293cc1982e46684ca6ffe28e98f43c4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
@@ -0,0 +1,18 @@
import paho.mqtt.client as mqtt
import time

MYTOPIC = "PutSomethingUniqueHere"

mqttc = mqtt.Client()
mqttc.connect( "iot.eclipse.org" ) # test broker

counter = 0
while True:
message = "Hello World {}!".format(counter)

print( message )
mqttc.publish( MYTOPIC + "/counter", message )
mqttc.loop()

counter += 1
time.sleep(2)
@@ -0,0 +1,18 @@
import paho.mqtt.client as mqtt

MYTOPIC = "PutSomethingUniqueHere"

def on_connect( client, userdata, rc ):
""" callback function for client connection """
client.subscribe( MYTOPIC + "/counter")

def on_message( client, userdata, msg ):
""" callback function for messages received """
print( "Topic: {}, Message: {}".format(msg.topic, msg.payload) )

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect( "iot.eclipse.org" ) # test broker
client.loop_forever()
@@ -0,0 +1,16 @@
import paho.mqtt.client as mqtt
import time

mqttc = mqtt.Client()
mqttc.connect( "iot.eclipse.org" ) # test broker

counter = 0
while True:
message = "Hello World {}!".format(counter)

print( message )
mqttc.publish( "mytest/counter", message )
mqttc.loop()

counter += 1
time.sleep(2)
@@ -0,0 +1,16 @@
import paho.mqtt.client as mqtt

def on_connect( client, userdata, rc ):
""" callback function for client connection """
client.subscribe( "mytest/counter")

def on_message( client, userdata, msg ):
""" callback function for messages received """
print( "Topic: {}, Message: {}".format(msg.topic, msg.payload) )

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect( "iot.eclipse.org" ) # test broker
client.loop_forever()
Binary file not shown.

0 comments on commit 0f73a27

Please sign in to comment.