当前位置: 首页>>代码示例>>Python>>正文


Python MQTTClient.unsubscribe方法代码示例

本文整理汇总了Python中hbmqtt.client.MQTTClient.unsubscribe方法的典型用法代码示例。如果您正苦于以下问题:Python MQTTClient.unsubscribe方法的具体用法?Python MQTTClient.unsubscribe怎么用?Python MQTTClient.unsubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hbmqtt.client.MQTTClient的用法示例。


在下文中一共展示了MQTTClient.unsubscribe方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
 def test_coro():
     try:
         broker = Broker(broker_config, plugin_namespace="hbmqtt.test.plugins")
         yield from broker.start()
         client = MQTTClient()
         yield from client.connect('mqtt://127.0.0.1/')
         self.assertIsNotNone(client.session)
         ret = yield from client.subscribe([
             ('test_topic', QOS_0),
         ])
         self.assertEqual(ret[0], QOS_0)
         client_pub = MQTTClient()
         yield from client_pub.connect('mqtt://127.0.0.1/')
         yield from client_pub.publish('test_topic', data, QOS_0)
         yield from client_pub.disconnect()
         message = yield from client.deliver_message()
         self.assertIsNotNone(message)
         self.assertIsNotNone(message.publish_packet)
         self.assertEqual(message.data, data)
         yield from client.unsubscribe(['$SYS/broker/uptime'])
         yield from client.disconnect()
         yield from broker.shutdown()
         future.set_result(True)
     except Exception as ae:
         future.set_exception(ae)
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:27,代码来源:test_client.py

示例2: test_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
 def test_coro():
     try:
         client = MQTTClient()
         yield from client.connect('mqtt://test.mosquitto.org/')
         self.assertIsNotNone(client.session)
         ret = yield from client.subscribe([
             ('$SYS/broker/uptime', QOS_0),
         ])
         self.assertEquals(ret[0], QOS_0)
         yield from client.unsubscribe(['$SYS/broker/uptime'])
         yield from client.disconnect()
         future.set_result(True)
     except Exception as ae:
         future.set_exception(ae)
开发者ID:FlorianLudwig,项目名称:hbmqtt,代码行数:16,代码来源:test_client.py

示例3: uptime_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
def uptime_coro():
    C = MQTTClient()
    yield from C.connect('mqtt://localhost/')
    yield from C.subscribe([
            ('sputnik/test', QOS_1),
         ])
    try:
        for i in range(1, 100):
            message = yield from C.deliver_message()
            packet = message.publish_packet
            print("%d:  %s => %s" % (i, packet.variable_header.topic_name, str(packet.payload.data)))
        yield from C.unsubscribe(['sputnik/test'])
        yield from C.disconnect()
    except ClientException as ce:
        logger.error("Client exception: %s" % ce)
开发者ID:helgrind,项目名称:sputnik,代码行数:17,代码来源:mqtt.py

示例4: main

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
 def main(self):
     client = MQTTClient()
     yield from client.connect('mqtt://localhost:1883/')
     for key in self.__registry.keys():
         yield from client.subscribe([{'filter': key, 'qos': 0x00}])
     while True:
         packet = yield from client.deliver_message()
         log.debug("%s : %s" % (packet.variable_header.topic_name, str(packet.payload.data)))
         try:
             #yield from self.getSensor("pressure-main").setValue(float(packet.payload.data))
             self.update(packet.variable_header.topic_name, packet.payload.data)
         except Exception as exception:
             log.exception(exception)
         yield from client.acknowledge_delivery(packet.variable_header.packet_id)
     for key in self.__registry.keys():
         yield from client.unsubscribe([key])
     yield from client.disconnect()
开发者ID:simudream,项目名称:poupool,代码行数:19,代码来源:mqtt.py

示例5: uptime_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
def uptime_coro():
    C = MQTTClient()
    yield from C.connect('mqtt://test.mosquitto.org/')
    # Subscribe to '$SYS/broker/uptime' with QOS=1
    yield from C.subscribe([
        ('$SYS/broker/uptime', QOS_1),
        ('$SYS/broker/load/#', QOS_2),
    ])
    logger.info("Subscribed")
    try:
        for i in range(1, 100):
            message = yield from C.deliver_message()
            packet = message.publish_packet
            print("%d: %s => %s" % (i, packet.variable_header.topic_name, str(packet.payload.data)))
        yield from C.unsubscribe(['$SYS/broker/uptime', '$SYS/broker/load/#'])
        logger.info("UnSubscribed")
        yield from C.disconnect()
    except ClientException as ce:
        logger.error("Client exception: %s" % ce)
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:21,代码来源:client_subscribe.py

示例6: uptime_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
def uptime_coro():
    C = MQTTClient()
    yield from C.connect('mqtt://test:[email protected]:1883')
    # yield from C.connect('mqtt://0.0.0.0:1883')
    # Subscribe to '$SYS/broker/uptime' with QOS=1
    yield from C.subscribe([
        ('data/memes', QOS_1),  # Topic allowed
        ('data/classified', QOS_1),  # Topic forbidden
        ('repositories/hbmqtt/master', QOS_1),  # Topic allowed
        ('repositories/hbmqtt/devel', QOS_1),  # Topic forbidden
        ('calendar/hbmqtt/releases', QOS_1),  # Topic allowed
    ])
    logger.info("Subscribed")
    try:
        for i in range(1, 100):
            message = yield from C.deliver_message()
            packet = message.publish_packet
            print("%d: %s => %s" % (i, packet.variable_header.topic_name, str(packet.payload.data)))
        yield from C.unsubscribe(['$SYS/broker/uptime', '$SYS/broker/load/#'])
        logger.info("UnSubscribed")
        yield from C.disconnect()
    except ClientException as ce:
        logger.error("Client exception: %s" % ce)
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:25,代码来源:client_subscribe_acl.py

示例7: test_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import unsubscribe [as 别名]
        def test_coro():
            try:
                broker = Broker(test_config, plugin_namespace="hbmqtt.test.plugins")
                yield from broker.start()
                self.assertTrue(broker.transitions.is_started())
                client = MQTTClient()
                ret = yield from client.connect('mqtt://127.0.0.1/')
                self.assertEqual(ret, 0)
                yield from client.subscribe([('/topic', QOS_0)])

                # Test if the client test client subscription is registered
                self.assertIn('/topic', broker._subscriptions)
                subs = broker._subscriptions['/topic']
                self.assertEqual(len(subs), 1)
                (s, qos) = subs[0]
                self.assertEqual(s, client.session)
                self.assertEqual(qos, QOS_0)

                yield from client.unsubscribe(['/topic'])
                yield from asyncio.sleep(0.1)
                self.assertEqual(broker._subscriptions['/topic'], [])
                yield from client.disconnect()
                yield from asyncio.sleep(0.1)
                yield from broker.shutdown()
                self.assertTrue(broker.transitions.is_stopped())
                MockPluginManager.assert_has_calls(
                    [
                        call().fire_event(EVENT_BROKER_CLIENT_SUBSCRIBED,
                                          client_id=client.session.client_id,
                                          topic='/topic', qos=QOS_0),
                        call().fire_event(EVENT_BROKER_CLIENT_UNSUBSCRIBED,
                                          client_id=client.session.client_id,
                                          topic='/topic')
                    ], any_order=True)
                future.set_result(True)
            except Exception as ae:
                future.set_exception(ae)
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:39,代码来源:test_broker.py


注:本文中的hbmqtt.client.MQTTClient.unsubscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。