diff --git a/intomqtt/lab_simple_pub.py b/intomqtt/lab_simple_pub.py new file mode 100644 index 0000000..67659a9 --- /dev/null +++ b/intomqtt/lab_simple_pub.py @@ -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) \ No newline at end of file diff --git a/intomqtt/lab_simple_sub.py b/intomqtt/lab_simple_sub.py new file mode 100644 index 0000000..e888874 --- /dev/null +++ b/intomqtt/lab_simple_sub.py @@ -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() \ No newline at end of file diff --git a/intomqtt/lec_simple_pub.py b/intomqtt/lec_simple_pub.py new file mode 100644 index 0000000..92ef9c4 --- /dev/null +++ b/intomqtt/lec_simple_pub.py @@ -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) \ No newline at end of file diff --git a/intomqtt/lec_simple_sub.py b/intomqtt/lec_simple_sub.py new file mode 100644 index 0000000..2b01868 --- /dev/null +++ b/intomqtt/lec_simple_sub.py @@ -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() \ No newline at end of file diff --git a/intomqtt/mqtt_lecture.pdf b/intomqtt/mqtt_lecture.pdf new file mode 100644 index 0000000..724486f Binary files /dev/null and b/intomqtt/mqtt_lecture.pdf differ