2015-07-05 13:53:02 +00:00
|
|
|
import logging
|
|
|
|
import asyncio
|
|
|
|
|
2015-07-07 19:55:17 +00:00
|
|
|
from hbmqtt.client import MQTTClient
|
|
|
|
|
|
|
|
|
2015-07-06 20:20:05 +00:00
|
|
|
#
|
|
|
|
# This sample shows a client running idle.
|
|
|
|
# Meanwhile, keepalive is managed through PING messages sent every 5 seconds
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2015-07-05 13:53:02 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
config = {
|
|
|
|
'keep_alive': 5,
|
|
|
|
'ping_delay': 1,
|
|
|
|
}
|
|
|
|
C = MQTTClient(config=config)
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_coro():
|
2015-07-10 20:55:43 +00:00
|
|
|
yield from C.connect(uri='mqtt://localhost:1883/', username=None, password=None)
|
2015-07-05 13:53:02 +00:00
|
|
|
yield from asyncio.sleep(18)
|
|
|
|
|
|
|
|
yield from C.disconnect()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
formatter = "[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format=formatter)
|
|
|
|
asyncio.get_event_loop().run_until_complete(test_coro())
|