def reg_handler(msg): global topic_reg_rep, topic_reg_rep_base global edge_capability dict = json.loads(msg.payload) Log.v('reg_handler', dict) edgeId = dict['client_id'] topic_reg_rep = topic_reg_rep_base + edgeId if edgeId == None: Log.e('reg_handler', 'Request without edge id: ' + dict) payload = json.dumps({"code":100,"message":"without edge id"}) elif dict.get('disk') == None: payload = json.dumps({"code":100,"message":"without disk data"}) elif dict.get('memory') == None: payload = json.dumps({"code":100,"message":"without memory data"}) elif dict.get('cpu') == None: payload = json.dumps({"code":100,"message":"without cpu data"}) else: edge_capability[edgeId] = {} edge_capability[edgeId]['broker'] = dict['broker'] edge_capability[edgeId]['disk'] = dict['disk'] edge_capability[edgeId]['memory'] = dict['memory'] edge_capability[edgeId]['cpu'] = dict['cpu'] payload = json.dumps({"code":200, "message":"success"}) Log.v('reg_handler', 'Pub topic: {}'.format(topic_reg_rep)) Log.v('reg_handler', 'Pub payload: {}'.format(payload)) client.publish(topic_reg_rep, payload, qos = 2, retain = False)
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()