examples/pubsubs.py
def connectToBroker(self, protocol):
        '''
        Connect to MQTT broker
        '''
        self.protocol                 = protocol
        self.protocol.onPublish       = self.onPublish
        self.protocol.onDisconnection = self.onDisconnection
        self.protocol.setWindowSize(3)
        self.task = task.LoopingCall(self.publish)
        self.task.start(5.0, now=False) 
        try:
            yield self.protocol.connect("TwistedMQTT-pubsubs", keepalive=60)
            yield self.subscribe()
        except Exception as e:
            log.error("Connecting to {broker} raised {excp!s}", 
               broker=BROKER, excp=e)
        else:
            log.info("Connected and subscribed to {broker}", broker=BROKER)
def connectToBroker(self, protocol):
        '''
        Connect to MQTT broker
        '''
        self.protocol                 = protocol
        self.protocol.onPublish       = self.onPublish
        self.protocol.onDisconnection = self.onDisconnection
        self.protocol.setWindowSize(3)
        self.task = task.LoopingCall(self.publish)
        self.task.start(5.0, now=False) 
        try:
            yield self.protocol.connect("TwistedMQTT-pubsubs", keepalive=60)
            yield self.subscribe()
        except Exception as e:
            log.error("Connecting to {broker} raised {excp!s}", 
               broker=BROKER, excp=e)
        else:
            log.info("Connected and subscribed to {broker}", broker=BROKER)
def connectToBroker ( self , protocol ) : self . protocol = protocol self . protocol . onPublish = self . onPublish self . protocol . onDisconnection = self . onDisconnection self . protocol . setWindowSize ( 3 ) self . task = task . LoopingCall ( self . publish ) self . task . start ( 5.0 , now = False ) try : yield self . protocol . connect ( "TwistedMQTT-pubsubs" , keepalive = 60 ) yield self . subscribe ( ) except Exception as e : log . error ( "Connecting to {broker} raised {excp!s}" , broker = BROKER , excp = e ) else : log . info ( "Connected and subscribed to {broker}" , broker = BROKER )
Connect to MQTT broker
Connect to MQTT broker