def do_cloud_connect(self): log.Ilog("do_cloud_connect"); self.set_cloud_connect_attempt_state(True); self.cloud_cli = mqtt.Client(self.app.config[self.app.app_name]['mqtt']['cloud_mqtt_client_id'],True); self.cloud_cli.user_data_set("cloud") self.cloud_cli.on_connect = self.cloud_on_connect; self.cloud_cli.on_message = self.cloud_on_message; self.cloud_cli.on_disconnect = self.cloud_on_disconnect self.cloud_cli.connect(self.app.config[self.app.app_name]['mqtt']['cloud_mqtt_host'],self.app.config[self.app.app_name]['mqtt']['cloud_mqtt_port'],self.app.config[self.app.app_name]['mqtt']['cloud_mqtt_keepalive']) self.cloud_cli.loop_start()
def __init__(self): log.Ilog("mqtt_cli Singleton __init__"); self.app= GW_APP(); ############### # auto connect# ############### self.local_auto_connect = self.app.config[self.app.app_name]['mqtt']['local_mqtt_auto_connect'] self.cloud_auto_connect = self.app.config[self.app.app_name]['mqtt']['cloud_mqtt_auto_connect'] if self.local_auto_connect is True: self.do_local_connect(); if self.cloud_auto_connect is True: self.do_cloud_connect();
def __init__(self,app_name=None,config_file_path=None): log.Ilog("GW_APP Singleton instace __init__"); self.app_name =app_name self.config = config(config_file_path=config_file_path);
def local_on_message(self,client, userdata, msg): log.Ilog("local_on_message");
def local_on_connect(self,client, userdata, flags, rc): log.Ilog("local_on_connect"); self.set_local_connect_state(True);
def set_cloud_connect_state(self,state): log.Ilog("set_cloud_connect_state") self.__cloud_mqtt_connect_state=state
def set_local_connect_state(self,state): log.Ilog("set_local_connect_state") self.__local_mqtt_connect_state =state;
def cloud_on_disconnect(self, _, __, ___): log.Ilog("cloud_on_disconnect") self.set_cloud_connect_state(False)
def cloud_on_message(self,client, userdata, msg): log.Ilog("cloud_on_message") topic = str(msg.topic).split('/'); stre = str(msg.topic)+" "+str(msg.payload);
def cloud_on_connect(self,client, userdata, flags, rc): log.Ilog("cloud_on_connect") self.set_cloud_connect_state(True)
def local_on_disconnect(self, _, __, ___): log.Ilog("local_on_disconnect"); self.set_local_connect_state(False);