def connectionLost(context, cause): print "connectionLost" print "rc from reconnect is", mqttv3.connect(self.client)
print "onFailure for", context["clientid"] context["state"] = "finished" noclients = 1 myclientid = None clients = [] for i in range(noclients): myclientid = clientid+str(i) rc, client = mqttv3.create("tcp://"+hostname+":1883", myclientid) #print "client is", hex(client) print "rc from create is", rc print "rc from setcallbacks is", mqttv3.setcallbacks(client, client, connectionLost, messageArrived, deliveryComplete) context = {"client" : client, "clientid" : clientid, "state" : "connecting"} print "rc from connect is", mqttv3.connect(client, {"context": context, "onSuccess": onSuccess, "onFailure": onFailure}) clients.append(context) while [x for x in clients if x["state"] != "finished"]: print [x for x in clients if x["state"] != "finished"] time.sleep(1) for client in clients: if mqttv3.isConnected(client["client"]): print "rc from disconnect is", mqttv3.disconnect(client["client"], 1000) time.sleep(1) mqttv3.destroy(client["client"]) print "after destroy"
noclients = 1 myclientid = None clients = [] for i in range(noclients): myclientid = clientid+str(i) rc, client = mqttv3.create("tcp://"+hostname+":1883", myclientid, mqttv3.PERSISTENCE_DEFAULT, {"sendWhileDisconnected" : 1}) #print "client is", hex(client) print "rc from create is", rc print "rc from setcallbacks is", mqttv3.setcallbacks(client, client, connectionLost, messageArrived, deliveryComplete) print "rc from setconnected is", mqttv3.setconnected(client, client, connected) context = {"client" : client, "clientid" : clientid, "state" : "connecting"} print "rc from connect is", mqttv3.connect(client, {"cleansession" : 0, "automaticReconnect": 1, "context": context, "onSuccess": onSuccess, "onFailure": onFailure}) clients.append(context) while [x for x in clients if x["state"] != "finished"]: print [x for x in clients if x["state"] != "finished"] time.sleep(1) print "waiting for 60 seconds" time.sleep(60) for client in clients: if mqttv3.isConnected(client["client"]): print "rc from disconnect is", mqttv3.disconnect(client["client"], 1000) time.sleep(1) mqttv3.destroy(client["client"])
mqttv3.PERSISTENCE_DEFAULT, {"sendWhileDisconnected": 1}) #print "client is", hex(client) print "rc from create is", rc print "rc from setcallbacks is", mqttv3.setcallbacks( client, client, connectionLost, messageArrived, deliveryComplete) print "rc from setconnected is", mqttv3.setconnected( client, client, connected) context = {"client": client, "clientid": clientid, "state": "connecting"} print "rc from connect is", mqttv3.connect( client, { "cleansession": 0, "automaticReconnect": 1, "context": context, "onSuccess": onSuccess, "onFailure": onFailure }) clients.append(context) while [x for x in clients if x["state"] != "finished"]: print[x for x in clients if x["state"] != "finished"] time.sleep(1) print "waiting for 60 seconds" time.sleep(60) for client in clients: if mqttv3.isConnected(client["client"]):
'sendWhileDisconnected': 1, 'maxBufferedMessages': 100000 }) print('mqttv3.create(), rc = %d' % rc) context = {'client': client} rc = mqttv3.setcallbacks(client, client, connection_lost, message_arrived, delivery_complete) print('mqttv3.setcallbacks(), rc = %d' % rc) rc = mqttv3.connect( client, { 'keepAliveInterval': int(os.getenv('MQTT_KEEP_ALIVE')), 'cleansession': 0, 'automaticReconnect': 1, 'maxRetryInterval': 10, 'context': context, 'on_success': on_success, 'on_failure': on_failure }) print('mqttv3.connect(), rc = %d' % rc) count = 0 while True: payload = str(count) print("OUT => " + payload) rc, _ = mqttv3.send(client, os.environ['MQTT_TOPIC'], payload, int(os.environ['MQTT_QOS']), 0, {}) print('mqttv3.send(), rc = %d' % rc) time.sleep(1)