amqtt/samples/client_keepalive.py

34 wiersze
720 B
Python
Czysty Zwykły widok Historia

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)
2017-08-06 22:06:57 +00:00
2015-07-05 13:53:02 +00:00
@asyncio.coroutine
def test_coro():
yield from C.connect('mqtt://test.mosquitto.org:1883/')
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)
2017-08-06 22:06:57 +00:00
asyncio.get_event_loop().run_until_complete(test_coro())