paho.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:kotori 作者: daq-tools 项目源码 文件源码
def connect(self):
        """
        Connect to MQTT broker.
        """
        # TODO: This is currently done synchronous which could have issues in timeout situations
        #       because it would block other subsystems.
        #       => Check if we can do asynchronous connection establishment.
        self.client = mqtt.Client(client_id=self.name, clean_session=True, userdata={'foo': 'bar'})

        if self.broker_username:
            self.client.username_pw_set(self.broker_username, self.broker_password)

        self.client.on_connect = lambda *args: reactor.callFromThread(self.on_connect, *args)
        self.client.on_message = lambda *args: reactor.callFromThread(self.on_message, *args)
        self.client.on_log     = lambda *args: reactor.callFromThread(self.on_log, *args)

        # Connect with retry
        self.connect_loop = LoopingCall(self.connect_with_retry)
        self.connect_loop.start(self.retry_interval, now=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号