test1.py
Go to the documentation of this file.
1 import paho_mqtt3c as mqttv3, time, random
2 
3 print dir(mqttv3)
4 
5 host = "localhost"
6 clientid = "myclientid"
7 noclients = 4
8 
9 def deliveryComplete(context, msgid):
10  print "deliveryComplete", msgid
11 
12 def connectionLost(context, cause):
13  print "connectionLost"
14  print "rc from reconnect is", mqttv3.connect(self.client)
15 
16 def messageArrived(context, topicName, message):
17  print "clientid", context
18  print "topicName", topicName
19  print "message", message
20  return 1
21 
22 print messageArrived
23 
24 myclientid = None
25 clients = []
26 for i in range(noclients):
27  myclientid = clientid+str(i)
28  rc, client = mqttv3.create("tcp://"+host+":1883", myclientid)
29  print "client is", hex(client)
30  print "rc from create is", rc
31  print "rc from setcallbacks is", mqttv3.setcallbacks(client, client, connectionLost, messageArrived, deliveryComplete)
32  print "client is", hex(client)
33  print "rc from connect is", mqttv3.connect(client, {})
34  clients.append(client)
35 
36 for client in clients:
37  print "rc from subscribe is", mqttv3.subscribe(client, "$SYS/#")
38 
39 for client in clients:
40  print "rc from publish is", mqttv3.publish(client, "a topic", "a message")
41  print "rc from publish is", mqttv3.publish(client, "a topic", "a message", 1)
42  print "rc from publish is", mqttv3.publish(client, "a topic", "a message", 2)
43 
44 print "about to sleep"
45 time.sleep(10)
46 print "finished sleeping"
47 
48 for client in clients:
49  print "rc from isConnected is", mqttv3.isConnected(client)
50  print "rc from disconnect is", mqttv3.disconnect(client)
51  mqttv3.destroy(client)
52 
def connectionLost(context, cause)
Definition: test1.py:12
def messageArrived(context, topicName, message)
Definition: test1.py:16
def deliveryComplete(context, msgid)
Definition: test1.py:9


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48