Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYsLab authored and MrYsLab committed Sep 4, 2017
1 parent 9472246 commit 1901fdd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 8 additions & 9 deletions python_banyan/performance_comparison/mqpub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import paho.mqtt.client as mqtt
import socket
import sys
import time
import umsgpack
Expand All @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions python_banyan/performance_comparison/mqsub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import time
import socket

import paho.mqtt.client as mqtt
import umsgpack
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1901fdd

Please sign in to comment.