kopia lustrzana https://github.com/Yakifo/amqtt
rodzic
e3dffa22e0
commit
18267d148e
|
@ -14,6 +14,12 @@ The example below shows how to write a simple MQTT client which subscribes a top
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from hbmqtt.client import MQTTClient, ClientException
|
||||||
|
from hbmqtt.mqtt.constants import QOS_1, QOS_2
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def uptime_coro():
|
def uptime_coro():
|
||||||
C = MQTTClient()
|
C = MQTTClient()
|
||||||
|
@ -53,6 +59,12 @@ This example also shows to method for publishing message asynchronously.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from hbmqtt.client import MQTTClient
|
||||||
|
from hbmqtt.mqtt.constants import QOS_1, QOS_2
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_coro():
|
def test_coro():
|
||||||
C = MQTTClient()
|
C = MQTTClient()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from hbmqtt.client import MQTTClient
|
from hbmqtt.client import MQTTClient
|
||||||
|
from hbmqtt.mqtt.constants import QOS_1, QOS_2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,8 +29,8 @@ def test_coro():
|
||||||
yield from C.connect('mqtts://test.mosquitto.org/', cafile='mosquitto.org.crt')
|
yield from C.connect('mqtts://test.mosquitto.org/', cafile='mosquitto.org.crt')
|
||||||
tasks = [
|
tasks = [
|
||||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
||||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=QOS_1)),
|
||||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=0x02)),
|
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=QOS_2)),
|
||||||
]
|
]
|
||||||
yield from asyncio.wait(tasks)
|
yield from asyncio.wait(tasks)
|
||||||
logger.info("messages published")
|
logger.info("messages published")
|
||||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from hbmqtt.client import MQTTClient
|
from hbmqtt.client import MQTTClient
|
||||||
|
from hbmqtt.mqtt.constants import QOS_1, QOS_2
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -29,8 +29,8 @@ def test_coro():
|
||||||
yield from C.connect('wss://test.mosquitto.org:8081/', cafile='mosquitto.org.crt')
|
yield from C.connect('wss://test.mosquitto.org:8081/', cafile='mosquitto.org.crt')
|
||||||
tasks = [
|
tasks = [
|
||||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
||||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=QOS_1)),
|
||||||
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=0x02)),
|
asyncio.ensure_future(C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=QOS_2)),
|
||||||
]
|
]
|
||||||
yield from asyncio.wait(tasks)
|
yield from asyncio.wait(tasks)
|
||||||
logger.info("messages published")
|
logger.info("messages published")
|
||||||
|
|
Ładowanie…
Reference in New Issue