def on_e_connect(client, userdata, flag, rc): if rc == 0: Log.i('on_e_connect', 'Edge broker connected ...') client.subscribe(topic_off_rep, 2) else: Log.e('on_e_connect', 'Connection refused with rc ({}).'.format(rc)) Log.e('on_e_connect', 'Stop connecting edge broker ...') client.loop_stop()
def on_e_connect(client, userdata, flags, rc): if rc == 0: Log.i('on_e_connect', 'Edge broker connected ...') client.subscribe(topic_off_req, 2) else: Log.e('on_e_connect', 'Connection refused with rc ({}).'.format(rc)) Log.e('on_e_connect', 'Shutting down edge') exit()
def on_connect(client, userdata, flags, rc): if rc == 0: Log.i('on_connect', 'Mediator broker connected ...') client.subscribe([(topic_reg_req, 2),(topic_sch_req, 2)]) else: Log.e('on_connect', 'Connection refused with rc ({}).'.format(rc)) Log.e('on_connect', 'Shutting down mediator') client.loop_stop() exit()
def start_mediator(): global client, clientId global username, password global broker, port, loop Log.v('start_mediator', 'Starting mediator ...') # Connect to mediator broker Log.v('start_mediator', 'Connecting mediator broker ...') client = mqtt.Client(clientId) client.username_pw_set(username, password) client.on_connect = on_connect client.on_message = on_message client.on_subscribe = on_subscribe client.connect(broker, port) client.loop_start() loop = True try: while loop: pass except KeyboardInterrupt: Log.i('start_mediator', 'Mediator stopped with Ctrl + C ...') exit()