Exemple #1
0
		context["state"] = "publishing qos 2"
		print "rc from publish is", mqttv3.send(client, topic, "a QoS 2 message", 2, 0, responseOptions)
	elif context["state"] == "publishing qos 2":
		context["state"] = "finished"
	print "leaving onSuccess"
	
def onFailure(context, failureData):
	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:
Exemple #2
0
		context["state"] = "publishing qos 2"
		print "rc from publish is", mqttv3.send(client, topic, "a QoS 2 message", 2, 0, responseOptions)
	elif context["state"] == "publishing qos 2":
		context["state"] = "finished"
	print "leaving onSuccess"
	
def onFailure(context, failureData):
	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, 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"]
Exemple #3
0
        context["state"] = "finished"
    print "leaving onSuccess"


def onFailure(context, failureData):
    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,
                               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,
Exemple #4
0
def connected(context, cause):
    print("connected", cause)


def on_success(context, success_data):
    print("on_success", success_data)


def on_failure(context, failure_data):
    print("on_failure", failure_data)


rc, client = mqttv3.create(
    'tcp://%s:%s' %
    (os.getenv("MQTT_SERVER_HOST"), os.getenv("MQTT_SERVER_PORT")),
    os.getenv('MQTT_CLIENT_ID'), mqttv3.PERSISTENCE_DEFAULT, {
        '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,