diff --git a/python_banyan/performance_comparison/mqpub.py b/python_banyan/performance_comparison/mqpub.py index 8d2ff3a..43eb3bc 100644 --- a/python_banyan/performance_comparison/mqpub.py +++ b/python_banyan/performance_comparison/mqpub.py @@ -1,4 +1,5 @@ import paho.mqtt.client as mqtt +import socket import sys import time import umsgpack @@ -18,7 +19,13 @@ def __init__(self): """ super(MQPUB, self).__init__() - self.connect('192.168.2.192', 1883, 60) + # determine current IP address of the local computer + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + # use the google dns + s.connect(('8.8.8.8', 0)) + self.ip_address = s.getsockname()[0] + + self.connect(self.ip_address, 1883, 60) print("MQPUB Connected - Sending 100000 messages") time.sleep(2) @@ -28,14 +35,6 @@ def __init__(self): packed = umsgpack.packb(payload) self.publish("test", packed) - if x == 45000: - timex = time.asctime(time.localtime(time.time())) - payload2 = {'modulo': x, 'time': timex} - packed2 = umsgpack.packb(payload2) - self.publish("m2", packed2) - print('m2 message: ' + str(x) + ' ' + timex) - - localtime = time.asctime(time.localtime(time.time())) print('Task completed on: ', localtime) diff --git a/python_banyan/performance_comparison/mqsub.py b/python_banyan/performance_comparison/mqsub.py index 0472f3b..0b430c4 100644 --- a/python_banyan/performance_comparison/mqsub.py +++ b/python_banyan/performance_comparison/mqsub.py @@ -1,5 +1,6 @@ import sys import time +import socket import paho.mqtt.client as mqtt import umsgpack @@ -25,16 +26,20 @@ def __init__(self): self.end = 0 self.message_count = 0 - self.connect('192.168.2.192', 1883, 60) - self.subscribe("test", 0) - self.subscribe("m2", 0) + # determine current IP address of the local computer + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + # use the google dns + s.connect(('8.8.8.8', 0)) + self.ip_address = s.getsockname()[0] + self.connect(self.ip_address, 1883, 60) + self.subscribe("test", 0) self.loop_forever() def on_connect(self, mqttc, obj, flags, rc): """ - Let the use know we are connected + Let the user know we are connected :param mqttc: unused :param obj: unused :param flags: unused @@ -75,10 +80,6 @@ def on_message(self, mqttc, obj, msg): time.sleep(1) self.loop_stop() sys.exit(0) - elif msg.topic == 'm2': - mg = umsgpack.unpackb(msg.payload) - if mg['modulo'] == 45000: - print(msg.payload) else: print('unkown topic' + msg.topic)