forked from A107CEM-1718BTA/TEACHING-MATERIALS
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
BIN
+181 KB
intomqtt/mqtt_lecture.pdf
Binary file not shown.