1 import paho_mqtt3c
as mqttv3, time, random
6 clientid =
"myclientid" 10 print "deliveryComplete", msgid
13 print "connectionLost" 14 print "rc from reconnect is", mqttv3.connect(self.client)
17 print "clientid", context
18 print "topicName", topicName
19 print "message", message
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)
36 for client
in clients:
37 print "rc from subscribe is", mqttv3.subscribe(client,
"$SYS/#")
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)
44 print "about to sleep" 46 print "finished sleeping" 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)
def connectionLost(context, cause)
def messageArrived(context, topicName, message)
def deliveryComplete(context, msgid)