2015-06-27 19:38:04 +00:00
|
|
|
import logging
|
|
|
|
import asyncio
|
2015-06-18 17:41:12 +00:00
|
|
|
|
2015-07-07 19:55:17 +00:00
|
|
|
from hbmqtt.client import MQTTClient
|
|
|
|
|
|
|
|
|
2015-07-06 20:19:31 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# This sample shows how to publish messages to broker using different QOS
|
|
|
|
# Debug outputs shows the message flows
|
|
|
|
#
|
|
|
|
|
2015-06-28 20:48:07 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2015-06-27 19:38:04 +00:00
|
|
|
C = MQTTClient()
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_coro():
|
2015-06-30 12:31:19 +00:00
|
|
|
yield from C.connect(uri='mqtt://iot.eclipse.org:1883/', username=None, password=None)
|
2015-06-28 20:48:07 +00:00
|
|
|
tasks = [
|
2015-07-05 20:27:34 +00:00
|
|
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
|
|
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
|
|
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_2', qos=0x02)),
|
2015-06-28 20:48:07 +00:00
|
|
|
]
|
|
|
|
yield from asyncio.wait(tasks)
|
2015-07-06 20:19:31 +00:00
|
|
|
|
2015-06-28 20:48:07 +00:00
|
|
|
logger.info("messages published")
|
2015-06-27 19:38:04 +00:00
|
|
|
yield from C.disconnect()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-06-29 20:38:36 +00:00
|
|
|
formatter = "[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format=formatter)
|
2015-06-27 19:38:04 +00:00
|
|
|
asyncio.get_event_loop().run_until_complete(test_coro())
|