def connectionLost(context, cause): print "connectionLost" print "rc from reconnect is", mqttv3.connect(self.client)
return 1 print messageArrived myclientid = None clients = [] for i in range(noclients): myclientid = clientid + str(i) rc, client = mqttv3.create("tcp://" + host + ":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) print "client is", hex(client) print "rc from connect is", mqttv3.connect(client, {}) clients.append(client) for client in clients: print "rc from subscribe is", mqttv3.subscribe(client, "$SYS/#") for client in clients: print "rc from publish is", mqttv3.publish(client, "a topic", "a message") print "rc from publish is", mqttv3.publish(client, "a topic", "a message", 1) print "rc from publish is", mqttv3.publish(client, "a topic", "a message", 2) print "about to sleep" time.sleep(10) print "finished sleeping"
'tcp://%s:%s' % (os.getenv("MQTT_SERVER_HOST"), os.getenv("MQTT_SERVER_PORT")), os.getenv('MQTT_CLIENT_ID'), mqttv3.PERSISTENCE_DEFAULT) 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.publish(client, os.environ['MQTT_TOPIC'], payload, int(os.environ['MQTT_QOS']), 0) print('mqttv3.send(), rc = %d' % rc) time.sleep(1)
print "topicName", topicName print "message", message return 1 print messageArrived myclientid = None clients = [] for i in range(noclients): myclientid = clientid+str(i) rc, client = mqttv3.create("tcp://"+host+":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) print "client is", hex(client) print "rc from connect is", mqttv3.connect(client, {}) clients.append(client) for client in clients: print "rc from subscribe is", mqttv3.subscribe(client, "$SYS/#") for client in clients: print "rc from publish is", mqttv3.publish(client, "a topic", "a message") print "rc from publish is", mqttv3.publish(client, "a topic", "a message", 1) print "rc from publish is", mqttv3.publish(client, "a topic", "a message", 2) print "about to sleep" time.sleep(10) print "finished sleeping" for client in clients: