def connect2(self, host, port, newsocket,cleanstart, keepalive, protocolName,willFlag, willTopic, willMessage, willQoS, willRetain,properties, willProperties, username, password): if newsocket: try: self.sock.close() except: pass socket.setdefaulttimeout(5) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.settimeout(5) self.sock.connect((host, port)) connect = MQTTV5.Connects() connect.ClientIdentifier = self.clientid connect.CleanStart = cleanstart connect.KeepAliveTimer = keepalive if protocolName: connect.ProtocolName = protocolName if willFlag: connect.WillFlag = True connect.WillTopic = willTopic connect.WillMessage = willMessage connect.WillQoS = willQoS connect.WillRETAIN = willRetain if willProperties: connect.WillProperties = willProperties if username: connect.usernameFlag = True connect.username = username if password: connect.passwordFlag = True connect.password = password if properties: connect.properties = properties sendtosocket(self.sock, connect.pack()) response = MQTTV5.unpackPacket(MQTTV5.getPacket(self.sock)) if not response: raise MQTTV5.MQTTException("connect failed - socket closed, no connack") assert response.fh.PacketType == MQTTV5.PacketTypes.CONNACK self.cleanstart = cleanstart # print("response =") # print(response) assert response.reasonCode.getName() == "Success", "connect was %s" % str(response) if self.cleanstart or self.__receiver == None: self.__receiver = internal.Receivers(self.sock) else: self.__receiver.socket = self.sock if self.callback: id = _thread.start_new_thread(self.__receiver, (self.callback,)) return response
def local_connect(self): # connect locally with V5, so we get noLocal and retainAsPublished connect = MQTTV5.Connects() connect.ClientIdentifier = "local" broker5.connect(self, connect) subscribe = MQTTV5.Subscribes() options = MQTTV5.SubscribeOptions() options.noLocal = options.retainAsPublished = True subscribe.data = [('+', options)] broker5.subscribe(self, subscribe)
def local_connect(self): # connect locally with V5, so we get noLocal and retainAsPublished connect = MQTTV5.Connects() connect.ClientIdentifier = self.name logger.debug("Bridge: local_connect:" + connect.ClientIdentifier) broker5.connect(self, connect) subscribe = MQTTV5.Subscribes() options = MQTTV5.SubscribeOptions() options.noLocal = options.retainAsPublished = True subscribe.data = [(self.topic, options)] broker5.subscribe(self, subscribe)