-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqttp
55 lines (46 loc) · 1.61 KB
/
mqttp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Import paho-mqtt Client class:
import paho.mqtt.client as mqtt
import threading
from threading import Thread
import time
f=open('rnd.list.5000')
lines=f.readlines()
n=-1
#def on_connect(client, userdata, flags, rc):
# print("Connection returned with result code:" + str(rc))
#def on_publish(client, userdata, mid):
# print(mid)
def on_disconnect(client, userdata, rc):
# print("Disconnection returned result:"+ str(rc))
# print(threading.active_count())
global n
n += 1
if n <5000:
t = Thread(target=publish, args=(n,))
t.start()
else:
exit
def publish(n):
print("Run: "+str(n))
client = mqtt.Client()
client.on_disconnect= on_disconnect
#client.tls_set(ca_certs="ca.crt", certfile="server.crt", keyfile="server.key")
#client.tls_insecure_set(True)
#client.connect("10.1.4.31", 8883, 60)
#client.connect("10.1.255.56", 1883, 60)
client.connect("emqx-openshift", 1883, 60)
client.loop_start()
#client.publish("a"+str(n), payload = "Hello world!", qos=1)
#ret=client.publish("my/topic", payload = lines[n].rstrip('\n'), qos=1)
ret=client.publish("topic", payload = lines[n].rstrip('\n'), qos=1)
client.loop_stop()
time.sleep(0.25)
client.disconnect()
return 0
for i in range(50):
n += 1
if n <5000:
t = Thread(target=publish, args=(n,))
t.start()
else:
exit