def M2M_RxRouting(self, objJsonMsg): class_Node_MQTTManager.SubscriberThreading.callbackST = self.CallBackRxRouting separation_obj_json_msg = copy.copy(objJsonMsg) if separation_obj_json_msg[ "Control"] == "ADDFS": # Recive control from IoT Server for Function Server Topic for fp in separation_obj_json_msg["FSPairs"]: # ["FS1", "M2M", "10.0.0.1", "IOs"] fspair = class_Node_Obj.FSPair(fp[0], fp[1], fp[2], fp[3]) if (fp[1] == "M2M"): try: ReqToFS = { "Node": "%s" % self.nodeUUID, "Control": "M2M_REQTOPICLIST", "Source": "%s" % self.nodeUUID } Send_json = json.dumps(ReqToFS) publisher.MQTT_PublishMessage(fp[0], Send_json) class_Node_MQTTManager.SubscriberThreading( fp[0], self.nodeUUID).start() #call = class_Node_MQTTManager.SubscriberThreading(fp[0], self.nodeUUID) #call.start() #call.join() except (RuntimeError, TypeError, NameError) as e: print(bcolors.FAIL + "[ERROR] Send Request for topic list error!" + str(e) + bcolors.ENDC) return elif separation_obj_json_msg["Control"] == "M2M_REPTOPICLIST": for subTopic in separation_obj_json_msg["SubscribeTopics"]: RuleObj = class_Node_Obj.M2M_RuleObj( subTopic["TopicName"], subTopic["Target"], subTopic["TargetValueOverride"]) ##過濾node多的訊息 # print(subTopic["Node"]+" ---- "+self.nodeUUID) self.Rules.append(RuleObj) if (subTopic["Node"] == self.nodeUUID): class_Node_MQTTManager.SubscriberThreading( subTopic["TopicName"], self.nodeUUID).start() elif separation_obj_json_msg["Control"] == "M2M_SET": for rule in self.Rules: if rule.TopicName == separation_obj_json_msg["TopicName"]: ####### You need custom something here ####### #print( # bcolors.OKGREEN + ">>Trigger<< Rx SET Msg " + rule.Target + " " + rule.TargetValueOverride + bcolors.ENDC) #pe print(bcolors.OKGREEN + "%s >>Parameter<< %s" % (separation_obj_json_msg["TopicName"], separation_obj_json_msg["M2M_Value"]) + bcolors.ENDC) #print(separation_obj_json_msg["M2M_Value"][0]) if (separation_obj_json_msg["M2M_Value"][0] == "TEMP"): return separation_obj_json_msg["M2M_Value"][1] elif (separation_obj_json_msg["M2M_Value"][0] == "DUST"): return separation_obj_json_msg["M2M_Value"][1] elif (separation_obj_json_msg["M2M_Value"][0] == "QUAKE"): return separation_obj_json_msg["M2M_Value"][1]
def M2M_RxRouting(self, objJsonMsg): class_Node_MQTTManager.SubscriberThreading.callbackST = self.CallBackRxRouting separation_obj_json_msg = copy.copy(objJsonMsg) if separation_obj_json_msg[ "Control"] == "ADDFS": # Recive control from IoT Server for Function Server Topic for fp in separation_obj_json_msg["FSPairs"]: # ["FS1", "M2M", "10.0.0.1", "IOs"] fspair = class_Node_Obj.FSPair(fp[0], fp[1], fp[2], fp[3]) if (fp[1] == "M2M"): try: ReqToFS = { "Node": "%s" % self.nodeUUID, "Control": "M2M_REQTOPICLIST", "Source": "%s" % self.nodeUUID } Send_json = json.dumps(ReqToFS) publisher.MQTT_PublishMessage(fp[0], Send_json) class_Node_MQTTManager.SubscriberThreading( fp[0], self.nodeUUID).start() except (RuntimeError, TypeError, NameError) as e: print(bcolors.FAIL + "[ERROR] Send Request for topic list error!" + str(e) + bcolors.ENDC) return elif separation_obj_json_msg["Control"] == "M2M_REPTOPICLIST": if separation_obj_json_msg[ "Gateway"] == "B0107@NODE-8c987879-958f-44e4-b1ac-010701070107": for subTopic in separation_obj_json_msg["SubscribeTopics"]: RuleObj = class_Node_Obj.M2M_RuleObj( subTopic["TopicName"], subTopic["Target"], subTopic["TargetValueOverride"]) self.Rules.append(RuleObj) class_Node_MQTTManager.SubscriberThreading( subTopic["TopicName"], self.nodeUUID).start() elif separation_obj_json_msg["Control"] == "M2M_SET": if separation_obj_json_msg["Room"] == "B0107": for rule in self.Rules: if rule.TopicName == separation_obj_json_msg["TopicName"]: key = rule.TargetValueOverride ser = serial.Serial('/dev/ttyACM0', 9600) ser.write(bytes(key, 'UTF-8')) ####### You need custom something here ####### print(bcolors.OKGREEN + ">>Trigger<< Rx SET Msg " + rule.Target + " " + rule.TargetValueOverride + bcolors.ENDC)
def M2M_RxRouting(self, objJsonMsg): class_Node_MQTTManager.SubscriberThreading.callbackST = self.CallBackRxRouting separation_obj_json_msg = copy.copy(objJsonMsg) if separation_obj_json_msg[ "Control"] == "ADDFS": # Recive control from IoT Server for Function Server Topic for fp in separation_obj_json_msg["FSPairs"]: # ["FS1", "M2M", "10.0.0.1", "IOs"] fspair = class_Node_Obj.FSPair(fp[0], fp[1], fp[2], fp[3]) if (fp[1] == "M2M"): try: ReqToFS = { "Node": "%s" % self.nodeUUID, "Control": "M2M_REQTOPICLIST", "Source": "%s" % self.nodeUUID } Send_json = json.dumps(ReqToFS) publisher.MQTT_PublishMessage(fp[0], Send_json) class_Node_MQTTManager.SubscriberThreading( fp[0], self.nodeUUID).start() except (RuntimeError, TypeError, NameError) as e: print(bcolors.FAIL + "[ERROR] Send Request for topic list error!" + str(e) + bcolors.ENDC) return if (fp[1] == "Guide"): try: ReqToFS = { "Node": "%s" % self.nodeUUID, "Control": "Guide_REQTOPICLIST", "Source": "%s" % self.nodeUUID } Send_json = json.dumps(ReqToFS) publisher.MQTT_PublishMessage(fp[0], Send_json) class_Node_MQTTManager.SubscriberThreading( fp[0], self.nodeUUID).start() except (RuntimeError, TypeError, NameError) as e: print(bcolors.FAIL + "[ERROR] Send Request for topic list error!" + str(e) + bcolors.ENDC) return elif separation_obj_json_msg["Control"] == "M2M_REPTOPICLIST": for subTopic in separation_obj_json_msg["SubscribeTopics"]: RuleObj = class_Node_Obj.M2M_RuleObj( subTopic["TopicName"], subTopic["Target"], subTopic["TargetValueOverride"]) self.Rules.append(RuleObj) class_Node_MQTTManager.SubscriberThreading( subTopic["TopicName"], self.nodeUUID).start() elif separation_obj_json_msg["Control"] == "Guide_REPTOPICLIST": for subTopic in separation_obj_json_msg["SubscribeTopics"]: RuleObj = class_Node_Obj.M2M_RuleObj( subTopic["TopicName"], subTopic["Target"], subTopic["TargetValueOverride"]) self.Rules.append(RuleObj) class_Node_MQTTManager.SubscriberThreading( subTopic["TopicName"], self.nodeUUID).start() elif separation_obj_json_msg["Control"] == "CALL": for rule in self.Rules: if rule.TopicName == separation_obj_json_msg["TopicName"]: ####### You need custom something here ####### print(bcolors.OKGREEN + ">>WARNING<< FROM THE INFROMATION DESK: " + separation_obj_json_msg["MSG"] + rule.Target + " " + bcolors.ENDC)