Skip to content
Permalink
Browse files
mqtt materials
  • Loading branch information
David Croft committed Dec 27, 2017
1 parent bc0f75d commit 7782a0dd9f4d60aebdeb816fbd25d7c114c4da2d
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 7782a0d

Please sign in to comment.