amqtt/samples/client_keepalive.py

32 wiersze
698 B
Python
Czysty Zwykły widok Historia

2015-07-05 13:53:02 +00:00
import asyncio
import logging
2015-07-05 13:53:02 +00:00
2021-03-27 12:59:48 +00:00
from amqtt.client import MQTTClient
2015-07-07 19:55:17 +00:00
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,
2015-07-05 13:53:02 +00:00
}
C = MQTTClient(config=config)
2017-08-06 22:06:57 +00:00
async def test_coro() -> None:
await C.connect("mqtt://test.mosquitto.org:1883/")
2020-12-31 00:16:45 +00:00
await asyncio.sleep(18)
2015-07-05 13:53:02 +00:00
2020-12-31 00:16:45 +00:00
await C.disconnect()
2015-07-05 13:53:02 +00:00
if __name__ == "__main__":
2015-07-05 13:53:02 +00:00
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())