amqtt/samples/client_keepalive.py

40 wiersze
748 B
Python

2015-07-05 13:53:02 +00:00
import asyncio
import logging
from asyncio import CancelledError
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
"""
This sample shows how to run an idle client
"""
2015-07-06 20:20:05 +00:00
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
}
async def main() -> None:
client = MQTTClient(config=config)
try:
2025-07-02 17:54:26 +00:00
await client.connect("mqtt://localhost:1883/")
logger.info("client connected")
await asyncio.sleep(15)
except CancelledError:
pass
await client.disconnect()
def __main__():
formatter = "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(message)s"
logging.basicConfig(level=logging.INFO, format=formatter)
asyncio.run(main())
2015-07-05 13:53:02 +00:00
if __name__ == "__main__":
__main__()